Mercurial > hg > soundsoftware-site
changeset 464:fbdfec975bfa feature_36
correctly adding more than one project to a publication.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Tue, 21 Jun 2011 17:13:08 +0100 |
parents | af5f6d56dc3a |
children | 5123e3a1c9cb |
files | vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/models/publication.rb vendor/plugins/redmine_bibliography/app/views/publications/_add_project_form.html.erb vendor/plugins/redmine_bibliography/app/views/publications/_list_projects.html.erb vendor/plugins/redmine_bibliography/app/views/publications/add_project.rjs vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb vendor/plugins/redmine_bibliography/lib/bibliography/project_publications_patch.rb |
diffstat | 8 files changed, 65 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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
--- /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| %> + <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 }, + :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> + + + </fieldset> + <% end %>
--- /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
--- /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 +
--- 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 @@ <h1>New Publication</h1> - - <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 }, - :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> - - - </fieldset> - <% end %> - </div> \ No newline at end of file
--- 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 @@ <h2>Publication Details</h2> + +<div class="splitcontentleft"> <h4>Title</h4> <%= h @publication.title %> @@ -18,12 +20,24 @@ <%- end -%> <%- end -%> - - <p> <%= link_to "Edit", edit_publication_path(@publication) %> | <%= link_to "Destroy", @publication, :confirm => 'Are you sure?', :method => :delete %> | <%= link_to "View All", publications_path %> </p> +</div> +<% projects = Project.active.find(:all, :limit => 100, :order => 'name ASC') - @publication.projects %> + +<div class="splitcontentright"> + + + <h4>List of Projects</h4> + <p id="list_projects"> + <%= render :partial => 'list_projects' %> + </p> + + <%= render :partial => 'add_project_form' %> + +</div> \ No newline at end of file
--- 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}%"