From d29638845a9c5d69f9ad6e9ab8c81ed29c808c3f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 7 Jan 2012 16:18:53 +0000 Subject: Allows project to be changed from the bulk edit form. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8536 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 39 ++++++++++++++++++++++++++++++------ app/views/issues/bulk_edit.html.erb | 21 +++++++++++++++++-- 2 files changed, 52 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 076a3a663..ff8d2d0e1 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -209,10 +209,25 @@ class IssuesController < ApplicationController # Bulk edit a set of issues def bulk_edit @issues.sort! - @available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w} - @custom_fields = @projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c} - @assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a} - @trackers = @projects.map(&:trackers).inject{|memo,t| memo & t} + + if User.current.allowed_to?(:move_issues, @projects) + @allowed_projects = Issue.allowed_target_projects_on_move + if params[:issue] + @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id]} + if @target_project + target_projects = [@target_project] + end + end + end + target_projects ||= @projects + + @available_statuses = target_projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w} + @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c} + @assignables = target_projects.map(&:assignable_users).inject{|memo,a| memo & a} + @trackers = target_projects.map(&:trackers).inject{|memo,t| memo & t} + + @notes = params[:notes] + render :layout => false if request.xhr? end def bulk_update @@ -220,18 +235,30 @@ class IssuesController < ApplicationController attributes = parse_params_for_bulk_issue_attributes(params) unsaved_issue_ids = [] + moved_issues = [] @issues.each do |issue| issue.reload journal = issue.init_journal(User.current, params[:notes]) issue.safe_attributes = attributes call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) - unless issue.save + if issue.save + moved_issues << issue + else # Keep unsaved issue ids to display them in flash error unsaved_issue_ids << issue.id end end set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) - redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) + + if params[:follow] + if @issues.size == 1 && moved_issues.size == 1 + redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first + elsif moved_issues.map(&:project).uniq.size == 1 + redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first + end + else + redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) + end end verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed } diff --git a/app/views/issues/bulk_edit.html.erb b/app/views/issues/bulk_edit.html.erb index 2a62a09ee..9161654ac 100644 --- a/app/views/issues/bulk_edit.html.erb +++ b/app/views/issues/bulk_edit.html.erb @@ -7,13 +7,22 @@ ) + h(": #{i.subject}")) }.join("\n").html_safe %> -<% form_tag(:action => 'bulk_update') do %> +<% form_tag({:action => 'bulk_update'}, :id => 'bulk_edit_form') do %> <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
<%= l(:label_change_properties) %>
+<% if @allowed_projects.present? %> +

+ + <%= select_tag('issue[project_id]', "" + project_tree_options_for_select(@allowed_projects, :selected => @target_project)) %> +

+<%= observe_field :issue_project_id, :url => {:action => 'bulk_edit'}, + :update => 'content', + :with => "Form.serialize('bulk_edit_form')" %> +<% end %>

<%= select_tag('issue[tracker_id]', "" + options_from_collection_for_select(@trackers, :id, :name)) %> @@ -92,5 +101,13 @@

-

<%= submit_tag l(:button_submit) %>

+

+ <% if @target_project %> + <%= submit_tag l(:button_move) %> + <%= submit_tag l(:button_move_and_follow), :name => 'follow' %> + <% else %> + <%= submit_tag l(:button_submit) %> + <% end %> +

+ <% end %> -- cgit v1.2.3