diff options
| author | Bharat Mediratta <bharat@menalto.com> | 2008-11-27 05:00:50 +0000 |
|---|---|---|
| committer | Bharat Mediratta <bharat@menalto.com> | 2008-11-27 05:00:50 +0000 |
| commit | 5447b8321080afd09387d837a4acfa9c90ddfa16 (patch) | |
| tree | 1fbaf7cc855066aa8d337282a648d809c921f5dc /modules/tag/controllers | |
| parent | 8e33f5d7b90335236e14b283ccb6d6ee5db4762d (diff) | |
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.
Diffstat (limited to 'modules/tag/controllers')
| -rw-r--r-- | modules/tag/controllers/tags.php | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 95d7145d..9a5422cf 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -46,16 +46,13 @@ class Tags_Controller extends REST_Controller { throw new Exception("@todo Tag_Controller::_index NOT IMPLEMENTED"); } - public function _form_add($parameters) { - $item_id = is_array($parameters) ? $parameters[0] : $parameters; - $form = tag::get_add_form($item_id); - if ($form->validate()) { - $tags = explode(",", $form->inputs["tags"]->value); - -// $item = ORM::factory("item", $item_id); - $form->inputs["tags"]->value("add new tags..."); - } - print $form->render(); + public function _form_add($item_id) { + $form = new Forge(url::site("tags"), "", "post", array("id" => "gAddTag")); + $form->input("tag_name")->value(_("add new tags..."))->id("gNewTags"); + $form->hidden("item_id")->value($item_id); + $form->submit(_("Add")); + $form->add_rules_from(ORM::factory("tag")); + return $form; } public function _form_edit($tag) { @@ -63,7 +60,20 @@ class Tags_Controller extends REST_Controller { } public function _create($tag) { - throw new Exception("@todo Tag_Controller::_create NOT IMPLEMENTED"); + // @todo: check permissions + $form = self::form_add($this->input->post('item_id')); + if ($form->validate()) { + $item = ORM::factory("item", $this->input->post("item_id")); + if ($item->loaded) { + tag::add($item, $this->input->post("tag_name")); + } + + rest::http_status(rest::CREATED); + rest::http_location(url::site("tags/{$tag->id}")); + } + + // @todo Return appropriate HTTP status code indicating error. + print $form; } public function _delete($tag) { |
