From 5447b8321080afd09387d837a4acfa9c90ddfa16 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 27 Nov 2008 05:00:50 +0000 Subject: Clean up REST pattern in tags: 1) Generate the form in Tags_Controller::_form_add() 2) Process the form submit in Tags_Controller::_create() 3) Create the tag properly This required me to limit our scope to adding one tag at a time, which I think is fine if we're doing Ajax style tag addition. --- modules/tag/helpers/tag.php | 18 ++++-------------- modules/tag/helpers/tag_block.php | 9 ++++++++- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 09109cd5..a1939df7 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -23,8 +23,9 @@ class tag_Core { * * @todo Write test. * - * @param ORM $item an item - * @param string $tag_name a tag name + * @param Item_Model $item an item + * @param string $tag_name a tag name + * @return Tag_Model * @throws Exception("@todo {$tag_name} WAS_NOT_ADDED_TO {$item->id}") */ public static function add($item, $tag_name) { @@ -46,6 +47,7 @@ class tag_Core { $tag->count++; $tag->save(); } + return $tag; } /** @@ -59,16 +61,4 @@ 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("tags") - ->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 5cf6aa75..c735ee04 100644 --- a/modules/tag/helpers/tag_block.php +++ b/modules/tag/helpers/tag_block.php @@ -17,7 +17,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ - class tag_block_Core { public static function head($theme) { $url = url::file("modules/tag/js/tag.js"); @@ -39,7 +38,15 @@ class tag_block_Core { if ($block->content->page_type != "tag") { $block->content->item = $theme->item(); } + } else { + $block->content->tags = array(); + } + + if ($theme->page_type() != "tag") { + $controller = new Tags_Controller(); + $block->content->form = $controller->form_add($theme->item()); } + return $block; } -- cgit v1.2.3