summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/tag/controllers/tags.php16
-rw-r--r--modules/tag/helpers/tag.php12
-rw-r--r--modules/tag/helpers/tag_block.php11
-rw-r--r--modules/tag/js/tag.js16
-rw-r--r--modules/tag/views/tag_block.html.php12
5 files changed, 56 insertions, 11 deletions
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php
index db5f93bd..a09c789d 100644
--- a/modules/tag/controllers/tags.php
+++ b/modules/tag/controllers/tags.php
@@ -47,11 +47,23 @@ class Tags_Controller extends REST_Controller {
}
public function _form_add($parameters) {
- throw new Exception("@todo Tag_Controller::_form NOT IMPLEMENTED");
+ $item_id = is_array($parameters) ? $parameters[0] : $parameters;
+ $form = tag::get_add_form($item_id);
+ if ($form->validate()) {
+ Kohana::log("debug", print_r($this->inputs->post(), true));
+ Kohana::log("debug", $form->inputs["text"]->value);
+ $tags = explode(",", $form->inputs["text"]->value);
+ Kohana::log("debug", print_r($tags, true));
+
+ $item = ORM::factory("item", $item_id);
+// $form->inputs["text"] = "add new tags...";
+ }
+ Kohana::log("debug", print_r($form, true));
+ print $form->render();
}
public function _form_edit($tag) {
- throw new Exception("@todo Tag_Controller::_form NOT IMPLEMENTED");
+ throw new Exception("@todo Tag_Controller::_form_edit NOT IMPLEMENTED");
}
public function _create($tag) {
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php
index 0ca86dc8..6e8f95f9 100644
--- a/modules/tag/helpers/tag.php
+++ b/modules/tag/helpers/tag.php
@@ -59,4 +59,16 @@ class tag_Core {
->limit($count)
->find_all();
}
+
+ public static function get_add_form($item_id) {
+ $form = new Forge(url::site("form/add/tags/$item_id"), "", "post", array("id" => "gAddTag"));
+ $form->input("text")
+ ->label(_("(Enter tags separated by commas)"))
+ ->id("gNewTags")
+ ->class("text")
+ ->value("add new tags...")
+ ->rules("required");
+ $form->submit(_("Add"));
+ return $form;
+ }
}
diff --git a/modules/tag/helpers/tag_block.php b/modules/tag/helpers/tag_block.php
index 1576ac08..5cf6aa75 100644
--- a/modules/tag/helpers/tag_block.php
+++ b/modules/tag/helpers/tag_block.php
@@ -19,6 +19,11 @@
*/
class tag_block_Core {
+ public static function head($theme) {
+ $url = url::file("modules/tag/js/tag.js");
+ return "<script src=\"$url\" type=\"text/javascript\"></script>";
+ }
+
public static function sidebar_blocks($theme) {
$block = new Block();
$block->id = "gTag";
@@ -31,9 +36,11 @@ class tag_block_Core {
usort($tags, array("tag_block", "sort_by_name"));
$block->content->tags = $tags;
-
- return $block;
+ if ($block->content->page_type != "tag") {
+ $block->content->item = $theme->item();
+ }
}
+ return $block;
}
public static function sort_by_name($tag1, $tag2) {
diff --git a/modules/tag/js/tag.js b/modules/tag/js/tag.js
new file mode 100644
index 00000000..726b8ad2
--- /dev/null
+++ b/modules/tag/js/tag.js
@@ -0,0 +1,16 @@
+$("document").ready(function() {
+ $("#gAddTag").submit(function(event){
+ get_tag_block($("#gAddTag").attr("action"));
+ return false;
+ });
+});
+
+function get_tag_block(url) {
+ $.get(url, function(data) {
+ $('#gTagFormContainer').html(data);
+ $("#gAddTag").submit(function(event){
+ get_tag_block($("#gAddTag").attr("action"));
+ return false;
+ });
+ });
+}
diff --git a/modules/tag/views/tag_block.html.php b/modules/tag/views/tag_block.html.php
index ba2978c7..bd507571 100644
--- a/modules/tag/views/tag_block.html.php
+++ b/modules/tag/views/tag_block.html.php
@@ -8,11 +8,9 @@
<? endforeach ?>
</ul>
-<form id="gAddTag">
- <ul>
- <li><input type="text" class="text" value="add new tags..." id="gNewTags" /></li>
- <li><input type="submit" value="add" /></li>
- </ul>
- <label for="gNewTags" class="gUnderState"><?= _("(separated by commas)") ?></label>
-</form>
+<? if ($page_type != "tag"): ?>
+ <div id="gTagFormContainer">
+ <?= tag::get_add_form($item->id) ?>
+ </div>
+<? endif; ?>