##// END OF EJS Templates
Code cleanup....
Jean-Philippe Lang -
r12576:8b58c9521288
parent child
Show More
@@ -1,89 +1,88
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class CustomFieldsController < ApplicationController
19 19 layout 'admin'
20 20
21 21 before_filter :require_admin
22 22 before_filter :build_new_custom_field, :only => [:new, :create]
23 23 before_filter :find_custom_field, :only => [:edit, :update, :destroy]
24 24 accept_api_auth :index
25 25
26 26 def index
27 27 respond_to do |format|
28 28 format.html {
29 29 @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name }
30 @tab = params[:tab] || 'IssueCustomField'
31 30 }
32 31 format.api {
33 32 @custom_fields = CustomField.all
34 33 }
35 34 end
36 35 end
37 36
38 37 def new
39 38 @custom_field.field_format = 'string' if @custom_field.field_format.blank?
40 39 @custom_field.default_value = nil
41 40 end
42 41
43 42 def create
44 43 if @custom_field.save
45 44 flash[:notice] = l(:notice_successful_create)
46 45 call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
47 46 redirect_to custom_fields_path(:tab => @custom_field.class.name)
48 47 else
49 48 render :action => 'new'
50 49 end
51 50 end
52 51
53 52 def edit
54 53 end
55 54
56 55 def update
57 56 if @custom_field.update_attributes(params[:custom_field])
58 57 flash[:notice] = l(:notice_successful_update)
59 58 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
60 59 redirect_to custom_fields_path(:tab => @custom_field.class.name)
61 60 else
62 61 render :action => 'edit'
63 62 end
64 63 end
65 64
66 65 def destroy
67 66 begin
68 67 @custom_field.destroy
69 68 rescue
70 69 flash[:error] = l(:error_can_not_delete_custom_field)
71 70 end
72 71 redirect_to custom_fields_path(:tab => @custom_field.class.name)
73 72 end
74 73
75 74 private
76 75
77 76 def build_new_custom_field
78 77 @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
79 78 if @custom_field.nil?
80 79 render :action => 'select_type'
81 80 end
82 81 end
83 82
84 83 def find_custom_field
85 84 @custom_field = CustomField.find(params[:id])
86 85 rescue ActiveRecord::RecordNotFound
87 86 render_404
88 87 end
89 88 end
General Comments 0
You need to be logged in to leave comments. Login now