changeset 1283:006057cf8f16 redmine-2.2-integration

Autocomplete working.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 14 May 2013 14:24:45 +0100
parents 8d30e7644b75
children 3ce07a57ce68
files plugins/redmine_bibliography/app/controllers/publications_controller.rb plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb plugins/redmine_bibliography/assets/javascripts/authors.js
diffstat 3 files changed, 15 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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
 
--- 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
+%>
--- 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);
+        }
     });
 });