# HG changeset patch # User luisf # Date 1380629117 -3600 # Node ID 3cb633d4b37dd0b6faecd540f12697aef03b2b9e # Parent b09744f35f76a39519f07eb5df6dd547e2a12fcd Authorship autocomplete is now a function. diff -r b09744f35f76 -r 3cb633d4b37d plugins/redmine_bibliography/app/views/publications/edit.html.erb --- 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' %> diff -r b09744f35f76 -r 3cb633d4b37d plugins/redmine_bibliography/app/views/publications/new.html.erb --- 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' %> diff -r b09744f35f76 -r 3cb633d4b37d plugins/redmine_bibliography/assets/javascripts/authors.js --- 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 $( "
  • " ) - .data("item.autocomplete", item ) - .append( "" + item.label + "
    " + item.email + "
    " + item.institution + "
    " ) - .appendTo(ul); - }; - }); - + // triggers the save button + $this.closest('div').next('div').find('.author_save_btn').click(); + } + }) + .data( "autocomplete" )._renderItem = function( ul, item ) { + return $( "
  • " ) + .data("item.autocomplete", item ) + .append( "" + item.label + "
    " + item.email + "
    " + item. institution + "
    " ) + .appendTo(ul); + }; + }); +}