Mercurial > hg > soundsoftware-site
comparison app/controllers/custom_fields_controller.rb @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | 433d4f72a19b |
children | e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1296:038ba2d95de8 | 1464:261b3d9a4903 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 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. |
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 | 25 |
25 def index | 26 def index |
26 @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name } | 27 respond_to do |format| |
27 @tab = params[:tab] || 'IssueCustomField' | 28 format.html { |
29 @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name } | |
30 @tab = params[:tab] || 'IssueCustomField' | |
31 } | |
32 format.api { | |
33 @custom_fields = CustomField.all | |
34 } | |
35 end | |
28 end | 36 end |
29 | 37 |
30 def new | 38 def new |
31 end | 39 end |
32 | 40 |
33 def create | 41 def create |
34 if request.post? and @custom_field.save | 42 if @custom_field.save |
35 flash[:notice] = l(:notice_successful_create) | 43 flash[:notice] = l(:notice_successful_create) |
36 call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field) | 44 call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field) |
37 redirect_to :action => 'index', :tab => @custom_field.class.name | 45 redirect_to custom_fields_path(:tab => @custom_field.class.name) |
38 else | 46 else |
39 render :action => 'new' | 47 render :action => 'new' |
40 end | 48 end |
41 end | 49 end |
42 | 50 |
43 def edit | 51 def edit |
44 end | 52 end |
45 | 53 |
46 def update | 54 def update |
47 if request.put? and @custom_field.update_attributes(params[:custom_field]) | 55 if @custom_field.update_attributes(params[:custom_field]) |
48 flash[:notice] = l(:notice_successful_update) | 56 flash[:notice] = l(:notice_successful_update) |
49 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field) | 57 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field) |
50 redirect_to :action => 'index', :tab => @custom_field.class.name | 58 redirect_to custom_fields_path(:tab => @custom_field.class.name) |
51 else | 59 else |
52 render :action => 'edit' | 60 render :action => 'edit' |
53 end | 61 end |
54 end | 62 end |
55 | 63 |
56 def destroy | 64 def destroy |
57 @custom_field.destroy | 65 begin |
58 redirect_to :action => 'index', :tab => @custom_field.class.name | 66 @custom_field.destroy |
59 rescue | 67 rescue |
60 flash[:error] = l(:error_can_not_delete_custom_field) | 68 flash[:error] = l(:error_can_not_delete_custom_field) |
61 redirect_to :action => 'index' | 69 end |
70 redirect_to custom_fields_path(:tab => @custom_field.class.name) | |
62 end | 71 end |
63 | 72 |
64 private | 73 private |
65 | 74 |
66 def build_new_custom_field | 75 def build_new_custom_field |
67 @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field]) | 76 @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field]) |
68 if @custom_field.nil? | 77 if @custom_field.nil? |
69 render_404 | 78 render_404 |
79 else | |
80 @custom_field.default_value = nil | |
70 end | 81 end |
71 end | 82 end |
72 | 83 |
73 def find_custom_field | 84 def find_custom_field |
74 @custom_field = CustomField.find(params[:id]) | 85 @custom_field = CustomField.find(params[:id]) |