Mercurial > hg > soundsoftware-site
comparison app/controllers/issue_categories_controller.rb @ 1338:25603efa57b5
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 20 Jun 2013 13:14:14 +0100 |
parents | 433d4f72a19b |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
1209:1b1138f6f55e | 1338:25603efa57b5 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
18 class IssueCategoriesController < ApplicationController | 18 class IssueCategoriesController < ApplicationController |
19 menu_item :settings | 19 menu_item :settings |
20 model_object IssueCategory | 20 model_object IssueCategory |
21 before_filter :find_model_object, :except => [:index, :new, :create] | 21 before_filter :find_model_object, :except => [:index, :new, :create] |
22 before_filter :find_project_from_association, :except => [:index, :new, :create] | 22 before_filter :find_project_from_association, :except => [:index, :new, :create] |
23 before_filter :find_project, :only => [:index, :new, :create] | 23 before_filter :find_project_by_project_id, :only => [:index, :new, :create] |
24 before_filter :authorize | 24 before_filter :authorize |
25 accept_api_auth :index, :show, :create, :update, :destroy | 25 accept_api_auth :index, :show, :create, :update, :destroy |
26 | 26 |
27 def index | 27 def index |
28 respond_to do |format| | 28 respond_to do |format| |
29 format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project } | 29 format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project } |
30 format.api { @categories = @project.issue_categories.all } | 30 format.api { @categories = @project.issue_categories.all } |
31 end | 31 end |
39 end | 39 end |
40 | 40 |
41 def new | 41 def new |
42 @category = @project.issue_categories.build | 42 @category = @project.issue_categories.build |
43 @category.safe_attributes = params[:issue_category] | 43 @category.safe_attributes = params[:issue_category] |
44 | |
45 respond_to do |format| | |
46 format.html | |
47 format.js | |
48 end | |
44 end | 49 end |
45 | 50 |
46 verify :method => :post, :only => :create | |
47 def create | 51 def create |
48 @category = @project.issue_categories.build | 52 @category = @project.issue_categories.build |
49 @category.safe_attributes = params[:issue_category] | 53 @category.safe_attributes = params[:issue_category] |
50 if @category.save | 54 if @category.save |
51 respond_to do |format| | 55 respond_to do |format| |
52 format.html do | 56 format.html do |
53 flash[:notice] = l(:notice_successful_create) | 57 flash[:notice] = l(:notice_successful_create) |
54 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project | 58 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project |
55 end | 59 end |
56 format.js do | 60 format.js |
57 # IE doesn't support the replace_html rjs method for select box options | |
58 render(:update) {|page| page.replace "issue_category_id", | |
59 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]') | |
60 } | |
61 end | |
62 format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) } | 61 format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) } |
63 end | 62 end |
64 else | 63 else |
65 respond_to do |format| | 64 respond_to do |format| |
66 format.html { render :action => 'new'} | 65 format.html { render :action => 'new'} |
67 format.js do | 66 format.js { render :action => 'new'} |
68 render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) } | |
69 end | |
70 format.api { render_validation_errors(@category) } | 67 format.api { render_validation_errors(@category) } |
71 end | 68 end |
72 end | 69 end |
73 end | 70 end |
74 | 71 |
75 def edit | 72 def edit |
76 end | 73 end |
77 | 74 |
78 verify :method => :put, :only => :update | |
79 def update | 75 def update |
80 @category.safe_attributes = params[:issue_category] | 76 @category.safe_attributes = params[:issue_category] |
81 if @category.save | 77 if @category.save |
82 respond_to do |format| | 78 respond_to do |format| |
83 format.html { | 79 format.html { |
84 flash[:notice] = l(:notice_successful_update) | 80 flash[:notice] = l(:notice_successful_update) |
85 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project | 81 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project |
86 } | 82 } |
87 format.api { head :ok } | 83 format.api { render_api_ok } |
88 end | 84 end |
89 else | 85 else |
90 respond_to do |format| | 86 respond_to do |format| |
91 format.html { render :action => 'edit' } | 87 format.html { render :action => 'edit' } |
92 format.api { render_validation_errors(@category) } | 88 format.api { render_validation_errors(@category) } |
93 end | 89 end |
94 end | 90 end |
95 end | 91 end |
96 | 92 |
97 verify :method => :delete, :only => :destroy | |
98 def destroy | 93 def destroy |
99 @issue_count = @category.issues.size | 94 @issue_count = @category.issues.size |
100 if @issue_count == 0 || params[:todo] || api_request? | 95 if @issue_count == 0 || params[:todo] || api_request? |
101 reassign_to = nil | 96 reassign_to = nil |
102 if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?) | 97 if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?) |
103 reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) | 98 reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) |
104 end | 99 end |
105 @category.destroy(reassign_to) | 100 @category.destroy(reassign_to) |
106 respond_to do |format| | 101 respond_to do |format| |
107 format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' } | 102 format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' } |
108 format.api { head :ok } | 103 format.api { render_api_ok } |
109 end | 104 end |
110 return | 105 return |
111 end | 106 end |
112 @categories = @project.issue_categories - [@category] | 107 @categories = @project.issue_categories - [@category] |
113 end | 108 end |
117 # @category instead of just @issue_category | 112 # @category instead of just @issue_category |
118 def find_model_object | 113 def find_model_object |
119 super | 114 super |
120 @category = @object | 115 @category = @object |
121 end | 116 end |
122 | |
123 def find_project | |
124 @project = Project.find(params[:project_id]) | |
125 rescue ActiveRecord::RecordNotFound | |
126 render_404 | |
127 end | |
128 end | 117 end |