# HG changeset patch # User luisf # Date 1308672788 -3600 # Node ID fbdfec975bfa8a3249d4554cf6d51d4beecb5555 # Parent af5f6d56dc3af5d4f5168f8e739c95ee1006d2d1 correctly adding more than one project to a publication. diff -r af5f6d56dc3a -r fbdfec975bfa vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Tue Jun 21 11:07:51 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Tue Jun 21 17:13:08 2011 +0100 @@ -183,21 +183,23 @@ def add_project - Rails.logger.debug { "ADD PROJECT" } + @projects = Project.find(params[:publication][:project_ids]) + @publication = Publication.find(params[:id]) + @publication.projects << @projects - @project = Project.find(params[:project_id]) - @publication = Publication.find(params[:id]) - - @publication.projects << @project - + # TODO luisf should also respond to HTML??? + respond_to do |format| + format.js + end end - def autocomplete_for_project @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.error "aaaaaaaa" + logger.error { @publication.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 diff -r af5f6d56dc3a -r fbdfec975bfa vendor/plugins/redmine_bibliography/app/models/publication.rb --- a/vendor/plugins/redmine_bibliography/app/models/publication.rb Tue Jun 21 11:07:51 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/publication.rb Tue Jun 21 17:13:08 2011 +0100 @@ -14,7 +14,7 @@ accepts_nested_attributes_for :authors, :allow_destroy => true accepts_nested_attributes_for :bibtex_entry, :allow_destroy => true - has_and_belongs_to_many :projects + has_and_belongs_to_many :projects, :uniq => true attr_writer :current_step diff -r af5f6d56dc3a -r fbdfec975bfa vendor/plugins/redmine_bibliography/app/views/publications/_add_project_form.html.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_add_project_form.html.erb Tue Jun 21 17:13:08 2011 +0100 @@ -0,0 +1,29 @@ +<% form_remote_for(:publication, + :url => {:controller => 'publications', :action => 'add_project', :id => @publication, :project_id => @project}, + :method => :post, + :html => { :id => 'add_project_form' }, + :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 }, + :with => 'q') + %> + +
+ <% if params[:q] && params[:q].length > 1 %> + <%= projects_check_box_tags 'project[project_ids][]', @projects %> + <% end %> +
+ +

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

+ + +
+ <% end %> diff -r af5f6d56dc3a -r fbdfec975bfa vendor/plugins/redmine_bibliography/app/views/publications/_list_projects.html.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_list_projects.html.erb Tue Jun 21 17:13:08 2011 +0100 @@ -0,0 +1,3 @@ +<% @publication.projects.each do |proj| %> + <%= link_to_project proj %> +<% end %> \ No newline at end of file diff -r af5f6d56dc3a -r fbdfec975bfa vendor/plugins/redmine_bibliography/app/views/publications/add_project.rjs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/add_project.rjs Tue Jun 21 17:13:08 2011 +0100 @@ -0,0 +1,3 @@ +page.replace_html :list_projects, :partial => 'list_projects' +page[:add_project_form].reset + diff -r af5f6d56dc3a -r fbdfec975bfa vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Tue Jun 21 11:07:51 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Tue Jun 21 17:13:08 2011 +0100 @@ -1,41 +1,9 @@

New Publication

- -
<%= 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 }, - :with => 'q') - %> - -
- <% if params[:q] && params[:q].length > 1 %> - <%= projects_check_box_tags 'project[project_ids][]', @projects %> - <% end %> -
- -

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

- - -
- <% end %> -
\ No newline at end of file diff -r af5f6d56dc3a -r fbdfec975bfa vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Tue Jun 21 11:07:51 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Tue Jun 21 17:13:08 2011 +0100 @@ -1,4 +1,6 @@

Publication Details

+ +

Title

<%= h @publication.title %> @@ -18,12 +20,24 @@ <%- end -%> <%- end -%> - -

<%= link_to "Edit", edit_publication_path(@publication) %> | <%= link_to "Destroy", @publication, :confirm => 'Are you sure?', :method => :delete %> | <%= link_to "View All", publications_path %>

+
+<% projects = Project.active.find(:all, :limit => 100, :order => 'name ASC') - @publication.projects %> + +
+ + +

List of Projects

+

+ <%= render :partial => 'list_projects' %> +

+ + <%= render :partial => 'add_project_form' %> + +
\ No newline at end of file diff -r af5f6d56dc3a -r fbdfec975bfa vendor/plugins/redmine_bibliography/lib/bibliography/project_publications_patch.rb --- a/vendor/plugins/redmine_bibliography/lib/bibliography/project_publications_patch.rb Tue Jun 21 11:07:51 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/lib/bibliography/project_publications_patch.rb Tue Jun 21 17:13:08 2011 +0100 @@ -4,7 +4,7 @@ module ProjectPublicationsPatch def self.included(base) base.class_eval do - has_and_belongs_to_many :publications + has_and_belongs_to_many :publications, :uniq => true named_scope :like, lambda {|q| s = "%#{q.to_s.strip.downcase}%"