Allow users to enter multiple tags at once, split by space, semicolon

or comma.

Fixes ticket #193.
This commit is contained in:
Bharat Mediratta 2009-05-13 01:43:47 +00:00
parent 983dc66684
commit 99c26f30c6
3 changed files with 8 additions and 9 deletions

View File

@ -52,7 +52,12 @@ class Tags_Controller extends REST_Controller {
$form = tag::get_add_form($item);
if ($form->validate()) {
tag::add($item, $form->add_tag->inputs["name"]->value);
foreach (split("[\,\ \;]", $form->add_tag->inputs["name"]->value) as $tag_name) {
$tag_name = trim($tag_name);
if ($tag_name) {
$tag = tag::add($item, $tag_name);
}
}
print json_encode(
array("result" => "success",

View File

@ -82,20 +82,18 @@ class tag_Core {
static function get_add_form($item) {
$form = new Forge("tags", "", "post", array("id" => "gAddTagForm"));
$group = $form->group("add_tag")->label(t("Add Tag"));
$group->input("name")->label(t("Add tag"));
$group->input("name")->label(t("Add tag"))->rules("required|length[1,64]");
$group->hidden("item_id")->value($item->id);
$group->submit("")->value(t("Add Tag"));
$form->add_rules_from(ORM::factory("tag"));
return $form;
}
static function get_rename_form($tag) {
$form = new Forge("admin/tags/rename/$tag->id", "", "post", array("id" => "gRenameTagForm"));
$group = $form->group("rename_tag")->label(t("Rename Tag"));
$group->input("name")->label(t("Tag name"))->value($tag->name);
$group->input("name")->label(t("Tag name"))->value($tag->name)->rules("required|length[1,64]");
$group->inputs["name"]->error_messages("in_use", t("There is already a tag with that name"));
$group->submit("")->value(t("Save"));
$form->add_rules_from(ORM::factory("tag"));
return $form;
}
@ -104,7 +102,6 @@ class tag_Core {
$group = $form->group("delete_tag")
->label(t("Really delete tag %tag_name?", array("tag_name" => $tag->name)));
$group->submit("")->value(t("Delete Tag"));
$form->add_rules_from(ORM::factory("tag"));
return $form;
}
}

View File

@ -20,9 +20,6 @@
class Tag_Model extends ORM {
protected $has_and_belongs_to_many = array("items");
var $rules = array(
"name" => "required|length[1,64]");
/**
* Return all viewable items associated with this tag.
* @param integer $limit number of rows to limit result to