Mercurial > hg > soundsoftware-site
comparison app/controllers/issue_categories_controller.rb @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | cbce1fd3b1b7 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 # redMine - project management software | |
2 # Copyright (C) 2006 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 IssueCategoriesController < ApplicationController | |
19 menu_item :settings | |
20 model_object IssueCategory | |
21 before_filter :find_model_object, :except => :new | |
22 before_filter :find_project_from_association, :except => :new | |
23 before_filter :find_project, :only => :new | |
24 before_filter :authorize | |
25 | |
26 verify :method => :post, :only => :destroy | |
27 | |
28 def new | |
29 @category = @project.issue_categories.build(params[:category]) | |
30 if request.post? | |
31 if @category.save | |
32 respond_to do |format| | |
33 format.html do | |
34 flash[:notice] = l(:notice_successful_create) | |
35 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project | |
36 end | |
37 format.js do | |
38 # IE doesn't support the replace_html rjs method for select box options | |
39 render(:update) {|page| page.replace "issue_category_id", | |
40 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]') | |
41 } | |
42 end | |
43 end | |
44 else | |
45 respond_to do |format| | |
46 format.html | |
47 format.js do | |
48 render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) } | |
49 end | |
50 end | |
51 end | |
52 end | |
53 end | |
54 | |
55 def edit | |
56 if request.post? and @category.update_attributes(params[:category]) | |
57 flash[:notice] = l(:notice_successful_update) | |
58 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project | |
59 end | |
60 end | |
61 | |
62 def destroy | |
63 @issue_count = @category.issues.size | |
64 if @issue_count == 0 | |
65 # No issue assigned to this category | |
66 @category.destroy | |
67 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' | |
68 elsif params[:todo] | |
69 reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) if params[:todo] == 'reassign' | |
70 @category.destroy(reassign_to) | |
71 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' | |
72 end | |
73 @categories = @project.issue_categories - [@category] | |
74 end | |
75 | |
76 private | |
77 # Wrap ApplicationController's find_model_object method to set | |
78 # @category instead of just @issue_category | |
79 def find_model_object | |
80 super | |
81 @category = @object | |
82 end | |
83 | |
84 def find_project | |
85 @project = Project.find(params[:project_id]) | |
86 rescue ActiveRecord::RecordNotFound | |
87 render_404 | |
88 end | |
89 end |