# HG changeset patch # User luisf # Date 1368537885 -3600 # Node ID 006057cf8f165b7ef07e479b441d9d85b9a6d5bc # Parent 8d30e7644b754ee7307bbd6e6edf2038c564bd35 Autocomplete working. diff -r 8d30e7644b75 -r 006057cf8f16 plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon May 13 18:02:38 2013 +0100 +++ b/plugins/redmine_bibliography/app/controllers/publications_controller.rb Tue May 14 14:24:45 2013 +0100 @@ -226,10 +226,10 @@ @object_name = "publications[authorships_attributes][#{object_id}][search_results]" # cc 20110909 -- revert to like instead of like_unique -- see #289 - authorships_list = Authorship.like(params[:q]).find(:all, :limit => 100) - users_list = User.active.like(params[:q]).find(:all, :limit => 100) + authorships_list = Authorship.like(params[:term]).find(:all, :limit => 100) + users_list = User.active.like(params[:term]).find(:all, :limit => 100) - logger.debug "Query for \"#{params[:q]}\" returned \"#{authorships_list.size}\" authorships and \"#{users_list.size}\" users" + logger.debug "Query for \"#{params[:term]}\" returned \"#{authorships_list.size}\" authorships and \"#{users_list.size}\" users" @results = users_list diff -r 8d30e7644b75 -r 006057cf8f16 plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb --- a/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb Mon May 13 18:02:38 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb Tue May 14 14:24:45 2013 +0100 @@ -1,4 +1,8 @@ -<% if params[:q] && params[:q].length > 1 %> - <%= choose_author_link @object_name, @results %> -<% end %> - +<%= raw @results.map {|result| { + 'id' => result.id, + 'label' => "#{result.name} (#{result.mail.partition('@')[2]})", + 'value' => result.name, + 'type' => result.class, + } + }.to_json +%> diff -r 8d30e7644b75 -r 006057cf8f16 plugins/redmine_bibliography/assets/javascripts/authors.js --- a/plugins/redmine_bibliography/assets/javascripts/authors.js Mon May 13 18:02:38 2013 +0100 +++ b/plugins/redmine_bibliography/assets/javascripts/authors.js Tue May 14 14:24:45 2013 +0100 @@ -17,7 +17,10 @@ $(".author_search").live('keyup.autocomplete', function(){ $(this).autocomplete({ source: '/publications/autocomplete_for_author', - minLength: 2 + minLength: 2, + select: function(event, ui){ + alert("gOtChA " + ui.item.id + " " + ui.item.type); + } }); });