# HG changeset patch # User luisf # Date 1313456796 -3600 # Node ID 84e8d34d024cc2eea181cad7c16f9deec77c281f # Parent 7234e0a90c628625675a51b2a73702109b6979b6 DEV Commit: now generating the seach "author select box" with the appropriate options and element names and id's, so that it gets correctly submitted with the form. diff -r 7234e0a90c62 -r 84e8d34d024c vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon Aug 15 16:18:00 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Tue Aug 16 02:06:36 2011 +0100 @@ -203,6 +203,10 @@ @results = [] + @object_name = params[:object_name] + + logger.error { "OBJECT NAME #{@object_name}" } + authorships_list = Authorship.like(params[:q]).find(:all, :limit => 100) users_list = User.active.like(params[:q]).find(:all, :limit => 100) diff -r 7234e0a90c62 -r 84e8d34d024c vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Mon Aug 15 16:18:00 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Tue Aug 16 02:06:36 2011 +0100 @@ -47,52 +47,22 @@ link_to_function(link_text, "update_author_info(this," + item_info.to_json + ")") + ' ' + suffix end - def choose_author_link(items) + 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 - - s = '' - list = [] - - items.sort.each do |item| - if item.respond_to? :name_on_paper - logger.error { "CHOOSE AUTHOR LINK - Authorship #{item.id}" } - list << item - else - logger.error { "CHOOSE AUTHOR LINK: USER #{item.id}" } - - list << item - unless item.author.nil? - unless item.author.authorships.nil? - list << item.author.authorships - list.flatten! - end - end - end - end - - if list.length > 0 - list.each do |element| - s << "
  • #{generate_autofill_suggestions element}
  • " - end - end - - - + @author_options = [] @results.each do |result| @author_options << ["#{result.name} (#{result.mail})", "#{result.class.to_s}_#{result.id.to_s}"] end -# if @results.size > 0 -# s = select('country', options_for_select(@options), :size => 3) -# s << observe_field( 'country', :on => 'click', :function => "alert('Element changed')", :with => 'q') -# -# else -# s = "No Authors found that match your search… sorry!" -# 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} ) + s << observe_field( form_tag_id(object_name, :author_search_results), :on => 'click', :function => "alert('Element changed')", :with => 'q') + else + s = "No Authors found that match your search… sorry!" + end end def link_to_remove_fields(name, f) @@ -114,7 +84,12 @@ def sanitized_method_name(method_name) method_name.sub(/\?$/, "") end - + + def form_tag_name(object_name, method_name) + str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]" + str.to_sym + end + def form_tag_id(object_name, method_name) str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}" str.to_sym diff -r 7234e0a90c62 -r 84e8d34d024c vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Mon Aug 15 16:18:00 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Tue Aug 16 02:06:36 2011 +0100 @@ -5,7 +5,7 @@

    <%= f.text_field :search_name, :size => 25 %> - <%= observe_field( form_tag_id(f.object_name, :search_name), :frequency => 0.5, :url => { :controller => 'publications', :action => 'autocomplete_for_author' }, :with => 'q') %> + <%= observe_field( form_tag_id(f.object_name, :search_name), :frequency => 0.5, :update => form_tag_id( f.object_name, :identify_author_results), :url => { :controller => 'publications', :action => 'autocomplete_for_author', :object_name => f.object_name }, :with => 'q' ) %> <%= link_to_function l(:label_author_is_me), "update_author_info(this," + User.current.get_author_info.to_json + ")", :id => "add_me_as_author" %>
    @@ -14,8 +14,8 @@

    - - <%= f.select :search_results, options_for_select(@author_options), :size => 3 %> +

    +

    <%= f.radio_button :add_this_author, false %> <%= f.radio_button :add_this_author, false %> diff -r 7234e0a90c62 -r 84e8d34d024c vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml Mon Aug 15 16:18:00 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml Tue Aug 16 02:06:36 2011 +0100 @@ -1,4 +1,4 @@ <% if params[:q] && params[:q].length > 1 %> - <% choose_author_link @results %> + <%= choose_author_link @object_name, @results %> <% end %>