autosuggest on tags now works, bumped up the version of the autocomplete plugin
This commit is contained in:
parent
2e25d1d745
commit
ba15ea940b
5 changed files with 44 additions and 368 deletions
|
|
@ -8,11 +8,19 @@ class ProfilesController < ApplicationController
|
|||
@person = current_user.person
|
||||
@aspect = :person_edit
|
||||
@profile = @person.profile
|
||||
|
||||
@tags = @profile.tags
|
||||
@tags_array = []
|
||||
@tags.each do |obj|
|
||||
@tags_array << { :name => ("#"+obj.name),
|
||||
:value => ("#"+obj.name)}
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
# upload and set new profile photo
|
||||
# upload and set new profile photo
|
||||
params[:profile] ||= {}
|
||||
params[:profile][:tag_string] = (params[:as_values_tags]) ? params[:as_values_tags].gsub(',',' ') : ""
|
||||
params[:profile][:searchable] ||= false
|
||||
params[:profile][:photo] = Photo.where(:author_id => current_user.person.id,
|
||||
:id => params[:photo_id]).first if params[:photo_id]
|
||||
|
|
|
|||
|
|
@ -12,22 +12,26 @@ class TagsController < ApplicationController
|
|||
respond_to :json, :only => [:index]
|
||||
|
||||
def index
|
||||
pp params
|
||||
params[:q].gsub!("#", "")
|
||||
if params[:q].length > 1
|
||||
@tags = ActsAsTaggableOn::Tag.named_like(params[:q])
|
||||
@hash = @tags.inject([]) do |memo, obj|
|
||||
memo << { :name => obj.name,
|
||||
:value => ("#"+obj.name)}
|
||||
@tags = ActsAsTaggableOn::Tag.named_like(params[:q]).limit(params[:limit] || 10)
|
||||
@array = []
|
||||
@tags.each do |obj|
|
||||
@array << { :name => ("#"+obj.name),
|
||||
:value => ("#"+obj.name)}
|
||||
end
|
||||
|
||||
if @array.empty?
|
||||
@array << { :name => params[:q],
|
||||
:value => ("#"+params[:q])}
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.json{
|
||||
json = { :items => @hash}.to_json
|
||||
render(:json => json, :status => 201)
|
||||
render(:json => @array.to_json, :status => 201)
|
||||
}
|
||||
end
|
||||
else
|
||||
pp "not!"
|
||||
render :nothing => true
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
autocompleteInput.autoSuggest(data, {
|
||||
selectedItemProp: "name",
|
||||
searchObjProps: "name",
|
||||
asHtmlID: "tag_ids",
|
||||
asHtmlID: "contact_ids",
|
||||
keyDelay: 0,
|
||||
startText: '',
|
||||
emptyText: '#{t('.no_results')}',
|
||||
|
|
|
|||
|
|
@ -7,20 +7,36 @@
|
|||
|
||||
:javascript
|
||||
$(document).ready(function () {
|
||||
var autocompleteInput = $("#profile_tag_string");
|
||||
var data = $.parseJSON( $('#tags_json').val() ),
|
||||
autocompleteInput = $("#profile_tag_string");
|
||||
|
||||
|
||||
|
||||
autocompleteInput.autoSuggest("#{tags_path}", {
|
||||
selectedItemProp: "name",
|
||||
searchObjProps: "name",
|
||||
asHtmlID: "tag_ids",
|
||||
asHtmlID: "tags",
|
||||
neverSubmit: true,
|
||||
retriveLimit: 10,
|
||||
selectionLimit: 5,
|
||||
minChars: 2,
|
||||
keyDelay: 0,
|
||||
startText: '',
|
||||
startText: "#{t('profiles.edit.your_tags_placeholder')}",
|
||||
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
|
||||
= t('profiles.edit.your_public_profile')
|
||||
|
||||
|
|
@ -33,8 +49,7 @@
|
|||
|
||||
%h4
|
||||
= 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
|
||||
= t('profiles.edit.your_photo')
|
||||
= render 'photos/new_profile_photo', :aspect => aspect, :person => person
|
||||
|
|
|
|||
353
public/javascripts/vendor/jquery.autoSuggest.js
vendored
353
public/javascripts/vendor/jquery.autoSuggest.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue