annotate app/controllers/.svn/text-base/issue_categories_controller.rb.svn-base @ 8:0c83d98252d9 yuya

* Add custom repo prefix and proper auth realm, remove auth cache (seems like an unwise feature), pass DB handle around, various other bits of tidying
author Chris Cannam
date Thu, 12 Aug 2010 15:31:37 +0100
parents 513646585e45
children cbce1fd3b1b7
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class IssueCategoriesController < ApplicationController
Chris@0 19 menu_item :settings
Chris@0 20 model_object IssueCategory
Chris@0 21 before_filter :find_model_object, :except => :new
Chris@0 22 before_filter :find_project_from_association, :except => :new
Chris@0 23 before_filter :find_project, :only => :new
Chris@0 24 before_filter :authorize
Chris@0 25
Chris@0 26 verify :method => :post, :only => :destroy
Chris@0 27
Chris@0 28 def new
Chris@0 29 @category = @project.issue_categories.build(params[:category])
Chris@0 30 if request.post?
Chris@0 31 if @category.save
Chris@0 32 respond_to do |format|
Chris@0 33 format.html do
Chris@0 34 flash[:notice] = l(:notice_successful_create)
Chris@0 35 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
Chris@0 36 end
Chris@0 37 format.js do
Chris@0 38 # IE doesn't support the replace_html rjs method for select box options
Chris@0 39 render(:update) {|page| page.replace "issue_category_id",
Chris@0 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]')
Chris@0 41 }
Chris@0 42 end
Chris@0 43 end
Chris@0 44 else
Chris@0 45 respond_to do |format|
Chris@0 46 format.html
Chris@0 47 format.js do
Chris@0 48 render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) }
Chris@0 49 end
Chris@0 50 end
Chris@0 51 end
Chris@0 52 end
Chris@0 53 end
Chris@0 54
Chris@0 55 def edit
Chris@0 56 if request.post? and @category.update_attributes(params[:category])
Chris@0 57 flash[:notice] = l(:notice_successful_update)
Chris@0 58 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
Chris@0 59 end
Chris@0 60 end
Chris@0 61
Chris@0 62 def destroy
Chris@0 63 @issue_count = @category.issues.size
Chris@0 64 if @issue_count == 0
Chris@0 65 # No issue assigned to this category
Chris@0 66 @category.destroy
Chris@0 67 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
Chris@0 68 elsif params[:todo]
Chris@0 69 reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) if params[:todo] == 'reassign'
Chris@0 70 @category.destroy(reassign_to)
Chris@0 71 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
Chris@0 72 end
Chris@0 73 @categories = @project.issue_categories - [@category]
Chris@0 74 end
Chris@0 75
Chris@0 76 private
Chris@0 77 # Wrap ApplicationController's find_model_object method to set
Chris@0 78 # @category instead of just @issue_category
Chris@0 79 def find_model_object
Chris@0 80 super
Chris@0 81 @category = @object
Chris@0 82 end
Chris@0 83
Chris@0 84 def find_project
Chris@0 85 @project = Project.find(params[:project_id])
Chris@0 86 rescue ActiveRecord::RecordNotFound
Chris@0 87 render_404
Chris@0 88 end
Chris@0 89 end