summaryrefslogtreecommitdiff
path: root/modules/tag/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/tag/controllers')
-rw-r--r--modules/tag/controllers/admin_tags.php46
-rw-r--r--modules/tag/controllers/tags.php9
2 files changed, 27 insertions, 28 deletions
diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php
index 63f7957c..67587c2e 100644
--- a/modules/tag/controllers/admin_tags.php
+++ b/modules/tag/controllers/admin_tags.php
@@ -69,7 +69,9 @@ class Admin_Tags_Controller extends Admin_Controller {
public function form_rename($id) {
$tag = ORM::factory("tag", $id);
if ($tag->loaded) {
- print tag::get_rename_form($tag);
+ print InPlaceEdit::factory($tag->name)
+ ->action("admin/tags/rename/$id")
+ ->render();
}
}
@@ -81,25 +83,15 @@ class Admin_Tags_Controller extends Admin_Controller {
kohana::show_404();
}
- // Don't use a form as the form is dynamically created in the js
- $post = new Validation($_POST);
- $post->add_rules("name", "required", "length[1,64]");
- $valid = $post->validate();
- if ($valid) {
- $new_name = $this->input->post("name");
- $new_tag = ORM::factory("tag")->where("name", $new_name)->find();
- if ($new_tag->loaded) {
- $error_msg = t("There is already a tag with that name");
- $valid = false;
- }
- } else {
- $error_msg = $post->errors();
- $error_msg = $error_msg[0];
- }
+ $in_place_edit = InPlaceEdit::factory($tag->name)
+ ->action("admin/tags/rename/$tag->id")
+ ->rules(array("required", "length[1,64]"))
+ ->messages(array("in_use" => t("There is already a tag with that name")))
+ ->callback(array($this, "check_for_duplicate"));
- if ($valid) {
+ if ($in_place_edit->validate()) {
$old_name = $tag->name;
- $tag->name = $new_name;
+ $tag->name = $in_place_edit->value();
$tag->save();
$message = t("Renamed tag %old_name to %new_name",
@@ -107,16 +99,18 @@ class Admin_Tags_Controller extends Admin_Controller {
message::success($message);
log::success("tags", $message);
- print json_encode(
- array("result" => "success",
- "location" => url::site("admin/tags"),
- "tag_id" => $tag->id,
- "new_tagname" => html::clean($tag->name)));
+ print json_encode(array("result" => "success"));
} else {
- print json_encode(
- array("result" => "error",
- "message" => (string) $error_msg));
+ print json_encode(array("result" => "error", "form" => $in_place_edit->render()));
}
}
+
+ public function check_for_duplicate(Validation $post_data, $field) {
+ $tag_exists = ORM::factory("tag")->where("name", $post_data[$field])->count_all();
+ if ($tag_exists) {
+ $post_data->add_error($field, "in_use");
+ }
+ }
+
}
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php
index 1bd6b3cc..c3b14fcc 100644
--- a/modules/tag/controllers/tags.php
+++ b/modules/tag/controllers/tags.php
@@ -25,13 +25,18 @@ class Tags_Controller extends REST_Controller {
$page = (int) $this->input->get("page", "1");
$children_count = $tag->items_count();
$offset = ($page-1) * $page_size;
+ $max_pages = max(ceil($children_count / $page_size), 1);
// Make sure that the page references a valid offset
- if ($page < 1 || ($children_count && $page > ceil($children_count / $page_size))) {
- Kohana::show_404();
+ if ($page < 1) {
+ url::redirect($album->abs_url());
+ } else if ($page > $max_pages) {
+ url::redirect($album->abs_url("page=$max_pages"));
}
$template = new Theme_View("page.html", "tag");
+ $template->set_global("page", $page);
+ $template->set_global("max_pages", $max_pages);
$template->set_global("page_size", $page_size);
$template->set_global("tag", $tag);
$template->set_global("children", $tag->items($page_size, $offset));