Commit 1e5aa0effffa60cc5f5a953011cfb40a37b6a862
1 parent
6323cdda
Exists in
master
and in
4 other branches
add tags autocomplete
Showing
6 changed files
with
63 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +class TagsController < ApplicationController | ||
2 | + def index | ||
3 | + end | ||
4 | + | ||
5 | + def autocomplete | ||
6 | + tags = Project.tag_counts.limit 8 | ||
7 | + tags = tags.where('name like ?', "%#{params[:term]}%") unless params[:term].blank? | ||
8 | + tags = tags.map {|t| t.name} | ||
9 | + | ||
10 | + respond_to do |format| | ||
11 | + format.json { render json: tags} | ||
12 | + end | ||
13 | + end | ||
14 | + | ||
15 | +end |
app/views/projects/_form.html.haml
@@ -57,9 +57,19 @@ | @@ -57,9 +57,19 @@ | ||
57 | $(function(){ | 57 | $(function(){ |
58 | var tag_field = $('#tag_field').tagify(); | 58 | var tag_field = $('#tag_field').tagify(); |
59 | 59 | ||
60 | + | ||
61 | + tag_field.tagify('inputField').autocomplete({ | ||
62 | + source: '/tags/autocomplete.json', | ||
63 | + position: { of: tag_field.tagify('containerDiv') }, | ||
64 | + close: function(event, ui) { tag_field.tagify('add'); }, | ||
65 | + }); | ||
66 | + | ||
67 | + | ||
60 | $('form').submit( function() { | 68 | $('form').submit( function() { |
61 | var tag_field = $('#tag_field') | 69 | var tag_field = $('#tag_field') |
62 | tag_field.val( tag_field.tagify('serialize') ); | 70 | tag_field.val( tag_field.tagify('serialize') ); |
63 | return true; | 71 | return true; |
64 | }); | 72 | }); |
73 | + | ||
74 | + | ||
65 | }) | 75 | }) |
config/routes.rb
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe "Tags" do | ||
4 | + before { login_as :user } | ||
5 | + | ||
6 | + # describe "GET 'tags/index'" do | ||
7 | + # it "should be successful" do | ||
8 | + # get 'tags/index' | ||
9 | + # response.should be_success | ||
10 | + # end | ||
11 | + # end | ||
12 | + | ||
13 | + | ||
14 | + describe "GET '/tags/autocomplete'" do | ||
15 | + before do | ||
16 | + @project = Factory :project | ||
17 | + @project.add_access(@user, :read) | ||
18 | + @project.tag_list = 'demo1' | ||
19 | + @project.save | ||
20 | + visit '/tags/autocomplete.json' | ||
21 | + end | ||
22 | + | ||
23 | + | ||
24 | + it "should contains tags" do | ||
25 | + page.should have_content('demo1') | ||
26 | + end | ||
27 | +end | ||
28 | + | ||
29 | + | ||
30 | + | ||
31 | +end |