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