2009-01-17 11:46:23 +03:00
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
2007-03-12 20:59:02 +03:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
class CustomFieldsController < ApplicationController
|
2009-12-17 21:21:02 +03:00
|
|
|
layout 'admin'
|
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
before_filter :require_admin
|
2006-07-29 13:32:58 +04:00
|
|
|
|
2006-06-28 22:11:03 +04:00
|
|
|
def index
|
2007-08-12 18:24:04 +04:00
|
|
|
@custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
|
2007-03-12 20:59:02 +03:00
|
|
|
@tab = params[:tab] || 'IssueCustomField'
|
2006-06-28 22:11:03 +04:00
|
|
|
end
|
2007-03-12 20:59:02 +03:00
|
|
|
|
|
|
|
def new
|
2009-01-17 11:41:30 +03:00
|
|
|
@custom_field = begin
|
|
|
|
if params[:type].to_s.match(/.+CustomField$/)
|
|
|
|
params[:type].to_s.constantize.new(params[:custom_field])
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
2009-12-18 17:22:18 +03:00
|
|
|
(redirect_to(:action => 'index'); return) unless @custom_field.is_a?(CustomField)
|
2009-01-17 11:41:30 +03:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
if request.post? and @custom_field.save
|
|
|
|
flash[:notice] = l(:notice_successful_create)
|
2009-03-21 03:22:59 +03:00
|
|
|
call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
|
2009-01-17 11:46:23 +03:00
|
|
|
redirect_to :action => 'index', :tab => @custom_field.class.name
|
2011-04-29 01:39:19 +04:00
|
|
|
else
|
|
|
|
@trackers = Tracker.find(:all, :order => 'position')
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@custom_field = CustomField.find(params[:id])
|
|
|
|
if request.post? and @custom_field.update_attributes(params[:custom_field])
|
|
|
|
flash[:notice] = l(:notice_successful_update)
|
2009-03-21 03:22:59 +03:00
|
|
|
call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
|
2009-01-17 11:46:23 +03:00
|
|
|
redirect_to :action => 'index', :tab => @custom_field.class.name
|
2011-04-29 01:39:19 +04:00
|
|
|
else
|
|
|
|
@trackers = Tracker.find(:all, :order => 'position')
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
|
|
|
end
|
2007-11-12 20:23:14 +03:00
|
|
|
|
2006-06-28 22:11:03 +04:00
|
|
|
def destroy
|
2007-03-12 20:59:02 +03:00
|
|
|
@custom_field = CustomField.find(params[:id]).destroy
|
2009-01-17 11:46:23 +03:00
|
|
|
redirect_to :action => 'index', :tab => @custom_field.class.name
|
2007-03-12 20:59:02 +03:00
|
|
|
rescue
|
2010-04-03 15:54:24 +04:00
|
|
|
flash[:error] = l(:error_can_not_delete_custom_field)
|
2009-01-17 11:46:23 +03:00
|
|
|
redirect_to :action => 'index'
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
end
|