@@ -1,78 +1,79 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 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. | |
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 |
|
24 | |||
25 | def index |
|
25 | def index | |
26 | @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name } |
|
26 | @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name } | |
27 | @tab = params[:tab] || 'IssueCustomField' |
|
27 | @tab = params[:tab] || 'IssueCustomField' | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def new |
|
30 | def new | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def create |
|
33 | def create | |
34 |
if |
|
34 | if @custom_field.save | |
35 | flash[:notice] = l(:notice_successful_create) |
|
35 | flash[:notice] = l(:notice_successful_create) | |
36 | call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field) |
|
36 | call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field) | |
37 | redirect_to custom_fields_path(:tab => @custom_field.class.name) |
|
37 | redirect_to custom_fields_path(:tab => @custom_field.class.name) | |
38 | else |
|
38 | else | |
39 | render :action => 'new' |
|
39 | render :action => 'new' | |
40 | end |
|
40 | end | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def edit |
|
43 | def edit | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def update |
|
46 | def update | |
47 |
if |
|
47 | if @custom_field.update_attributes(params[:custom_field]) | |
48 | flash[:notice] = l(:notice_successful_update) |
|
48 | flash[:notice] = l(:notice_successful_update) | |
49 | call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field) |
|
49 | call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field) | |
50 | redirect_to custom_fields_path(:tab => @custom_field.class.name) |
|
50 | redirect_to custom_fields_path(:tab => @custom_field.class.name) | |
51 | else |
|
51 | else | |
52 | render :action => 'edit' |
|
52 | render :action => 'edit' | |
53 | end |
|
53 | end | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def destroy |
|
56 | def destroy | |
57 | @custom_field.destroy |
|
57 | begin | |
58 | redirect_to custom_fields_path(:tab => @custom_field.class.name) |
|
58 | @custom_field.destroy | |
59 | rescue |
|
59 | rescue | |
60 | flash[:error] = l(:error_can_not_delete_custom_field) |
|
60 | flash[:error] = l(:error_can_not_delete_custom_field) | |
|
61 | end | |||
61 | redirect_to custom_fields_path(:tab => @custom_field.class.name) |
|
62 | redirect_to custom_fields_path(:tab => @custom_field.class.name) | |
62 | end |
|
63 | end | |
63 |
|
64 | |||
64 | private |
|
65 | private | |
65 |
|
66 | |||
66 | def build_new_custom_field |
|
67 | def build_new_custom_field | |
67 | @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field]) |
|
68 | @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field]) | |
68 | if @custom_field.nil? |
|
69 | if @custom_field.nil? | |
69 | render_404 |
|
70 | render_404 | |
70 | end |
|
71 | end | |
71 | end |
|
72 | end | |
72 |
|
73 | |||
73 | def find_custom_field |
|
74 | def find_custom_field | |
74 | @custom_field = CustomField.find(params[:id]) |
|
75 | @custom_field = CustomField.find(params[:id]) | |
75 | rescue ActiveRecord::RecordNotFound |
|
76 | rescue ActiveRecord::RecordNotFound | |
76 | render_404 |
|
77 | render_404 | |
77 | end |
|
78 | end | |
78 | end |
|
79 | end |
General Comments 0
You need to be logged in to leave comments.
Login now