# HG changeset patch # User luisf # Date 1312983040 -3600 # Node ID f463be9d101ac86db915189eb95f172491ca159a # Parent e1699e8d6d69341d580ca887579d94d896696e73 some changes to add/remove projects. Not Finished. diff -r e1699e8d6d69 -r f463be9d101a vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Tue Aug 09 15:55:08 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Wed Aug 10 14:30:40 2011 +0100 @@ -98,7 +98,7 @@ def show find_project_by_project_id unless params[:project_id].nil? - + @publication = Publication.find(params[:id]) if @publication.nil? @@ -189,17 +189,6 @@ end - def add_project - @projects = Project.find(params[:publication][:project_ids]) - @publication = Publication.find(params[:id]) - @publication.projects << @projects - - # TODO luisf should also respond to HTML??? - respond_to do |format| - format.js - end - end - def autocomplete_for_project @publication = Publication.find(params[:id]) @@ -235,24 +224,47 @@ end render :nothing => true end + + def add_project + @projects = Project.find(params[:publication][:project_ids]) + @publication.projects << @projects + + # TODO luisf should also respond to HTML??? + respond_to do |format| + format.html { redirect_to :back } + format.js { + render(:update) {|page| + page[:add_project_form].reset + page.replace_html :list_projects, :partial => 'list_projects' + } + } + end + end - def remove_from_project_list - pub = Publication.find(params[:id]) - proj = Project.find(params[:project_id]) + def remove_project + find_project_by_project_id + proj_to_remove = Project.find(params[:remove_project_id]) + + if proj_to_remove == @project + warning = "You are about to remove the current project from the publication's project list. Are you sure?" + end - if pub.projects.length > 1 - if pub.projects.exists? proj - pub.projects.delete proj if request.post? + if @publication.projects.length > 1 + if @publication.projects.exists? proj_to_remove + @publication.projects.delete proj_to_remove if request.post? end else - logger.error { "Cannot remove project from publication list" } + logger.error { "Cannot remove project from publication list" } end respond_to do |format| - format.js { render(:update) {|page| page.replace_html "list_projects", :partial => 'list_projects', :id => pub} } + format.html { redirect_to :back } + format.js { + render(:update) {|page| + page.replace_html :list_projects, :partial => 'list_projects' + } + } end - - end def destroy diff -r e1699e8d6d69 -r f463be9d101a vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Tue Aug 09 15:55:08 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Wed Aug 10 14:30:40 2011 +0100 @@ -77,9 +77,9 @@ def render_projects_list(publication) s = "" - + publication.projects.each do |proj| - s << link_to_project(proj) + link_to_remote(l(:button_delete), { :url => { :controller => 'publications', :action => 'remove_from_project_list', :id => publication, :project_id => proj }, :method => :post }, :class => 'icon icon-del') + "
" + s << link_to_project(proj) + link_to_remote(l(:button_delete), { :url => { :controller => 'publications', :action => 'remove_project', :id => publication, :remove_project_id => proj, :project_id => @project }, :method => :post }, :class => 'icon icon-del') + "
" end s