changeset 1409:3cb633d4b37d biblio_alt_search_auth

Authorship autocomplete is now a function.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 01 Oct 2013 13:05:17 +0100
parents b09744f35f76
children 320ea02c238a
files plugins/redmine_bibliography/app/views/publications/edit.html.erb plugins/redmine_bibliography/app/views/publications/new.html.erb plugins/redmine_bibliography/assets/javascripts/authors.js
diffstat 3 files changed, 34 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/redmine_bibliography/app/views/publications/edit.html.erb	Tue Oct 01 12:08:09 2013 +0100
+++ b/plugins/redmine_bibliography/app/views/publications/edit.html.erb	Tue Oct 01 13:05:17 2013 +0100
@@ -16,6 +16,8 @@
                             dataType: 'script'
                         }); return false; });" -%>
 
+  <%= javascript_tag "authorship_autocomplete('#{url_for :controller => :publications, :action => :autocomplete_for_author}');" -%>
+
 <% end %>
 
 <%= error_messages_for 'publication' %>
--- a/plugins/redmine_bibliography/app/views/publications/new.html.erb	Tue Oct 01 12:08:09 2013 +0100
+++ b/plugins/redmine_bibliography/app/views/publications/new.html.erb	Tue Oct 01 13:05:17 2013 +0100
@@ -3,6 +3,7 @@
     <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
     <%= javascript_include_tag 'bibliography', :plugin => 'redmine_bibliography' -%>
     <%= javascript_include_tag 'new_publication', :plugin => 'redmine_bibliography' -%>
+
     <%= javascript_tag "
       $('#publication_bibtex_entry_attributes_entry_type').live('change', function() {
           $this = $(this);
@@ -17,6 +18,8 @@
           return false;
       });"-%>
 
+  <%= javascript_tag "authorship_autocomplete('#{url_for :controller => :publications, :action => :autocomplete_for_author}');" -%>
+
 <% end %>
 
 <%= error_messages_for 'publication' %>
--- a/plugins/redmine_bibliography/assets/javascripts/authors.js	Tue Oct 01 12:08:09 2013 +0100
+++ b/plugins/redmine_bibliography/assets/javascripts/authors.js	Tue Oct 01 13:05:17 2013 +0100
@@ -10,35 +10,36 @@
   $(link).closest(".fields").hide();
 }
 
-$(".author_name_on_paper").live('keyup.autocomplete', function(){
-     $this = $(this);
+function authorship_autocomplete(url){
+    $(".author_name_on_paper").live('keyup.autocomplete', function(){
+         $this = $(this);
 
-     $this.autocomplete({
-        source: '/publications/autocomplete_for_author',
-        minLength: 2,
-        focus: function(event, ui) {
-            $this.val(ui.item.label);
-            return false;
-        },
-        select: function(event, ui){
-            $this.closest('div').find("input[id$='institution']").val(ui.item.institution);
-            $this.closest('div').find("input[id$='email']").val(ui.item.email);
+         $this.autocomplete({
+            source: url,
+            minLength: 2,
+            focus: function(event, ui) {
+                $this.val(ui.item.label);
+                return false;
+            },
+            select: function(event, ui){
+                $this.closest('div').find("input[id$='institution']").val(ui.item.institution);
+                $this.closest('div').find("input[id$='email']").val(ui.item.email);
 
-            $this.closest('div').find("input[id$='search_author_class']").val(ui.item.search_author_class);
-            $this.closest('div').find("input[id$='search_author_id']").val(ui.item.search_author_id);
+                $this.closest('div').find("input[id$='search_author_class']").val(ui.item.  search_author_class);
+                $this.closest('div').find("input[id$='search_author_id']").val(ui.item. search_author_id);
 
-            $this.closest('div').find("input[id$='search_author_tie']").attr('checked', 'checked');
-            $this.closest('div').find("input[id$='search_author_tie']").next('span').replaceWith(ui.item.authorship_link);
+                $this.closest('div').find("input[id$='search_author_tie']").attr('checked', '   checked');
+                $this.closest('div').find("input[id$='search_author_tie']").next('span').   replaceWith(ui.item.authorship_link);
 
-            // triggers the save button
-            $this.closest('div').next('div').find('.author_save_btn').click();
-        }
-        })
-        .data( "autocomplete" )._renderItem = function( ul, item ) {
-            return $( "<li>" )
-                .data("item.autocomplete", item )
-                .append( "<a>" + item.label + "<br><em>" + item.email + "</em><br>" + item.institution + "</a>" )
-                .appendTo(ul);
-            };
-        });
-
+                // triggers the save button
+                $this.closest('div').next('div').find('.author_save_btn').click();
+            }
+            })
+            .data( "autocomplete" )._renderItem = function( ul, item ) {
+                return $( "<li>" )
+                    .data("item.autocomplete", item )
+                    .append( "<a>" + item.label + "<br><em>" + item.email + "</em><br>" + item. institution + "</a>" )
+                    .appendTo(ul);
+                };
+            });
+}