diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index d86e823c3..d05e1bab3 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -17,20 +17,8 @@ class TagsController < ApplicationController if params[:q] && params[:q].length > 1 && request.format.json? params[:q].gsub!("#", "") params[:limit] = !params[:limit].blank? ? params[:limit].to_i : 10 - @tags = ActsAsTaggableOn::Tag.named_like(params[:q]).limit(params[:limit] - 1) - @tags.map! do |obj| - { :name => ("#"+obj.name), - :value => ("#"+obj.name), - :url => tag_path(obj.name) - } - end - - @tags << { - :name => ('#' + params[:q]), - :value => ("#" + params[:q]), - :url => tag_path(params[:q].downcase) - } - @tags.uniq! + @tags = ActsAsTaggableOn::Tag.autocomplete(params[:q]).limit(params[:limit] - 1) + prep_tags_for_javascript respond_to do |format| format.json{ @@ -77,4 +65,20 @@ class TagsController < ApplicationController end @tag_followed end + + def prep_tags_for_javascript + @tags.map! do |obj| + { :name => ("#"+obj.name), + :value => ("#"+obj.name), + :url => tag_path(obj.name) + } + end + + @tags << { + :name => ('#' + params[:q]), + :value => ("#" + params[:q]), + :url => tag_path(params[:q].downcase) + } + @tags.uniq! + end end diff --git a/app/models/acts_as_taggable_on_tag.rb b/app/models/acts_as_taggable_on_tag.rb index 8417f772a..66d948e99 100644 --- a/app/models/acts_as_taggable_on_tag.rb +++ b/app/models/acts_as_taggable_on_tag.rb @@ -2,4 +2,8 @@ class ActsAsTaggableOn::Tag def followed_count @followed_count ||= TagFollowing.where(:tag_id => self.id).count end + + def self.autocomplete(name) + where("name LIKE ?", "#{name.downcase}%") + end end diff --git a/app/views/profiles/_edit.haml b/app/views/profiles/_edit.haml index 13c3b3edf..77e92fdbe 100644 --- a/app/views/profiles/_edit.haml +++ b/app/views/profiles/_edit.haml @@ -13,32 +13,42 @@ %h3 = t('profiles.edit.your_private_profile') + %h4 = t('profiles.edit.your_bio') - = text_area_tag 'profile[bio]', profile.bio, :rows => 5, :placeholder => t('fill_me_out') + = text_area_tag 'profile[bio]', profile.bio, :rows => 5, :placeholder => t('fill_me_out') + + %br %h4 = t('profiles.edit.your_location') - %br - = text_field_tag 'profile[location]', profile.location, :placeholder => t('fill_me_out') - + = text_field_tag 'profile[location]', profile.location, :placeholder => t('fill_me_out') + + + %br + %h4 = t('profiles.edit.your_gender') - %br - = text_field_tag 'profile[gender]', profile.gender, :placeholder => t("fill_me_out") + = text_field_tag 'profile[gender]', profile.gender, :placeholder => t("fill_me_out") + + %br %h4 = t('profiles.edit.your_birthday') - %br - = select_date profile.birthday, :prompt => true, - :default => true, :order => t('date.order'), :start_year => 2000, :end_year => 1930, :prefix => 'profile[date]' + = select_date profile.birthday, :prompt => true, + :default => true, :order => t('date.order'), :start_year => 2000, :end_year => 1930, :prefix => 'profile[date]' + + %br + %br %h4 = t('search') - %p{:class=>"checkbox_select"} - = label_tag 'profile[searchable]', t('profiles.edit.allow_search') - = check_box_tag 'profile[searchable]', true, profile.searchable + %p{:class=>"checkbox_select"} + = label_tag 'profile[searchable]', t('profiles.edit.allow_search') + = check_box_tag 'profile[searchable]', true, profile.searchable + + %br %br .submit_block diff --git a/app/views/profiles/_edit_public.haml b/app/views/profiles/_edit_public.haml index 62ae2477f..d866d7f78 100644 --- a/app/views/profiles/_edit_public.haml +++ b/app/views/profiles/_edit_public.haml @@ -11,7 +11,6 @@ autocompleteInput = $("#profile_tag_string"); - autocompleteInput.autoSuggest("#{tags_path}", { selectedItemProp: "name", searchObjProps: "name", @@ -21,13 +20,14 @@ selectionLimit: 5, minChars: 2, keyDelay: 200, - startText: "#{t('profiles.edit.your_tags_placeholder')}", + startText: "", emptyText: "#{t('no_results')}", preFill: data }); autocompleteInput.bind('keydown', function(evt){ if(evt.keyCode == 13 || evt.keyCode == 9 || evt.keyCode == 32){ + evt.preventDefault(); if( $('li.as-result-item.active').length == 0 ){ $('li.as-result-item').first().click(); } @@ -35,7 +35,6 @@ }); }); - %h3 = t('profiles.edit.your_public_profile') @@ -43,13 +42,23 @@ %h4 = t('profiles.edit.your_name') - = text_field_tag 'profile[first_name]', profile.first_name, :placeholder => t('profiles.edit.first_name') - = text_field_tag 'profile[last_name]', profile.last_name, :placeholder => t('profiles.edit.last_name') += text_field_tag 'profile[first_name]', profile.first_name, :placeholder => t('profiles.edit.first_name') += text_field_tag 'profile[last_name]', profile.last_name, :placeholder => t('profiles.edit.last_name') + +%br %h4 = t('profiles.edit.your_tags') - = text_field_tag 'profile[tag_string]', "" + += text_field_tag 'profile[tag_string]', "" +%p{:style => "color:#777;font-style:italic"} + = t('profiles.edit.your_tags_placeholder') + +%br + %h4 = t('profiles.edit.your_photo') - = render 'photos/new_profile_photo', :aspect => aspect, :person => person - %br + += render 'photos/new_profile_photo', :aspect => aspect, :person => person + +%br diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 185dd14b9..38a64343e 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -275,11 +275,6 @@ ul.dropdown //hacks for tagging plugin... ul.as-selections :width 100% !important - >li.as-original - :width 100% !important - >input - :width 100% !important - :color #999 ////////////////////////////////// .unread @@ -835,7 +830,7 @@ a.paginate, #infscr-loading :size 16px :color #333 -input:not([type='submit']):not([type='reset']):not([type='hidden']), +input:not([type='submit']):not([type='reset']):not([type='hidden']):not(.as-input), textarea @include border-radius(2px) diff --git a/public/stylesheets/vendor/autoSuggest.css b/public/stylesheets/vendor/autoSuggest.css index 802db6f58..3614c924f 100644 --- a/public/stylesheets/vendor/autoSuggest.css +++ b/public/stylesheets/vendor/autoSuggest.css @@ -16,7 +16,7 @@ ul.as-selections { } ul.as-selections.loading { - background-color: #eee; + background: url("/images/ajax-loader.gif") right center no-repeat; } ul.as-selections li { diff --git a/spec/models/acts_as_taggable_on_tag_spec.rb b/spec/models/acts_as_taggable_on_tag_spec.rb new file mode 100644 index 000000000..177125479 --- /dev/null +++ b/spec/models/acts_as_taggable_on_tag_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe ActsAsTaggableOn::Tag do + describe '.autocomplete' do + before do + @tag = ActsAsTaggableOn::Tag.create(:name => "cats") + end + it 'downcases the tag name' do + ActsAsTaggableOn::Tag.autocomplete("CATS").should == [@tag] + + end + + it 'does an end where on tags' do + ActsAsTaggableOn::Tag.autocomplete("CAT").should == [@tag] + end + end +end