From fbf30eec7c58786d615852bc17ffe5a1c49229b6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 20 Jan 2012 18:22:43 +0000 Subject: Adds an option of the copy form to enable/disable attachments copy (#3055). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8677 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 14 +++++++++----- app/models/issue.rb | 8 +++++--- app/views/issues/new.html.erb | 7 +++++++ 3 files changed, 21 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 82fa5f8ea..e3e6ffedc 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -360,11 +360,15 @@ private def build_new_issue_from_params if params[:id].blank? @issue = Issue.new - begin - @issue.copy_from(params[:copy_from]) if params[:copy_from] - rescue ActiveRecord::RecordNotFound - render_404 - return + if params[:copy_from] + begin + @copy_from = Issue.visible.find(params[:copy_from]) + @copy_attachments = params[:copy_attachments].present? || request.get? + @issue.copy_from(@copy_from, :attachments => @copy_attachments) + rescue ActiveRecord::RecordNotFound + render_404 + return + end end @issue.project = @project else diff --git a/app/models/issue.rb b/app/models/issue.rb index 16257bf83..ad91ab488 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -129,14 +129,16 @@ class Issue < ActiveRecord::Base end # Copies attributes from another issue, arg can be an id or an Issue - def copy_from(arg) + def copy_from(arg, options={}) issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg) self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on") self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h} self.status = issue.status self.author = User.current - self.attachments = issue.attachments.map do |attachement| - attachement.copy(:container => self) + unless options[:attachments] == false + self.attachments = issue.attachments.map do |attachement| + attachement.copy(:container => self) + end end @copied_from = issue self diff --git a/app/views/issues/new.html.erb b/app/views/issues/new.html.erb index 7ff994de5..bddb62788 100644 --- a/app/views/issues/new.html.erb +++ b/app/views/issues/new.html.erb @@ -11,6 +11,13 @@ <%= render :partial => 'issues/form', :locals => {:f => f} %> + <% if @copy_from && @copy_from.attachments.any? %> +

+ + <%= check_box_tag 'copy_attachments', '1', @copy_attachments %> +

+ <% end %> +

<%= label_tag('attachments[1][file]', l(:label_attachment_plural))%><%= render :partial => 'attachments/form' %>

<% if @issue.safe_attribute? 'watcher_user_ids' -%> -- cgit v1.2.3