1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
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.
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.
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.
18 class WorkflowsController < ApplicationController
19 before_filter :require_admin
22 @workflow_counts = Workflow.count_by_tracker_and_role
26 @role = Role.find_by_id(params[:role_id])
27 @tracker = Tracker.find_by_id(params[:tracker_id])
30 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
31 (params[:issue_status] || []).each { |old, news|
33 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
37 flash[:notice] = l(:notice_successful_update)
38 redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker
41 @roles = Role.find(:all, :order => 'builtin, position')
42 @trackers = Tracker.find(:all, :order => 'position')
43 @statuses = IssueStatus.find(:all, :order => 'position')
47 @trackers = Tracker.find(:all, :order => 'position')
48 @roles = Role.find(:all, :order => 'builtin, position')
50 @source_tracker = params[:source_tracker_id].blank? ? nil : Tracker.find_by_id(params[:source_tracker_id])
51 @source_role = params[:source_role_id].blank? ? nil : Role.find_by_id(params[:source_role_id])
53 @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids])
54 @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids])
57 if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
58 flash.now[:error] = l(:error_workflow_copy_source)
59 elsif @target_trackers.nil? || @target_roles.nil?
60 flash.now[:error] = l(:error_workflow_copy_target)
62 Workflow.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
63 flash[:notice] = l(:notice_successful_update)
64 redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role