1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
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.
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.
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.
18 class CustomFieldsController < ApplicationController
21 before_filter :require_admin
24 @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
25 @tab = params[:tab] || 'IssueCustomField'
30 if params[:type].to_s.match(/.+CustomField$/)
31 params[:type].to_s.constantize.new(params[:custom_field])
35 (redirect_to(:action => 'index'); return) unless @custom_field.is_a?(CustomField)
37 if request.post? and @custom_field.save
38 flash[:notice] = l(:notice_successful_create)
39 call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
40 redirect_to :action => 'index', :tab => @custom_field.class.name
42 @trackers = Tracker.find(:all, :order => 'position')
46 @custom_field = CustomField.find(params[:id])
47 if request.post? and @custom_field.update_attributes(params[:custom_field])
48 flash[:notice] = l(:notice_successful_update)
49 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
50 redirect_to :action => 'index', :tab => @custom_field.class.name
52 @trackers = Tracker.find(:all, :order => 'position')
56 @custom_field = CustomField.find(params[:id]).destroy
57 redirect_to :action => 'index', :tab => @custom_field.class.name
59 flash[:error] = "Unable to delete custom field"
60 redirect_to :action => 'index'