2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# Copyright (C) 2010-2011 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
2010-08-11 18:42:10 +04:00
|
|
|
class IssueMovesController < ApplicationController
|
|
|
|
default_search_scope :issues
|
2010-09-29 09:22:53 +04:00
|
|
|
before_filter :find_issues, :check_project_uniqueness
|
2010-08-11 18:42:10 +04:00
|
|
|
before_filter :authorize
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-08-11 18:42:10 +04:00
|
|
|
def new
|
|
|
|
prepare_for_issue_move
|
|
|
|
render :layout => false if request.xhr?
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
prepare_for_issue_move
|
|
|
|
|
|
|
|
if request.post?
|
|
|
|
new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
|
|
|
|
unsaved_issue_ids = []
|
|
|
|
moved_issues = []
|
|
|
|
@issues.each do |issue|
|
|
|
|
issue.reload
|
2010-11-05 19:04:09 +03:00
|
|
|
issue.init_journal(User.current, @notes || "")
|
2010-08-11 18:42:10 +04:00
|
|
|
call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
|
|
|
|
if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
|
|
|
|
moved_issues << r
|
|
|
|
else
|
|
|
|
unsaved_issue_ids << issue.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
|
|
|
|
|
|
|
|
if params[:follow]
|
|
|
|
if @issues.size == 1 && moved_issues.size == 1
|
|
|
|
redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
|
|
|
|
else
|
|
|
|
redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def prepare_for_issue_move
|
|
|
|
@issues.sort!
|
|
|
|
@copy = params[:copy_options] && params[:copy_options][:copy]
|
|
|
|
@allowed_projects = Issue.allowed_target_projects_on_move
|
|
|
|
@target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
|
2011-05-30 22:52:25 +04:00
|
|
|
@target_project ||= @project
|
2010-08-11 18:42:10 +04:00
|
|
|
@trackers = @target_project.trackers
|
|
|
|
@available_statuses = Workflow.available_statuses(@project)
|
2010-10-25 22:44:46 +04:00
|
|
|
@notes = params[:notes]
|
|
|
|
@notes ||= ''
|
2010-08-11 18:42:10 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def extract_changed_attributes_for_move(params)
|
|
|
|
changed_attributes = {}
|
2010-10-25 22:44:41 +04:00
|
|
|
[:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute|
|
2010-08-11 18:42:10 +04:00
|
|
|
unless params[valid_attribute].blank?
|
|
|
|
changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
changed_attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|