summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-01-04 08:44:06 +0000
committerBharat Mediratta <bharat@menalto.com>2009-01-04 08:44:06 +0000
commit92ceef27dafbc0e217a8ec7f5e2ee9694d4118a3 (patch)
tree24ce7c4aef358651f92b3361fded9d30cbac7434
parent625d0785572af319b22a523550145b4dacbd6100 (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).
-rw-r--r--modules/tag/controllers/admin_tags.php56
-rw-r--r--modules/tag/controllers/tags.php2
-rw-r--r--modules/tag/helpers/tag.php19
-rw-r--r--modules/tag/models/tag.php2
-rw-r--r--modules/tag/views/admin_tags.html.php17
5 files changed, 88 insertions, 8 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",
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php
index b1505b3d..fac2ab70 100644
--- a/modules/tag/helpers/tag.php
+++ b/modules/tag/helpers/tag.php
@@ -78,10 +78,27 @@ class tag_Core {
public static function get_add_form($item) {
$form = new Forge("tags", "", "post", array("id" => "gAddTagForm"));
$group = $form->group("add_tag")->label(_("Add Tag"));
- $group->input("tag_name")->label(_("Add tag"));
+ $group->input("name")->label(_("Add tag"));
$group->hidden("item_id")->value($item->id);
$group->submit(_("Add"));
$form->add_rules_from(ORM::factory("tag"));
return $form;
}
+
+ public static function get_rename_form($tag) {
+ $form = new Forge("admin/tags/rename/$tag->id", "", "post", array("id" => "gRenameTagForm"));
+ $group = $form->group("rename_tag")->label(_("Rename Tag"));
+ $group->input("name")->label(_("Tag name"))->value($tag->name);
+ $group->submit(_("Rename"));
+ $form->add_rules_from(ORM::factory("tag"));
+ return $form;
+ }
+
+ public static function get_delete_form($tag) {
+ $form = new Forge("admin/tags/delete/$tag->id", "", "post", array("id" => "gDeleteTagForm"));
+ $group = $form->group("delete_tag")->label(_("Delete Tag"));
+ $group->submit(_("Delete"));
+ $form->add_rules_from(ORM::factory("tag"));
+ return $form;
+ }
}
diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php
index 37fd92fb..2a728131 100644
--- a/modules/tag/models/tag.php
+++ b/modules/tag/models/tag.php
@@ -21,7 +21,7 @@ class Tag_Model extends ORM {
protected $has_and_belongs_to_many = array("items");
var $rules = array(
- "name" => "required|length[4,32]");
+ "name" => "required|length[1,64]");
/**
* Return all viewable items associated with this tag.
diff --git a/modules/tag/views/admin_tags.html.php b/modules/tag/views/admin_tags.html.php
index 9f2aa099..4315917b 100644
--- a/modules/tag/views/admin_tags.html.php
+++ b/modules/tag/views/admin_tags.html.php
@@ -22,9 +22,20 @@
<td> <?= $tag->name ?> </td>
<td> <?= $tag->count ?> </td>
<td>
- <a href="<?= url::site("admin/tags/delete/$tag->id?csrf=" . access::csrf_token()) ?>">
- <?= _("delete") ?>
- </a>
+ <ul>
+ <li>
+ <a href="<?= url::site("admin/tags/form_delete/$tag->id") ?>" class="gDialogLink"
+ title="<?= sprintf(_("Delete tag %s"), $tag->name) ?>">
+ <?= _("delete") ?>
+ </a>
+ </li>
+ <li>
+ <a href="<?= url::site("admin/tags/form_rename/$tag->id") ?>" class="gDialogLink"
+ title="<?= sprintf(_("Rename tag %s"), $tag->name) ?>">
+ <?= _("rename") ?>
+ </a>
+ </li>
+ </ul>
</td>
</tr>
<? endforeach ?>