diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gallery/libraries/InPlaceEdit.php | 89 | ||||
-rw-r--r-- | modules/gallery/views/in_place_edit.html.php | 24 |
2 files changed, 113 insertions, 0 deletions
diff --git a/modules/gallery/libraries/InPlaceEdit.php b/modules/gallery/libraries/InPlaceEdit.php new file mode 100644 index 00000000..eb685b65 --- /dev/null +++ b/modules/gallery/libraries/InPlaceEdit.php @@ -0,0 +1,89 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class InPlaceEdit_Core { + private $rules = array(); + private $messages = array(); + private $callback = array(); + private $initial_value; + private $action = ""; + private $errors; + private $form; + + static function factory($initial_value) { + $instance = new InPlaceEdit(); + $instance->initial_value = $initial_value; + $instance->form = array("input" => $initial_value); + $instance->errors = array("input" => ""); + + return $instance; + } + + public function add_action($action) { + $this->action = $action; + return $this; + } + + public function add_rules($rules) { + $this->rules += $rules; + return $this; + } + + public function add_messages($messages) { + $this->messages += $messages; + return $this; + } + + public function add_callback($callback) { + $this->callback = $callback; + return $this; + } + + public function validate() { + $post = Validation::factory($_POST) + ->add_callbacks("input", $this->callback); + foreach ($this->rules as $rule) { + $post->add_rules("input", $rule); + } + + $valid = $post->validate(); + $this->form = array_merge($this->form, $post->as_array()); + $this->errors = array_merge($this->errors, $post->errors()); + return $valid; + } + + public function render() { + $v = new View("in_place_edit.html"); + $v->hidden = array("csrf" => access::csrf_token()); + $v->action = url::site($this->action); + $v->form = $this->form; + $v->errors = $this->errors; + Kohana::log("alert", Kohana::debug($this->errors)); + foreach ($v->errors as $key => $error) { + if (!empty($error)) { + $v->errors[$key] = $this->messages[$error]; + } + } + return $v->render(); + } + + public function value() { + return $this->form["input"]; + } +}
\ No newline at end of file diff --git a/modules/gallery/views/in_place_edit.html.php b/modules/gallery/views/in_place_edit.html.php new file mode 100644 index 00000000..5cc42cd6 --- /dev/null +++ b/modules/gallery/views/in_place_edit.html.php @@ -0,0 +1,24 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<style> + #g-inplace-edit-form ul { + margin: 0; + } + #g-inplace-edit-message { +background-color: #FFF; + } +</style> +<?= form::open($action, array("method" => "post", "id" => "g-inplace-edit-form", "class" => "g-short-form"), $hidden) ?> + <ul> + <li <? if (!empty($errors["input"])): ?> class="g-error"<? endif ?>> + <?= form::input("input", $form["input"], " class='textbox'") ?> + </li> + <li> + <?= form::submit(array("class" => "submit ui-state-default"), t("Save")) ?> + </li> + <li><a href="#" class="g-cancel"><?= t("Cancel") ?></a></li> + </ul> +<?= form::close() ?> +<? if (!empty($errors["input"])): ?> +<div id="g-inplace-edit-message" class="g-error"><?= $errors["input"] ?></div> +<? endif ?> + |