To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / issue_moves_controller.rb @ 1081:b56a4c5afa35

History | View | Annotate | Download (3.17 KB)

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

    
18
class IssueMovesController < ApplicationController
19
  menu_item :issues
20

    
21
  default_search_scope :issues
22
  before_filter :find_issues, :check_project_uniqueness
23
  before_filter :authorize
24

    
25
  def new
26
    prepare_for_issue_move
27
    render :layout => false if request.xhr?
28
  end
29

    
30
  def create
31
    prepare_for_issue_move
32

    
33
    if request.post?
34
      new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
35
      unsaved_issue_ids = []
36
      moved_issues = []
37
      @issues.each do |issue|
38
        issue.reload
39
        issue.init_journal(User.current)
40
        issue.current_journal.notes = @notes if @notes.present?
41
        call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
42
        if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
43
          moved_issues << r
44
        else
45
          unsaved_issue_ids << issue.id
46
        end
47
      end
48
      set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
49

    
50
      if params[:follow]
51
        if @issues.size == 1 && moved_issues.size == 1
52
          redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
53
        else
54
          redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
55
        end
56
      else
57
        redirect_to :controller => 'issues', :action => 'index', :project_id => @project
58
      end
59
      return
60
    end
61
  end
62

    
63
  private
64

    
65
  def prepare_for_issue_move
66
    @issues.sort!
67
    @copy = params[:copy_options] && params[:copy_options][:copy]
68
    @allowed_projects = Issue.allowed_target_projects_on_move
69
    @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
70
    @target_project ||= @project
71
    @trackers = @target_project.trackers
72
    @available_statuses = Workflow.available_statuses(@project)
73
    @notes = params[:notes]
74
    @notes ||= ''
75
  end
76

    
77
  def extract_changed_attributes_for_move(params)
78
    changed_attributes = {}
79
    [:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute|
80
      unless params[valid_attribute].blank?
81
        changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
82
      end
83
    end
84
    changed_attributes
85
  end
86

    
87
end