changeset 461:841b2e40895d feature_36

Adding other projects to publication - created query for projects and controller actions to be used in the AJAX call; still need to get the AJAX call working
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 17 Jun 2011 18:59:49 +0100
parents 9bdb8e3b9135
children b02b2eb2a312
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb vendor/plugins/redmine_bibliography/config/locales/en.yml vendor/plugins/redmine_bibliography/lib/bibliography/project_publications_patch.rb
diffstat 4 files changed, 70 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Thu Jun 16 13:45:19 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Fri Jun 17 18:59:49 2011 +0100
@@ -180,11 +180,27 @@
     
   end
 
-  def review_new_entries
+  
+  def add_project
+    Rails.logger.debug { "ADD PROJECT" }
+    
+    @project = Project.find(params[:project_id])    
+    @publication = Publication.find(params[:id])
+    
+    @publication.projects << @project
+    
+  end
 
+
+  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
+    logger.debug "Query for \"#{params[:q]}\" returned \"#{@projects.size}\" results"
+    render :layout => false
   end
   
-  
   private
    
   # TODO: luisf. - only here for debugging purposes 
--- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Thu Jun 16 13:45:19 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Fri Jun 17 18:59:49 2011 +0100
@@ -1,3 +1,37 @@
 <h1>New Publication</h1>
 
-<%= render :partial => 'edit' %>
+
+
+<div class="splitcontentleft">
+  <%= render :partial => 'edit' %>
+</div>
+
+
+<% projects = Project.active.find(:all, :limit => 100, :order => 'name ASC') - @publication.projects %>
+
+<div class="splitcontentright">
+
+  <% form_remote_for(:project, @project, 
+                     :url => {:controller => 'publication', :action => 'new', :id => @publication.id, :project_id => @project}, 
+                     :method => :post,
+									   :loading => "$('project-add-submit').disable()",
+									   :complete => "$('project-add-submit').enable()") do |f| %>
+      
+      <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},
+               :with => 'q')
+                %>
+
+        <p><%= submit_tag l(:button_add), :id => 'project-add-submit' %></p>
+    
+    
+      </fieldset>
+  <% end %>
+    
+</div>
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/config/locales/en.yml	Thu Jun 16 13:45:19 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/config/locales/en.yml	Fri Jun 17 18:59:49 2011 +0100
@@ -8,6 +8,8 @@
   remove: "Remove"
   
   label_publication_new: "Add Publication"
+  label_add_project_to_publication: "Add Project to Publication"
+  label_project_search: "Search by name: "
   
       
   # bibtex_entries strings
--- a/vendor/plugins/redmine_bibliography/lib/bibliography/project_publications_patch.rb	Thu Jun 16 13:45:19 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/lib/bibliography/project_publications_patch.rb	Fri Jun 17 18:59:49 2011 +0100
@@ -5,7 +5,21 @@
     def self.included(base)
           base.class_eval do
             has_and_belongs_to_many :publications
+          
+            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}],
+               :order => 'name'
+              }
+            }
           end
-        end
+    end #self.included
+        
+    module ProjectMethods
+
+
+
+    
+    end #ProjectMethods
   end #ProjectPublicationsPatch
 end #RedmineBibliography
\ No newline at end of file