From 950c58e6d37f68f69815d4d73df5577b9789679a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 8 Nov 2008 09:28:11 +0000 Subject: Add support for in-place editing of data fields. --- core/controllers/album.php | 2 +- core/controllers/item.php | 41 +++++++++++++++++++++++++++++++++++++++ core/controllers/photo.php | 2 +- core/libraries/Theme.php | 4 ++++ core/models/item.php | 4 ++++ core/views/in_place_edit.html.php | 38 ++++++++++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 core/controllers/item.php create mode 100644 core/views/in_place_edit.html.php (limited to 'core') 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 @@ +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 "id}-{$real_column}\">" . + "{$this->$real_column}"; } 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 @@ + + \ No newline at end of file -- cgit v1.2.3