diff options
| author | Bharat Mediratta <bharat@menalto.com> | 2009-01-04 08:44:06 +0000 |
|---|---|---|
| committer | Bharat Mediratta <bharat@menalto.com> | 2009-01-04 08:44:06 +0000 |
| commit | 92ceef27dafbc0e217a8ec7f5e2ee9694d4118a3 (patch) | |
| tree | 24ce7c4aef358651f92b3361fded9d30cbac7434 /modules/tag/controllers | |
| parent | 625d0785572af319b22a523550145b4dacbd6100 (diff) | |
Allow renaming of tags using a modal dialog. Put up a confirmation
dialog for deleting tags. Remove the 4 character restriction on tags
(it was getting ignored by the add form anyway since it was mistakenly
referred to as tag_name there).
Diffstat (limited to 'modules/tag/controllers')
| -rw-r--r-- | modules/tag/controllers/admin_tags.php | 56 | ||||
| -rw-r--r-- | modules/tag/controllers/tags.php | 2 |
2 files changed, 55 insertions, 3 deletions
diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index 42bb9985..6199aebb 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -33,18 +33,70 @@ class Admin_Tags_Controller extends Admin_Controller { print $view; } + public function form_delete($id) { + $tag = ORM::factory("tag", $id); + if ($tag->loaded) { + print tag::get_delete_form($tag); + } + } + public function delete($id) { access::verify_csrf(); $tag = ORM::factory("tag", $id); - if ($tag->loaded) { + if (!$tag->loaded) { + kohana::show_404(); + } + + $form = tag::get_delete_form($tag); + if ($form->validate()) { $name = $tag->name; Database::instance()->query("DELETE from `items_tags` where `tag_id` = $tag->id"); $tag->delete(); message::success(sprintf(_("Deleted tag %s"), $name)); log::success("tags", sprintf(_("Deleted tag %s"), $name)); + + print json_encode( + array("result" => "success", + "location" => url::site("admin/tags"))); + } else { + print json_encode( + array("result" => "error", + "form" => $form->__toString())); } + } - url::redirect("admin/tags"); + public function form_rename($id) { + $tag = ORM::factory("tag", $id); + if ($tag->loaded) { + print tag::get_rename_form($tag); + } + } + + public function rename($id) { + access::verify_csrf(); + + $tag = ORM::factory("tag", $id); + if (!$tag->loaded) { + kohana::show_404(); + } + + $form = tag::get_rename_form($tag); + if ($form->validate()) { + $old_name = $tag->name; + $tag->name = $form->rename_tag->inputs["name"]->value; + $tag->save(); + + message::success(sprintf(_("Renamed tag %s to %s"), $old_name, $tag->name)); + log::success("tags", sprintf(_("Renamed tag %s to %s"), $old_name, $tag->name)); + + print json_encode( + array("result" => "success", + "location" => url::site("admin/tags"))); + } else { + print json_encode( + array("result" => "error", + "form" => $form->__toString())); + } } } diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 36cf9900..01c5d2df 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -51,7 +51,7 @@ class Tags_Controller extends REST_Controller { $form = tag::get_add_form($item); if ($form->validate()) { - tag::add($item, $this->input->post("tag_name")); + tag::add($item, $form->add_tag->inputs["name"]->value); print json_encode( array("result" => "success", |
