summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-09-16 12:27:13 -0700
committerTim Almdal <tnalmdal@shaw.ca>2009-09-16 12:27:13 -0700
commit5490057480f17e5810cf8b9e558769ebd74d4b27 (patch)
treeb7168b6a0d3560ba0340c9145f525215430e32de
parentf1887422f8b4ba68dc273fe6f7d3f1123681e89a (diff)
When editing tags in place, and there is a validation error, highlight the tag with a red border and show a statust message. This fixes ticket: #779
-rw-r--r--modules/tag/controllers/admin_tags.php15
-rw-r--r--modules/tag/js/tag.js6
2 files changed, 16 insertions, 5 deletions
diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php
index 8b8dde21..3301566b 100644
--- a/modules/tag/controllers/admin_tags.php
+++ b/modules/tag/controllers/admin_tags.php
@@ -81,15 +81,20 @@ class Admin_Tags_Controller extends Admin_Controller {
kohana::show_404();
}
- $form = tag::get_rename_form($tag);
- $valid = $form->validate();
+ //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 = $form->rename_tag->inputs["name"]->value;
+ $new_name = $this->input->post("name");
$new_tag = ORM::factory("tag")->where("name", $new_name)->find();
if ($new_tag->loaded) {
- $form->rename_tag->inputs["name"]->add_error("in_use", 1);
+ $error_msg = "There is already a tag with that name";
$valid = false;
}
+ } else {
+ $error_msg = $post->errors();
+ $error_msg = $error_msg[0];
}
if ($valid) {
@@ -110,7 +115,7 @@ class Admin_Tags_Controller extends Admin_Controller {
} else {
print json_encode(
array("result" => "error",
- "form" => $form->__toString()));
+ "message" => $error_msg));
}
}
}
diff --git a/modules/tag/js/tag.js b/modules/tag/js/tag.js
index aaae9e72..d656da36 100644
--- a/modules/tag/js/tag.js
+++ b/modules/tag/js/tag.js
@@ -19,6 +19,7 @@ function ajaxify_tag_form() {
function closeEditInPlaceForms() {
// closes currently open inplace edit forms
if ($("#gRenameTagForm").length) {
+ $("#gEditErrorMessage").remove();
var li = $("#gRenameTagForm").parent();
$("#gRenameTagForm").parent().html($("#gRenameTagForm").parent().data("revert"));
li.height("");
@@ -66,6 +67,11 @@ function editInPlace(element) {
$("#gTag-" + data.tag_id).text(data.new_tagname); // update tagname
console.log(data);
window.location.reload();
+ } else if (data.result == "error") {
+ $("#gRenameTagForm #name")
+ .css("border", "2px solid red")
+ .focus();
+ $("#gTagAdmin").before("<p id=\"gEditErrorMessage\" class=\"gError\">" + data.message + "</p>");
}
}
});