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 @ 912:5e80956cc792
History | View | Annotate | Download (4.4 KB)
| 1 | 909:cbb26bc654de | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
||
| 3 | 0:513646585e45 | Chris | #
|
| 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 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | before_filter :find_model_object, :except => [:index, :new, :create] |
| 22 | before_filter :find_project_from_association, :except => [:index, :new, :create] |
||
| 23 | before_filter :find_project, :only => [:index, :new, :create] |
||
| 24 | 0:513646585e45 | Chris | before_filter :authorize
|
| 25 | 909:cbb26bc654de | Chris | accept_api_auth :index, :show, :create, :update, :destroy |
| 26 | 0:513646585e45 | Chris | |
| 27 | 909:cbb26bc654de | Chris | def index |
| 28 | respond_to do |format|
|
||
| 29 | format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
|
||
| 30 | format.api { @categories = @project.issue_categories.all }
|
||
| 31 | end
|
||
| 32 | end
|
||
| 33 | |||
| 34 | def show |
||
| 35 | respond_to do |format|
|
||
| 36 | format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
|
||
| 37 | format.api |
||
| 38 | end
|
||
| 39 | end
|
||
| 40 | 0:513646585e45 | Chris | |
| 41 | def new |
||
| 42 | 909:cbb26bc654de | Chris | @category = @project.issue_categories.build(params[:issue_category]) |
| 43 | end
|
||
| 44 | |||
| 45 | verify :method => :post, :only => :create |
||
| 46 | def create |
||
| 47 | @category = @project.issue_categories.build(params[:issue_category]) |
||
| 48 | if @category.save |
||
| 49 | respond_to do |format|
|
||
| 50 | format.html do
|
||
| 51 | flash[:notice] = l(:notice_successful_create) |
||
| 52 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project |
||
| 53 | 0:513646585e45 | Chris | end
|
| 54 | 909:cbb26bc654de | Chris | format.js do
|
| 55 | # IE doesn't support the replace_html rjs method for select box options
|
||
| 56 | render(:update) {|page| page.replace "issue_category_id", |
||
| 57 | 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]') |
||
| 58 | } |
||
| 59 | 0:513646585e45 | Chris | end
|
| 60 | 909:cbb26bc654de | Chris | format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) }
|
| 61 | end
|
||
| 62 | else
|
||
| 63 | respond_to do |format|
|
||
| 64 | format.html { render :action => 'new'}
|
||
| 65 | format.js do
|
||
| 66 | render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) } |
||
| 67 | end
|
||
| 68 | format.api { render_validation_errors(@category) }
|
||
| 69 | 0:513646585e45 | Chris | end
|
| 70 | end
|
||
| 71 | end
|
||
| 72 | 909:cbb26bc654de | Chris | |
| 73 | 0:513646585e45 | Chris | def edit |
| 74 | 909:cbb26bc654de | Chris | end
|
| 75 | |||
| 76 | verify :method => :put, :only => :update |
||
| 77 | def update |
||
| 78 | if @category.update_attributes(params[:issue_category]) |
||
| 79 | respond_to do |format|
|
||
| 80 | format.html {
|
||
| 81 | flash[:notice] = l(:notice_successful_update) |
||
| 82 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project |
||
| 83 | } |
||
| 84 | format.api { head :ok }
|
||
| 85 | end
|
||
| 86 | else
|
||
| 87 | respond_to do |format|
|
||
| 88 | format.html { render :action => 'edit' }
|
||
| 89 | format.api { render_validation_errors(@category) }
|
||
| 90 | end
|
||
| 91 | 0:513646585e45 | Chris | end
|
| 92 | end
|
||
| 93 | |||
| 94 | 909:cbb26bc654de | Chris | verify :method => :delete, :only => :destroy |
| 95 | 0:513646585e45 | Chris | def destroy |
| 96 | @issue_count = @category.issues.size |
||
| 97 | 909:cbb26bc654de | Chris | if @issue_count == 0 || params[:todo] || api_request? |
| 98 | reassign_to = nil
|
||
| 99 | if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?) |
||
| 100 | reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) |
||
| 101 | end
|
||
| 102 | 0:513646585e45 | Chris | @category.destroy(reassign_to)
|
| 103 | 909:cbb26bc654de | Chris | respond_to do |format|
|
| 104 | format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' }
|
||
| 105 | format.api { head :ok }
|
||
| 106 | end
|
||
| 107 | 441:cbce1fd3b1b7 | Chris | return
|
| 108 | 0:513646585e45 | Chris | end
|
| 109 | @categories = @project.issue_categories - [@category] |
||
| 110 | end
|
||
| 111 | |||
| 112 | private |
||
| 113 | # Wrap ApplicationController's find_model_object method to set
|
||
| 114 | # @category instead of just @issue_category
|
||
| 115 | def find_model_object |
||
| 116 | super
|
||
| 117 | @category = @object |
||
| 118 | 909:cbb26bc654de | Chris | end
|
| 119 | |||
| 120 | 0:513646585e45 | Chris | def find_project |
| 121 | @project = Project.find(params[:project_id]) |
||
| 122 | rescue ActiveRecord::RecordNotFound |
||
| 123 | render_404 |
||
| 124 | end
|
||
| 125 | end |