issue_categories_controller.rb
117 lines
| 3.9 KiB
| text/x-ruby
|
RubyLexer
|
r6783 | # Redmine - project management software | ||
|
r9453 | # Copyright (C) 2006-2012 Jean-Philippe Lang | ||
|
r330 | # | ||
# 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. | ||||
|
r6783 | # | ||
|
r330 | # This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
|
r6783 | # | ||
|
r330 | # You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
|
r2 | class IssueCategoriesController < ApplicationController | ||
|
r1062 | menu_item :settings | ||
|
r3483 | model_object IssueCategory | ||
|
r7762 | before_filter :find_model_object, :except => [:index, :new, :create] | ||
before_filter :find_project_from_association, :except => [:index, :new, :create] | ||||
|
r9040 | before_filter :find_project_by_project_id, :only => [:index, :new, :create] | ||
|
r3435 | before_filter :authorize | ||
|
r7762 | accept_api_auth :index, :show, :create, :update, :destroy | ||
|
r10411 | |||
|
r7762 | def index | ||
respond_to do |format| | ||||
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project } | ||||
format.api { @categories = @project.issue_categories.all } | ||||
end | ||||
end | ||||
def show | ||||
respond_to do |format| | ||||
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project } | ||||
format.api | ||||
end | ||||
end | ||||
|
r6783 | |||
|
r3435 | def new | ||
|
r9011 | @category = @project.issue_categories.build | ||
@category.safe_attributes = params[:issue_category] | ||||
|
r9524 | |||
respond_to do |format| | ||||
format.html | ||||
|
r9860 | format.js | ||
|
r9524 | end | ||
|
r7761 | end | ||
def create | ||||
|
r9011 | @category = @project.issue_categories.build | ||
@category.safe_attributes = params[:issue_category] | ||||
|
r7761 | if @category.save | ||
respond_to do |format| | ||||
format.html do | ||||
flash[:notice] = l(:notice_successful_create) | ||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project | ||||
|
r3435 | end | ||
|
r9860 | format.js | ||
|
r7762 | format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) } | ||
|
r7761 | end | ||
else | ||||
respond_to do |format| | ||||
format.html { render :action => 'new'} | ||||
|
r9860 | format.js { render :action => 'new'} | ||
|
r7762 | format.api { render_validation_errors(@category) } | ||
|
r3435 | end | ||
end | ||||
end | ||||
|
r6783 | |||
|
r2 | def edit | ||
|
r7761 | end | ||
def update | ||||
|
r9011 | @category.safe_attributes = params[:issue_category] | ||
if @category.save | ||||
|
r7762 | respond_to do |format| | ||
format.html { | ||||
flash[:notice] = l(:notice_successful_update) | ||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project | ||||
} | ||||
|
r9792 | format.api { render_api_ok } | ||
|
r7762 | end | ||
|
r7761 | else | ||
|
r7762 | respond_to do |format| | ||
format.html { render :action => 'edit' } | ||||
format.api { render_validation_errors(@category) } | ||||
end | ||||
|
r2 | end | ||
end | ||||
def destroy | ||||
|
r722 | @issue_count = @category.issues.size | ||
|
r10411 | if @issue_count == 0 || params[:todo] || api_request? | ||
|
r7762 | reassign_to = nil | ||
if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?) | ||||
reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) | ||||
end | ||||
|
r722 | @category.destroy(reassign_to) | ||
|
r7762 | respond_to do |format| | ||
format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' } | ||||
|
r9792 | format.api { render_api_ok } | ||
|
r7762 | end | ||
|
r5491 | return | ||
|
r722 | end | ||
@categories = @project.issue_categories - [@category] | ||||
|
r330 | end | ||
|
r2 | |||
|
r330 | private | ||
|
r3483 | # Wrap ApplicationController's find_model_object method to set | ||
# @category instead of just @issue_category | ||||
def find_model_object | ||||
super | ||||
@category = @object | ||||
|
r6783 | end | ||
|
r2 | end | ||