# HG changeset patch # User Chris Cannam # Date 1312984185 -3600 # Node ID e98a5b2fe3b8e2d752a31ca3c10a435f57d83e19 # Parent c5858d96b9a493e922857875c8c83726b486c9b7# Parent 724c97fc03dc0e09b4db4c4bfea8eecf7d593ec1 Merge diff -r c5858d96b9a4 -r e98a5b2fe3b8 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Wed Aug 10 14:49:36 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Wed Aug 10 14:49:45 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 c5858d96b9a4 -r e98a5b2fe3b8 vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Wed Aug 10 14:49:36 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Wed Aug 10 14:49:45 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 diff -r c5858d96b9a4 -r e98a5b2fe3b8 vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb Wed Aug 10 14:49:36 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb Wed Aug 10 14:49:45 2011 +0100 @@ -8,11 +8,11 @@

<%= l(:authors) %>

- <% f.fields_for :authorships do |builder| %> - <%= render "authorship_fields", :f => builder %> - <% end %> + <% f.fields_for :authorships do |builder| %> + <%= render "authorship_fields", :f => builder %> + <% end %> - <%= link_to_add_fields l(:label_add_another_author), f, :authorships %> + <%= link_to_add_fields l(:label_add_another_author), f, :authorships %>
diff -r c5858d96b9a4 -r e98a5b2fe3b8 vendor/plugins/redmine_bibliography/assets/javascripts/authors.js --- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Wed Aug 10 14:49:36 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Wed Aug 10 14:49:45 2011 +0100 @@ -6,7 +6,7 @@ function add_fields(link, association, content) { var new_id = new Date().getTime(); var regexp = new RegExp("new_" + association, "g") - $(link).up().insert({ + $(link).insert({ before: content.replace(regexp, new_id) }); }