diff options
| author | Romain LE DISEZ <romain.git@ledisez.net> | 2009-07-25 13:59:04 +0200 |
|---|---|---|
| committer | Romain LE DISEZ <romain.git@ledisez.net> | 2009-07-25 13:59:04 +0200 |
| commit | 0aa3ec3ae90a101b2bfc1b395a1749551da22287 (patch) | |
| tree | 02702942bc27e0e4e7b634a56cd35b71cb35fecc /modules/tag | |
| parent | b181707c1651af8737c2e6ff550fd20f480b781b (diff) | |
| parent | 50d6cc0150b930d79d3e8b90956ffa9655fcc9c5 (diff) | |
Merge commit 'upstream/master'
Diffstat (limited to 'modules/tag')
| -rw-r--r-- | modules/tag/controllers/tags.php | 17 | ||||
| -rw-r--r-- | modules/tag/helpers/tag.php | 2 | ||||
| -rw-r--r-- | modules/tag/helpers/tag_event.php | 10 | ||||
| -rw-r--r-- | modules/tag/helpers/tag_theme.php | 2 | ||||
| -rw-r--r-- | modules/tag/js/tag.js | 15 | ||||
| -rw-r--r-- | modules/tag/models/tag.php | 10 | ||||
| -rw-r--r-- | modules/tag/views/tag_block.html.php | 10 |
7 files changed, 60 insertions, 6 deletions
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 5dd07935..a600ea1a 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -78,4 +78,21 @@ class Tags_Controller extends REST_Controller { return tag::get_add_form($item); } + + public function autocomplete() { + $tags = array(); + $tag_parts = preg_split("#[,\s;]+# ", $this->input->get("q")); + $limit = $this->input->get("limit"); + $tag_part = end($tag_parts); + $tag_list = ORM::factory("tag") + ->like("name", "{$tag_part}%", false) + ->orderby("name", "ASC") + ->limit($limit) + ->find_all(); + foreach ($tag_list as $tag) { + $tags[] = $tag->name; + } + + print implode("\n", $tags); + } } diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 5efa6a19..be5461a4 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -104,7 +104,7 @@ class tag_Core { ($item->is_photo() ? t("Add tag to photo") : t("Add tag to movie")); $group = $form->group("add_tag")->label("Add Tag"); - $group->input("name")->label($label)->rules("required|length[1,64]"); + $group->input("name")->label($label)->rules("required"); $group->hidden("item_id")->value($item->id); $group->submit("")->value(t("Add Tag")); return $form; diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index e1ab1b73..58034900 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -64,9 +64,15 @@ class tag_event_Core { tag::compact(); } - static function item_edit_form($item, $form) { + static function item_edit_form($item, $view) { + $url = url::site("tags/autocomplete"); + $view->script[] = "$('#gEditFormContainer form').ready(function() { + $('#gEditFormContainer form input[id=tags]').autocomplete( + '$url', {max: 30, formatResult: formatTagAutoCompleteResult} + ); + });"; $tag_value = implode("; ", tag::item_tags($item)); - $form->edit_item->input("tags")->label(t("Tags (separate by , or ;)")) + $view->form->edit_item->input("tags")->label(t("Tags (separate by , or ;)")) ->value($tag_value); } diff --git a/modules/tag/helpers/tag_theme.php b/modules/tag/helpers/tag_theme.php index d46a91e9..1bce9bd8 100644 --- a/modules/tag/helpers/tag_theme.php +++ b/modules/tag/helpers/tag_theme.php @@ -19,6 +19,8 @@ */ class tag_theme_Core { static function head($theme) { + $theme->css("jquery.autocomplete.css"); + $theme->script("jquery.autocomplete.js"); $theme->script("tag.js"); } diff --git a/modules/tag/js/tag.js b/modules/tag/js/tag.js index a5aaa3f8..bbf44166 100644 --- a/modules/tag/js/tag.js +++ b/modules/tag/js/tag.js @@ -66,3 +66,18 @@ function editInPlace(element) { }; ajaxify_editInPlaceForm(); } + +function formatTagAutoCompleteResult(row) { + var text = $(".ac_loading").val(); + if (/[\s,;]/.test(text)) { + for (var i= text.length - 1; i >= 0; i--) { + var chr = text.charAt(i); + if (chr == " " || chr == "," || chr == ";") { + break; + } + } + return text.substr(0, i + 1) + row[0]; + } else { + return row[0]; + } +} diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index 7a85dbab..e910a8ee 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -44,10 +44,14 @@ class Tag_Model extends ORM { * @return integer */ public function items_count($type=null) { - return ORM::factory("item") + $model = ORM::factory("item") ->viewable() ->join("items_tags", "items.id", "items_tags.item_id") - ->where("items_tags.tag_id", $this->id) - ->count_all(); + ->where("items_tags.tag_id", $this->id); + + if ($type) { + $model->where("items.type", $type); + } + return $model->count_all(); } }
\ No newline at end of file diff --git a/modules/tag/views/tag_block.html.php b/modules/tag/views/tag_block.html.php index 12c90857..233eb361 100644 --- a/modules/tag/views/tag_block.html.php +++ b/modules/tag/views/tag_block.html.php @@ -1,4 +1,14 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> +<script> + $("#gAddTagForm").ready(function() { + var url = $("#gTagCloud").attr("title") + "/autocomplete"; + $("#gAddTagForm input:text").autocomplete( + url, { + max: 30, + formatResult: formatTagAutoCompleteResult} + ); + }); +</script> <div id="gTagCloud" title="<?= url::site("tags") ?>"> <?= $cloud ?> </div> |
