summaryrefslogtreecommitdiff
path: root/modules/tag
diff options
context:
space:
mode:
Diffstat (limited to 'modules/tag')
-rw-r--r--modules/tag/controllers/tags.php22
-rw-r--r--modules/tag/helpers/tag.php4
-rw-r--r--modules/tag/js/tag.js6
3 files changed, 12 insertions, 20 deletions
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php
index 69bc9a48..4f8cfa5b 100644
--- a/modules/tag/controllers/tags.php
+++ b/modules/tag/controllers/tags.php
@@ -42,31 +42,22 @@ class Tags_Controller extends REST_Controller {
}
public function _index() {
- // @todo: represent this in different formats
print tag::cloud(30);
}
- public function _form_add($item_id) {
- return tag::get_add_form($item_id);
- }
-
- public function _form_edit($tag) {
- throw new Exception("@todo Tag_Controller::_form_edit NOT IMPLEMENTED");
- }
-
public function _create($tag) {
rest::http_content_type(rest::JSON);
$item = ORM::factory("item", $this->input->post("item_id"));
access::required("edit", $item);
- $form = tag::get_add_form($item->id);
+ $form = tag::get_add_form($item);
if ($form->validate()) {
tag::add($item, $this->input->post("tag_name"));
print json_encode(
array("result" => "success",
"resource" => url::site("tags/{$tag->id}"),
- "form" => tag::get_add_form($item->id)->__toString()));
+ "form" => tag::get_add_form($item)->__toString()));
} else {
print json_encode(
array("result" => "error",
@@ -74,11 +65,10 @@ class Tags_Controller extends REST_Controller {
}
}
- public function _delete($tag) {
- throw new Exception("@todo Tag_Controller::_delete NOT IMPLEMENTED");
- }
+ public function _form_add($item_id) {
+ $item = ORM::factory("item", $item_id);
+ access::required("view", $item);
- public function _update($tag) {
- throw new Exception("@todo Tag_Controller::_update NOT IMPLEMENTED");
+ return tag::get_add_form($item);
}
}
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php
index 7e42ed50..b6d39213 100644
--- a/modules/tag/helpers/tag.php
+++ b/modules/tag/helpers/tag.php
@@ -79,11 +79,11 @@ class tag_Core {
}
}
- public static function get_add_form($item_id) {
+ public static function get_add_form($item) {
$form = new Forge(url::site("tags"), "", "post", array("id" => "gAddTagForm"));
$group = $form->group("add_tag")->label(_("Add Tag"));
$group->input("tag_name")->label(_("Add tag"));
- $group->hidden("item_id")->value($item_id);
+ $group->hidden("item_id")->value($item->id);
$group->submit(_("Add"));
$form->add_rules_from(ORM::factory("tag"));
return $form;
diff --git a/modules/tag/js/tag.js b/modules/tag/js/tag.js
index 92f585a5..fc74eb26 100644
--- a/modules/tag/js/tag.js
+++ b/modules/tag/js/tag.js
@@ -6,8 +6,10 @@ function ajaxify_tag_form() {
$("#gTag form").ajaxForm({
dataType: "json",
success: function(data) {
- $("#gTag form").replaceWith(data.form);
- ajaxify_tag_form();
+ if (data.form) {
+ $("#gTag form").replaceWith(data.form);
+ ajaxify_tag_form();
+ }
if (data.result == "success") {
$.get($("#gTagCloud").attr("src"), function(data, textStatus) {
$("#gTagCloud").html(data);