@@ -1,68 +1,87 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
1 | class IssueMovesController < ApplicationController |
|
18 | class IssueMovesController < ApplicationController | |
|
19 | menu_item :issues | |||
|
20 | ||||
2 | default_search_scope :issues |
|
21 | default_search_scope :issues | |
3 | before_filter :find_issues, :check_project_uniqueness |
|
22 | before_filter :find_issues, :check_project_uniqueness | |
4 | before_filter :authorize |
|
23 | before_filter :authorize | |
5 |
|
24 | |||
6 | def new |
|
25 | def new | |
7 | prepare_for_issue_move |
|
26 | prepare_for_issue_move | |
8 | render :layout => false if request.xhr? |
|
27 | render :layout => false if request.xhr? | |
9 | end |
|
28 | end | |
10 |
|
29 | |||
11 | def create |
|
30 | def create | |
12 | prepare_for_issue_move |
|
31 | prepare_for_issue_move | |
13 |
|
32 | |||
14 | if request.post? |
|
33 | if request.post? | |
15 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) |
|
34 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) | |
16 | unsaved_issue_ids = [] |
|
35 | unsaved_issue_ids = [] | |
17 | moved_issues = [] |
|
36 | moved_issues = [] | |
18 | @issues.each do |issue| |
|
37 | @issues.each do |issue| | |
19 | issue.reload |
|
38 | issue.reload | |
20 | issue.init_journal(User.current) |
|
39 | issue.init_journal(User.current) | |
21 | issue.current_journal.notes = @notes if @notes.present? |
|
40 | issue.current_journal.notes = @notes if @notes.present? | |
22 | call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy }) |
|
41 | call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy }) | |
23 | if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)}) |
|
42 | if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)}) | |
24 | moved_issues << r |
|
43 | moved_issues << r | |
25 | else |
|
44 | else | |
26 | unsaved_issue_ids << issue.id |
|
45 | unsaved_issue_ids << issue.id | |
27 | end |
|
46 | end | |
28 | end |
|
47 | end | |
29 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) |
|
48 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) | |
30 |
|
49 | |||
31 | if params[:follow] |
|
50 | if params[:follow] | |
32 | if @issues.size == 1 && moved_issues.size == 1 |
|
51 | if @issues.size == 1 && moved_issues.size == 1 | |
33 | redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first |
|
52 | redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first | |
34 | else |
|
53 | else | |
35 | redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project) |
|
54 | redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project) | |
36 | end |
|
55 | end | |
37 | else |
|
56 | else | |
38 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
57 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
39 | end |
|
58 | end | |
40 | return |
|
59 | return | |
41 | end |
|
60 | end | |
42 | end |
|
61 | end | |
43 |
|
62 | |||
44 | private |
|
63 | private | |
45 |
|
64 | |||
46 | def prepare_for_issue_move |
|
65 | def prepare_for_issue_move | |
47 | @issues.sort! |
|
66 | @issues.sort! | |
48 | @copy = params[:copy_options] && params[:copy_options][:copy] |
|
67 | @copy = params[:copy_options] && params[:copy_options][:copy] | |
49 | @allowed_projects = Issue.allowed_target_projects_on_move |
|
68 | @allowed_projects = Issue.allowed_target_projects_on_move | |
50 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] |
|
69 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] | |
51 | @target_project ||= @project |
|
70 | @target_project ||= @project | |
52 | @trackers = @target_project.trackers |
|
71 | @trackers = @target_project.trackers | |
53 | @available_statuses = Workflow.available_statuses(@project) |
|
72 | @available_statuses = Workflow.available_statuses(@project) | |
54 | @notes = params[:notes] |
|
73 | @notes = params[:notes] | |
55 | @notes ||= '' |
|
74 | @notes ||= '' | |
56 | end |
|
75 | end | |
57 |
|
76 | |||
58 | def extract_changed_attributes_for_move(params) |
|
77 | def extract_changed_attributes_for_move(params) | |
59 | changed_attributes = {} |
|
78 | changed_attributes = {} | |
60 | [:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute| |
|
79 | [:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute| | |
61 | unless params[valid_attribute].blank? |
|
80 | unless params[valid_attribute].blank? | |
62 | changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute]) |
|
81 | changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute]) | |
63 | end |
|
82 | end | |
64 | end |
|
83 | end | |
65 | changed_attributes |
|
84 | changed_attributes | |
66 | end |
|
85 | end | |
67 |
|
86 | |||
68 | end |
|
87 | end |
General Comments 0
You need to be logged in to leave comments.
Login now