diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-11-08 09:28:11 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-11-08 09:28:11 +0000 |
commit | 950c58e6d37f68f69815d4d73df5577b9789679a (patch) | |
tree | f8f176513d9b364b4b0a7b2a6e87ade8af11baeb /core | |
parent | ac8199a09a810277624c93fd82e49d2250ae0461 (diff) |
Add support for in-place editing of data fields.
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/album.php | 2 | ||||
-rw-r--r-- | core/controllers/item.php | 41 | ||||
-rw-r--r-- | core/controllers/photo.php | 2 | ||||
-rw-r--r-- | core/libraries/Theme.php | 4 | ||||
-rw-r--r-- | core/models/item.php | 4 | ||||
-rw-r--r-- | core/views/in_place_edit.html.php | 38 |
6 files changed, 89 insertions, 2 deletions
diff --git a/core/controllers/album.php b/core/controllers/album.php index 788ff9e2..d6b457d6 100644 --- a/core/controllers/album.php +++ b/core/controllers/album.php @@ -20,7 +20,7 @@ class Album_Controller extends Template_Controller { public $template = "page.html"; - public function View($id) { + public function view($id) { $item = ORM::factory("item")->where("id", $id)->find(); if (empty($item->id)) { return Kohana::show_404(); diff --git a/core/controllers/item.php b/core/controllers/item.php new file mode 100644 index 00000000..bb670f8a --- /dev/null +++ b/core/controllers/item.php @@ -0,0 +1,41 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 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 Item_Controller extends Controller { + public function view($id) { + $item = ORM::factory("item")->where("id", $id)->find(); + if (empty($item->id)) { + return Kohana::show_404(); + } + + if (request::method() == 'get') { + if ($item->type == 'album') { + url::redirect("album/$id"); + } else { + url::redirect("photo/$id"); + } + } else { + $key = $this->input->post("key"); + $value = $this->input->post("value"); + $item->$key = $value; + $item->save(); + print $value; + } + } +} diff --git a/core/controllers/photo.php b/core/controllers/photo.php index 6f746e65..45db4b02 100644 --- a/core/controllers/photo.php +++ b/core/controllers/photo.php @@ -20,7 +20,7 @@ class Photo_Controller extends Template_Controller { public $template = "page.html"; - public function View($id) { + public function view($id) { $item = ORM::factory("item")->where("id", $id)->find(); if (empty($item->id)) { return Kohana::show_404(); diff --git a/core/libraries/Theme.php b/core/libraries/Theme.php index 0f195d08..239a4256 100644 --- a/core/libraries/Theme.php +++ b/core/libraries/Theme.php @@ -48,6 +48,10 @@ class Theme_Core { return $this->pagination->render(); } + public function in_place_edit() { + return new View("in_place_edit.html"); + } + public function blocks() { /** @todo: make this data driven */ $blocks = array( diff --git a/core/models/item.php b/core/models/item.php index a32becc9..b83fe5c3 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -185,6 +185,10 @@ class Item_Model extends ORM_MPTT { $this->owner = ORM::factory("user", $this->owner_id); } return $this->owner; + } else if (substr($column, -5) == "_edit") { + $real_column = substr($column, 0, strlen($column) - 5); + return "<span class=\"gInPlaceEdit gEditField-{$this->id}-{$real_column}\">" . + "{$this->$real_column}</span>"; } else { return parent::__get($column); } diff --git a/core/views/in_place_edit.html.php b/core/views/in_place_edit.html.php new file mode 100644 index 00000000..adcad6c6 --- /dev/null +++ b/core/views/in_place_edit.html.php @@ -0,0 +1,38 @@ +<? defined("SYSPATH") or die("No direct script access."); ?> +<script type="text/javascript"> +$(document).ready(function() { + ajax_update = function(className, id) { + return function(value, settings) { + $.post("<?= url::site("item/__ID__") ?>".replace("__ID__", id), + {"key": settings.name, "value": value}, + function(data, textStatus) { + if (textStatus == "success") { + $(className).html(data); + } + }, + "html"); + } + } + + var seen_before = {}; + var editable = $(".gInPlaceEdit"); + for (i = 0; i < editable.length; i++) { + var matches = editable[i].className.match(/gEditField-(\d+)-(\S+)/); + if (matches && matches.length == 3) { + var className = "." + matches[0]; + if (!seen_before[className]) { + $(className).editable( + ajax_update(className, matches[1]), + {indicator : "<?= _("Saving...") ?>", + tooltip : "<?= _("Double-click to edit...") ?>", + event : "dblclick", + style : "inherit", + name : matches[2], + select : true} + ); + seen_before[className] = 1; + } + } + } +}); +</script>
\ No newline at end of file |