autosuggest on tags now works, bumped up the version of the autocomplete plugin

This commit is contained in:
zhitomirskiyi 2011-03-29 13:14:47 -07:00
parent 2e25d1d745
commit ba15ea940b
5 changed files with 44 additions and 368 deletions

View file

@ -8,11 +8,19 @@ class ProfilesController < ApplicationController
@person = current_user.person @person = current_user.person
@aspect = :person_edit @aspect = :person_edit
@profile = @person.profile @profile = @person.profile
@tags = @profile.tags
@tags_array = []
@tags.each do |obj|
@tags_array << { :name => ("#"+obj.name),
:value => ("#"+obj.name)}
end
end end
def update def update
# upload and set new profile photo # upload and set new profile photo
params[:profile] ||= {} params[:profile] ||= {}
params[:profile][:tag_string] = (params[:as_values_tags]) ? params[:as_values_tags].gsub(',',' ') : ""
params[:profile][:searchable] ||= false params[:profile][:searchable] ||= false
params[:profile][:photo] = Photo.where(:author_id => current_user.person.id, params[:profile][:photo] = Photo.where(:author_id => current_user.person.id,
:id => params[:photo_id]).first if params[:photo_id] :id => params[:photo_id]).first if params[:photo_id]

View file

@ -12,22 +12,26 @@ class TagsController < ApplicationController
respond_to :json, :only => [:index] respond_to :json, :only => [:index]
def index def index
pp params params[:q].gsub!("#", "")
if params[:q].length > 1 if params[:q].length > 1
@tags = ActsAsTaggableOn::Tag.named_like(params[:q]) @tags = ActsAsTaggableOn::Tag.named_like(params[:q]).limit(params[:limit] || 10)
@hash = @tags.inject([]) do |memo, obj| @array = []
memo << { :name => obj.name, @tags.each do |obj|
@array << { :name => ("#"+obj.name),
:value => ("#"+obj.name)} :value => ("#"+obj.name)}
end end
if @array.empty?
@array << { :name => params[:q],
:value => ("#"+params[:q])}
end
respond_to do |format| respond_to do |format|
format.json{ format.json{
json = { :items => @hash}.to_json render(:json => @array.to_json, :status => 201)
render(:json => json, :status => 201)
} }
end end
else else
pp "not!"
render :nothing => true render :nothing => true
end end
end end

View file

@ -10,7 +10,7 @@
autocompleteInput.autoSuggest(data, { autocompleteInput.autoSuggest(data, {
selectedItemProp: "name", selectedItemProp: "name",
searchObjProps: "name", searchObjProps: "name",
asHtmlID: "tag_ids", asHtmlID: "contact_ids",
keyDelay: 0, keyDelay: 0,
startText: '', startText: '',
emptyText: '#{t('.no_results')}', emptyText: '#{t('.no_results')}',

View file

@ -7,20 +7,36 @@
:javascript :javascript
$(document).ready(function () { $(document).ready(function () {
var autocompleteInput = $("#profile_tag_string"); var data = $.parseJSON( $('#tags_json').val() ),
autocompleteInput = $("#profile_tag_string");
autocompleteInput.autoSuggest("#{tags_path}", { autocompleteInput.autoSuggest("#{tags_path}", {
selectedItemProp: "name", selectedItemProp: "name",
searchObjProps: "name", searchObjProps: "name",
asHtmlID: "tag_ids", asHtmlID: "tags",
neverSubmit: true,
retriveLimit: 10,
selectionLimit: 5,
minChars: 2,
keyDelay: 0, keyDelay: 0,
startText: '', startText: "#{t('profiles.edit.your_tags_placeholder')}",
emptyText: '#{t('.no_results')}', emptyText: '#{t('.no_results')}',
preFill: data
}); });
autocompleteInput.focus(); autocompleteInput.bind('keydown', function(evt){
if(evt.keyCode == 13 || evt.keyCode == 32){
if( $('li.as-result-item.active').length == 0 ){
$('li.as-result-item').first().click();
}
}
});
}); });
= hidden_field_tag :tags_json, @tags_array.to_json
%h3 %h3
= t('profiles.edit.your_public_profile') = t('profiles.edit.your_public_profile')
@ -33,8 +49,7 @@
%h4 %h4
= t('profiles.edit.your_tags') = t('profiles.edit.your_tags')
= text_field_tag 'profile[tag_string]', profile.tag_string, :placeholder => t('profiles.edit.your_tags_placeholder') = text_field_tag 'profile[tag_string]', ""
%h4 %h4
= t('profiles.edit.your_photo') = t('profiles.edit.your_photo')
= render 'photos/new_profile_photo', :aspect => aspect, :person => person = render 'photos/new_profile_photo', :aspect => aspect, :person => person

File diff suppressed because one or more lines are too long