changeset 595:84e8d34d024c feature_36

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.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 16 Aug 2011 02:06:36 +0100
parents 7234e0a90c62
children fcff84e1c1ce
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml
diffstat 4 files changed, 22 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- 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)
 
--- 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 + ")") + '&nbsp;' + 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 << "<li>#{generate_autofill_suggestions element}</li>"
-      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 = "<em>No Authors found that match your search… sorry!</em>"
-#   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 = "<em>No Authors found that match your search… sorry!</em>"
+   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
--- 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 @@
   <p>
 	<%= 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" %>
 	<br />
@@ -14,8 +14,8 @@
 
   <p>
     <div id="<%= form_tag_id( f.object_name, :identify_author ) %>">		
-
-			<%= f.select :search_results, options_for_select(@author_options), :size => 3 %>
+		<p id="<%= form_tag_id( f.object_name, :identify_author_results ) %>">
+		</p>
 
 			<%= f.radio_button :add_this_author, false %>
 			<%= f.radio_button :add_this_author, false %>
--- 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 %>