OSDN Git Service

f11aa473049686d81e8635c0aa2c29a955d2d5d9
[redminele/redmine.git] / app / controllers / workflows_controller.rb
1 # Redmine - project management software
2 # Copyright (C) 2006-2008  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 WorkflowsController < ApplicationController
19   before_filter :require_admin
20
21   def index
22     @workflow_counts = Workflow.count_by_tracker_and_role
23   end
24   
25   def edit
26     @role = Role.find_by_id(params[:role_id])
27     @tracker = Tracker.find_by_id(params[:tracker_id])    
28     
29     if request.post?
30       Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
31       (params[:issue_status] || []).each { |old, news| 
32         news.each { |new| 
33           @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new) 
34         }
35       }
36       if @role.save
37         flash[:notice] = l(:notice_successful_update)
38         redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker
39       end
40     end
41     @roles = Role.find(:all, :order => 'builtin, position')
42     @trackers = Tracker.find(:all, :order => 'position')
43     @statuses = IssueStatus.find(:all, :order => 'position')
44   end
45   
46   def copy
47     @trackers = Tracker.find(:all, :order => 'position')
48     @roles = Role.find(:all, :order => 'builtin, position')
49     
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])
52     
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])
55      
56     if request.post?
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)
61       else
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
65       end
66     end
67   end
68 end