# HG changeset patch # User luisf # Date 1308333589 -3600 # Node ID 841b2e40895dc1cea6f6f00460de5d805987fd40 # Parent 9bdb8e3b9135d91b6a67143eef1f5614aebeea53 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 diff -r 9bdb8e3b9135 -r 841b2e40895d vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- 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 diff -r 9bdb8e3b9135 -r 841b2e40895d vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb --- 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 @@

New Publication

-<%= render :partial => 'edit' %> + + +
+ <%= render :partial => 'edit' %> +
+ + +<% projects = Project.active.find(:all, :limit => 100, :order => 'name ASC') - @publication.projects %> + +
+ + <% 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| %> + +
<%=l(:label_add_project_to_publication)%> + +

<%= label_tag "project_search", l(:label_project_search) %><%= text_field_tag 'project_search', nil %>

+ + <%= observe_field(:project_search, + :frequency => 0.5, + :update => :projects, + :url => { :controller => 'publications', :action => 'autocomplete_for_project', :id => @publication, :project_id => @project}, + :with => 'q') + %> + +

<%= submit_tag l(:button_add), :id => 'project-add-submit' %>

+ + +
+ <% end %> + +
\ No newline at end of file diff -r 9bdb8e3b9135 -r 841b2e40895d vendor/plugins/redmine_bibliography/config/locales/en.yml --- 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 diff -r 9bdb8e3b9135 -r 841b2e40895d vendor/plugins/redmine_bibliography/lib/bibliography/project_publications_patch.rb --- 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