2009-01-17 11:46:23 +03:00
|
|
|
# Redmine - project management software
|
2013-01-12 13:29:31 +04:00
|
|
|
# Copyright (C) 2006-2013 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.
|
2011-08-31 16:11:19 +04:00
|
|
|
#
|
2007-03-12 20:59:02 +03:00
|
|
|
# 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.
|
2011-08-31 16:11:19 +04:00
|
|
|
#
|
2007-03-12 20:59:02 +03:00
|
|
|
# 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'
|
2011-08-31 16:11:19 +04:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
before_filter :require_admin
|
2011-12-10 02:58:30 +04:00
|
|
|
before_filter :build_new_custom_field, :only => [:new, :create]
|
|
|
|
before_filter :find_custom_field, :only => [:edit, :update, :destroy]
|
2006-07-29 13:32:58 +04:00
|
|
|
|
2006-06-28 22:11:03 +04:00
|
|
|
def index
|
2012-12-02 23:09:42 +04:00
|
|
|
@custom_fields_by_type = CustomField.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-08-31 16:11:19 +04:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
def new
|
2011-12-10 02:58:30 +04:00
|
|
|
end
|
2011-08-31 16:11:19 +04:00
|
|
|
|
2011-12-10 02:58:30 +04:00
|
|
|
def create
|
2012-12-11 23:42:12 +04:00
|
|
|
if @custom_field.save
|
2007-03-12 20:59:02 +03:00
|
|
|
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)
|
2012-12-11 21:51:30 +04:00
|
|
|
redirect_to custom_fields_path(:tab => @custom_field.class.name)
|
2011-05-02 03:15:03 +04:00
|
|
|
else
|
2011-12-10 02:58:30 +04:00
|
|
|
render :action => 'new'
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2011-12-10 02:58:30 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-12-11 23:42:12 +04:00
|
|
|
if @custom_field.update_attributes(params[:custom_field])
|
2007-03-12 20:59:02 +03:00
|
|
|
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)
|
2012-12-11 21:51:30 +04:00
|
|
|
redirect_to custom_fields_path(:tab => @custom_field.class.name)
|
2011-05-02 03:15:03 +04:00
|
|
|
else
|
2011-12-10 02:58:30 +04:00
|
|
|
render :action => 'edit'
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
|
|
|
end
|
2011-08-31 16:11:19 +04:00
|
|
|
|
2006-06-28 22:11:03 +04:00
|
|
|
def destroy
|
2012-12-11 23:42:12 +04:00
|
|
|
begin
|
|
|
|
@custom_field.destroy
|
|
|
|
rescue
|
|
|
|
flash[:error] = l(:error_can_not_delete_custom_field)
|
|
|
|
end
|
2012-12-11 21:51:30 +04:00
|
|
|
redirect_to custom_fields_path(:tab => @custom_field.class.name)
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2011-12-10 02:58:30 +04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def build_new_custom_field
|
|
|
|
@custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
|
|
|
|
if @custom_field.nil?
|
|
|
|
render_404
|
2013-02-15 14:43:56 +04:00
|
|
|
else
|
|
|
|
@custom_field.default_value = nil
|
2011-12-10 02:58:30 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_custom_field
|
|
|
|
@custom_field = CustomField.find(params[:id])
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
end
|