changeset 462:b02b2eb2a312 feature_36

Searching for publications via AJAX call; the publication ID is not being sent correctly, so still shows the current publication's associated projects in the select list.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 21 Jun 2011 01:27:41 +0100
parents 841b2e40895d
children af5f6d56dc3a
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/new.html.erb vendor/plugins/redmine_bibliography/lib/bibliography/project_publications_patch.rb
diffstat 4 files changed, 20 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Fri Jun 17 18:59:49 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Tue Jun 21 01:27:41 2011 +0100
@@ -3,7 +3,8 @@
 class PublicationsController < ApplicationController
   unloadable
   
-  before_filter :find_project_by_project_id
+  before_filter :find_project_by_project_id, :except => [:autocomplete_for_project]
+  
   
   def new
     @publication = Publication.new      
@@ -193,10 +194,10 @@
 
 
   def autocomplete_for_project
-    # TODO luisf - Should This Be HERE???
     @publication = Publication.find(params[:id])
-    
     @projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects
+            
+#    @projects = Project.active.like(params[:q]).find(:all, :limit => 100)
     logger.debug "Query for \"#{params[:q]}\" returned \"#{@projects.size}\" results"
     render :layout => false
   end
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Fri Jun 17 18:59:49 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Tue Jun 21 01:27:41 2011 +0100
@@ -2,4 +2,11 @@
 
 module PublicationsHelper
 
+  def projects_check_box_tags(name, projects)
+    s = ''
+    projects.sort.each do |project|
+      s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
+    end
+    s 
+  end
 end
--- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Fri Jun 17 18:59:49 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Tue Jun 21 01:27:41 2011 +0100
@@ -16,18 +16,22 @@
                      :method => :post,
 									   :loading => "$('project-add-submit').disable()",
 									   :complete => "$('project-add-submit').enable()") do |f| %>
-      
-      <fieldset><legend><%=l(:label_add_project_to_publication)%></legend>
-    
+								<fieldset><legend><%=l(:label_add_project_to_publication)%></legend>
 	      <p><%= label_tag "project_search", l(:label_project_search) %><%= text_field_tag 'project_search', nil %></p>
 	     
 	      <%= observe_field(:project_search,
                :frequency => 0.5,
                :update => :projects,
-               :url => { :controller => 'publications', :action => 'autocomplete_for_project', :id => @publication, :project_id => @project},
+               :url => { :controller => 'publications', :action => 'autocomplete_for_project', :id => @publication },
                :with => 'q')
                 %>
 
+					<div id="projects">
+					<% if params[:q] && params[:q].length > 1 %>
+			  		  <%= projects_check_box_tags 'project[project_ids][]', @projects %>
+					<% end %>
+					</div>
+
         <p><%= submit_tag l(:button_add), :id => 'project-add-submit' %></p>
     
     
--- a/vendor/plugins/redmine_bibliography/lib/bibliography/project_publications_patch.rb	Fri Jun 17 18:59:49 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/lib/bibliography/project_publications_patch.rb	Tue Jun 21 01:27:41 2011 +0100
@@ -8,7 +8,7 @@
           
             named_scope :like, lambda {|q| 
               s = "%#{q.to_s.strip.downcase}%"
-              {:conditions => ["LOWER(name) LIKE :s OR LOWER(description) LIKE :s OR LOWER(homepage) LIKE :s", {:s => s}],
+              {:conditions => ["LOWER(name) LIKE :s OR LOWER(homepage) LIKE :s", {:s => s}],
                :order => 'name'
               }
             }