2009-01-17 11:46:23 +03:00
|
|
|
# Redmine - project management software
|
2014-01-30 02:45:39 +04:00
|
|
|
# Copyright (C) 2006-2014 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]
|
2013-09-29 14:08:30 +04:00
|
|
|
accept_api_auth :index
|
2006-07-29 13:32:58 +04:00
|
|
|
|
2006-06-28 22:11:03 +04:00
|
|
|
def index
|
2013-09-29 14:08:30 +04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
@custom_fields_by_type = CustomField.all.group_by {|f| f.class.name }
|
|
|
|
}
|
|
|
|
format.api {
|
|
|
|
@custom_fields = CustomField.all
|
|
|
|
}
|
|
|
|
end
|
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
|
2013-12-14 12:22:43 +04:00
|
|
|
@custom_field.field_format = 'string' if @custom_field.field_format.blank?
|
|
|
|
@custom_field.default_value = nil
|
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?
|
2014-02-07 11:57:59 +04:00
|
|
|
render :action => 'select_type'
|
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
|