# HG changeset patch # User luisf # Date 1368543080 -3600 # Node ID 3ce07a57ce681fb574573149b7ee273729d52efb # Parent 006057cf8f165b7ef07e479b441d9d85b9a6d5bc Correctly adds the author info to the input fields; corrected toggle function. diff -r 006057cf8f16 -r 3ce07a57ce68 plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/plugins/redmine_bibliography/app/helpers/publications_helper.rb Tue May 14 14:24:45 2013 +0100 +++ b/plugins/redmine_bibliography/app/helpers/publications_helper.rb Tue May 14 15:51:20 2013 +0100 @@ -21,26 +21,8 @@ s end - def choose_author_link(object_name, items) - # called by autocomplete_for_author (publications' action/view) - # creates the select list based on the results array - # results is an array with both Users and Authorships objects - @author_options = [] - @results.each do |result| - email_bit = result.mail.partition('@')[2] - if email_bit != "" - email_bit = "(@#{email_bit})" - end - @author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"] - end - if @results.size > 0 - s = select_tag( form_tag_name(object_name, :author_search_results), options_for_select(@author_options), { :id => form_tag_id(object_name, :author_search_results), :size => 3} ) - else - s = "No Authors found that match your search… sorry!" - end - end def link_to_remove_fields(name, f) f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del') @@ -77,6 +59,32 @@ str.to_sym end + ####### + ### DELETE ME + + def choose_author_link(object_name, items) + # called by autocomplete_for_author (publications' action/view) + # creates the select list based on the results array + # results is an array with both Users and Authorships objects + + @author_options = [] + @results.each do |result| + email_bit = result.mail.partition('@')[2] + if email_bit != "" + email_bit = "(@#{email_bit})" + end + @author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"] + end + + if @results.size > 0 + s = select_tag( form_tag_name(object_name, :author_search_results), options_for_select(@author_options), { :id => form_tag_id(object_name, :author_search_results), :size => 3} ) + else + s = "No Authors found that match your search… sorry!" + end + end + + + def render_authorships_list(publication) s = '

' diff -r 006057cf8f16 -r 3ce07a57ce68 plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb --- a/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb Tue May 14 14:24:45 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb Tue May 14 15:51:20 2013 +0100 @@ -2,7 +2,9 @@ 'id' => result.id, 'label' => "#{result.name} (#{result.mail.partition('@')[2]})", 'value' => result.name, - 'type' => result.class, + 'type' => result.class.name, + 'institution' => result.institution, + 'email' => result.mail, } }.to_json -%> +%> \ No newline at end of file diff -r 006057cf8f16 -r 3ce07a57ce68 plugins/redmine_bibliography/assets/javascripts/authors.js --- a/plugins/redmine_bibliography/assets/javascripts/authors.js Tue May 14 14:24:45 2013 +0100 +++ b/plugins/redmine_bibliography/assets/javascripts/authors.js Tue May 14 15:51:20 2013 +0100 @@ -15,39 +15,51 @@ } $(".author_search").live('keyup.autocomplete', function(){ - $(this).autocomplete({ + $this = $(this); + + $this.autocomplete({ source: '/publications/autocomplete_for_author', minLength: 2, select: function(event, ui){ - alert("gOtChA " + ui.item.id + " " + ui.item.type); + $this.closest('div').next().find("input[id$='name_on_paper']").val(ui.item.value); + $this.closest('div').next().find("input[id$='institution']").val(ui.item.institution); + $this.closest('div').next().find("input[id$='email']").val(ui.item.email); } }); }); + + + function identify_author_status(status, object_id) { $('publication_authorships_attributes_' + object_id + '_edit_author_info').select('input').each(function(s) { - if(status == "no"){ - s.value = ""; - s.readOnly = false; - }; - if(status == "correct"){s.readOnly = false;}; - if(status == "yes"){s.readOnly = true;}; + if(status == "no"){ + s.value = ""; + s.readOnly = false; + } + + if(status == "correct"){ + s.readOnly = false; + } + if(status == "yes"){ + s.readOnly = true; + } }); } function toggle_div(div_id){ - Effect.toggle(div_id, "appear", {duration:0.3}); + $("#" + div_id).toggle(0.3); } function toggle_input_field(field){ - if (field.classNames().inspect().include("readonly") == false){ + if (field.classNames().inspect().include("readonly") === false){ field.readOnly = true; field.addClassName('readonly'); } else { field.readOnly = false; field.removeClassName('readonly'); - }; + } } function toggle_edit_save_button(object_id){