To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / issue_categories_controller.rb @ 780:31b3aa308568
History | View | Annotate | Download (3.29 KB)
| 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 |
return
|
| 69 |
elsif params[:todo] |
| 70 |
reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) if params[:todo] == 'reassign' |
| 71 |
@category.destroy(reassign_to)
|
| 72 |
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' |
| 73 |
return
|
| 74 |
end
|
| 75 |
@categories = @project.issue_categories - [@category] |
| 76 |
end
|
| 77 |
|
| 78 |
private |
| 79 |
# Wrap ApplicationController's find_model_object method to set
|
| 80 |
# @category instead of just @issue_category
|
| 81 |
def find_model_object |
| 82 |
super
|
| 83 |
@category = @object |
| 84 |
end
|
| 85 |
|
| 86 |
def find_project |
| 87 |
@project = Project.find(params[:project_id]) |
| 88 |
rescue ActiveRecord::RecordNotFound |
| 89 |
render_404 |
| 90 |
end
|
| 91 |
end
|