@@ -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 | 18 | class IssueMovesController < ApplicationController |
|
19 | menu_item :issues | |
|
20 | ||
|
2 | 21 | default_search_scope :issues |
|
3 | 22 | before_filter :find_issues, :check_project_uniqueness |
|
4 | 23 | before_filter :authorize |
|
5 | 24 | |
|
6 | 25 | def new |
|
7 | 26 | prepare_for_issue_move |
|
8 | 27 | render :layout => false if request.xhr? |
|
9 | 28 | end |
|
10 | 29 | |
|
11 | 30 | def create |
|
12 | 31 | prepare_for_issue_move |
|
13 | 32 | |
|
14 | 33 | if request.post? |
|
15 | 34 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) |
|
16 | 35 | unsaved_issue_ids = [] |
|
17 | 36 | moved_issues = [] |
|
18 | 37 | @issues.each do |issue| |
|
19 | 38 | issue.reload |
|
20 | 39 | issue.init_journal(User.current) |
|
21 | 40 | issue.current_journal.notes = @notes if @notes.present? |
|
22 | 41 | call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy }) |
|
23 | 42 | if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)}) |
|
24 | 43 | moved_issues << r |
|
25 | 44 | else |
|
26 | 45 | unsaved_issue_ids << issue.id |
|
27 | 46 | end |
|
28 | 47 | end |
|
29 | 48 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) |
|
30 | 49 | |
|
31 | 50 | if params[:follow] |
|
32 | 51 | if @issues.size == 1 && moved_issues.size == 1 |
|
33 | 52 | redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first |
|
34 | 53 | else |
|
35 | 54 | redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project) |
|
36 | 55 | end |
|
37 | 56 | else |
|
38 | 57 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
39 | 58 | end |
|
40 | 59 | return |
|
41 | 60 | end |
|
42 | 61 | end |
|
43 | 62 | |
|
44 | 63 | private |
|
45 | 64 | |
|
46 | 65 | def prepare_for_issue_move |
|
47 | 66 | @issues.sort! |
|
48 | 67 | @copy = params[:copy_options] && params[:copy_options][:copy] |
|
49 | 68 | @allowed_projects = Issue.allowed_target_projects_on_move |
|
50 | 69 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] |
|
51 | 70 | @target_project ||= @project |
|
52 | 71 | @trackers = @target_project.trackers |
|
53 | 72 | @available_statuses = Workflow.available_statuses(@project) |
|
54 | 73 | @notes = params[:notes] |
|
55 | 74 | @notes ||= '' |
|
56 | 75 | end |
|
57 | 76 | |
|
58 | 77 | def extract_changed_attributes_for_move(params) |
|
59 | 78 | changed_attributes = {} |
|
60 | 79 | [:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute| |
|
61 | 80 | unless params[valid_attribute].blank? |
|
62 | 81 | changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute]) |
|
63 | 82 | end |
|
64 | 83 | end |
|
65 | 84 | changed_attributes |
|
66 | 85 | end |
|
67 | 86 | |
|
68 | 87 | end |
General Comments 0
You need to be logged in to leave comments.
Login now