Mercurial > hg > soundsoftware-site
comparison .svn/pristine/20/201b3871255841575db5d12d8a5ed0f4a9dfd618.svn-base @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2014 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 class CustomFieldsController < ApplicationController | |
19 layout 'admin' | |
20 | |
21 before_filter :require_admin | |
22 before_filter :build_new_custom_field, :only => [:new, :create] | |
23 before_filter :find_custom_field, :only => [:edit, :update, :destroy] | |
24 accept_api_auth :index | |
25 | |
26 def index | |
27 respond_to do |format| | |
28 format.html { | |
29 @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name } | |
30 } | |
31 format.api { | |
32 @custom_fields = CustomField.all | |
33 } | |
34 end | |
35 end | |
36 | |
37 def new | |
38 @custom_field.field_format = 'string' if @custom_field.field_format.blank? | |
39 @custom_field.default_value = nil | |
40 end | |
41 | |
42 def create | |
43 if @custom_field.save | |
44 flash[:notice] = l(:notice_successful_create) | |
45 call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field) | |
46 redirect_to custom_fields_path(:tab => @custom_field.class.name) | |
47 else | |
48 render :action => 'new' | |
49 end | |
50 end | |
51 | |
52 def edit | |
53 end | |
54 | |
55 def update | |
56 if @custom_field.update_attributes(params[:custom_field]) | |
57 flash[:notice] = l(:notice_successful_update) | |
58 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field) | |
59 redirect_to custom_fields_path(:tab => @custom_field.class.name) | |
60 else | |
61 render :action => 'edit' | |
62 end | |
63 end | |
64 | |
65 def destroy | |
66 begin | |
67 @custom_field.destroy | |
68 rescue | |
69 flash[:error] = l(:error_can_not_delete_custom_field) | |
70 end | |
71 redirect_to custom_fields_path(:tab => @custom_field.class.name) | |
72 end | |
73 | |
74 private | |
75 | |
76 def build_new_custom_field | |
77 @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field]) | |
78 if @custom_field.nil? | |
79 render :action => 'select_type' | |
80 end | |
81 end | |
82 | |
83 def find_custom_field | |
84 @custom_field = CustomField.find(params[:id]) | |
85 rescue ActiveRecord::RecordNotFound | |
86 render_404 | |
87 end | |
88 end |