annotate app/controllers/custom_fields_controller.rb @ 1169:492ff72268e3 bug_521

Close obsolete branch bug_521
author Chris Cannam
date Thu, 18 Oct 2012 10:42:48 +0100
parents cbb26bc654de
children 433d4f72a19b
rev   line source
Chris@0 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class CustomFieldsController < ApplicationController
Chris@0 19 layout 'admin'
Chris@909 20
Chris@0 21 before_filter :require_admin
Chris@0 22
Chris@0 23 def index
Chris@0 24 @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
Chris@0 25 @tab = params[:tab] || 'IssueCustomField'
Chris@0 26 end
Chris@909 27
Chris@0 28 def new
Chris@0 29 @custom_field = begin
Chris@0 30 if params[:type].to_s.match(/.+CustomField$/)
Chris@0 31 params[:type].to_s.constantize.new(params[:custom_field])
Chris@0 32 end
Chris@0 33 rescue
Chris@0 34 end
Chris@0 35 (redirect_to(:action => 'index'); return) unless @custom_field.is_a?(CustomField)
Chris@909 36
Chris@0 37 if request.post? and @custom_field.save
Chris@0 38 flash[:notice] = l(:notice_successful_create)
Chris@0 39 call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
Chris@0 40 redirect_to :action => 'index', :tab => @custom_field.class.name
Chris@441 41 else
Chris@441 42 @trackers = Tracker.find(:all, :order => 'position')
Chris@0 43 end
Chris@0 44 end
Chris@0 45
Chris@0 46 def edit
Chris@0 47 @custom_field = CustomField.find(params[:id])
Chris@0 48 if request.post? and @custom_field.update_attributes(params[:custom_field])
Chris@0 49 flash[:notice] = l(:notice_successful_update)
Chris@0 50 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
Chris@0 51 redirect_to :action => 'index', :tab => @custom_field.class.name
Chris@441 52 else
Chris@441 53 @trackers = Tracker.find(:all, :order => 'position')
Chris@0 54 end
Chris@0 55 end
Chris@909 56
Chris@0 57 def destroy
Chris@0 58 @custom_field = CustomField.find(params[:id]).destroy
Chris@0 59 redirect_to :action => 'index', :tab => @custom_field.class.name
Chris@0 60 rescue
Chris@0 61 flash[:error] = l(:error_can_not_delete_custom_field)
Chris@0 62 redirect_to :action => 'index'
Chris@0 63 end
Chris@0 64 end