2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2013-01-07 02:20:49 +04:00
|
|
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04: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.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
class CustomFieldsController < ApplicationController
|
2009-12-17 21:21:02 +03:00
|
|
|
layout 'admin'
|
2011-05-30 22:52:25 +04:00
|
|
|
|
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
|
2011-05-30 22:52:25 +04:00
|
|
|
|
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)
|
2011-05-30 22:52:25 +04: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
|
2011-05-30 22:52:25 +04: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
|