2019-03-16 09:37:35 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2009-01-17 08:46:23 +00:00
|
|
|
# Redmine - project management software
|
2024-02-26 22:55:54 +00:00
|
|
|
# Copyright (C) 2006- Jean-Philippe Lang
|
2007-03-12 17:59:02 +00: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 12:11:19 +00:00
|
|
|
#
|
2007-03-12 17:59:02 +00: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 12:11:19 +00:00
|
|
|
#
|
2007-03-12 17:59:02 +00: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 18:21:02 +00:00
|
|
|
layout 'admin'
|
2016-11-19 10:30:02 +00:00
|
|
|
self.main_menu = false
|
2011-08-31 12:11:19 +00:00
|
|
|
|
2016-07-14 07:27:31 +00:00
|
|
|
before_action :require_admin
|
|
|
|
|
before_action :build_new_custom_field, :only => [:new, :create]
|
|
|
|
|
before_action :find_custom_field, :only => [:edit, :update, :destroy]
|
2013-09-29 10:08:30 +00:00
|
|
|
accept_api_auth :index
|
2006-07-29 09:32:58 +00:00
|
|
|
|
2006-06-28 18:11:03 +00:00
|
|
|
def index
|
2013-09-29 10:08:30 +00:00
|
|
|
respond_to do |format|
|
2020-11-08 13:02:10 +00:00
|
|
|
format.html do
|
2020-11-18 16:15:50 +00:00
|
|
|
@custom_fields_by_type = CustomField.all.group_by {|f| f.class.name}
|
2016-12-13 19:46:31 +00:00
|
|
|
@custom_fields_projects_count =
|
|
|
|
|
IssueCustomField.where(is_for_all: false).joins(:projects).group(:custom_field_id).count
|
2020-11-08 13:02:10 +00:00
|
|
|
end
|
|
|
|
|
format.api do
|
2013-09-29 10:08:30 +00:00
|
|
|
@custom_fields = CustomField.all
|
2020-11-08 13:02:10 +00:00
|
|
|
end
|
2013-09-29 10:08:30 +00:00
|
|
|
end
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|
2011-08-31 12:11:19 +00:00
|
|
|
|
2007-03-12 17:59:02 +00:00
|
|
|
def new
|
2013-12-14 08:22:43 +00:00
|
|
|
@custom_field.field_format = 'string' if @custom_field.field_format.blank?
|
|
|
|
|
@custom_field.default_value = nil
|
2011-12-09 22:58:30 +00:00
|
|
|
end
|
2011-08-31 12:11:19 +00:00
|
|
|
|
2011-12-09 22:58:30 +00:00
|
|
|
def create
|
2012-12-11 19:42:12 +00:00
|
|
|
if @custom_field.save
|
2007-03-12 17:59:02 +00:00
|
|
|
flash[:notice] = l(:notice_successful_create)
|
2009-03-21 00:22:59 +00:00
|
|
|
call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
|
2019-04-09 14:53:55 +00:00
|
|
|
if params[:continue]
|
|
|
|
|
redirect_to new_custom_field_path({:type => @custom_field.type})
|
|
|
|
|
else
|
2020-05-04 00:46:50 +00:00
|
|
|
redirect_to custom_fields_path({:tab => @custom_field.type})
|
2019-04-09 14:53:55 +00:00
|
|
|
end
|
2011-05-01 23:15:03 +00:00
|
|
|
else
|
2011-12-09 22:58:30 +00:00
|
|
|
render :action => 'new'
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def edit
|
2011-12-09 22:58:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
2016-07-17 07:15:25 +00:00
|
|
|
@custom_field.safe_attributes = params[:custom_field]
|
|
|
|
|
if @custom_field.save
|
2009-03-21 00:22:59 +00:00
|
|
|
call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
|
2016-04-17 07:40:39 +00:00
|
|
|
respond_to do |format|
|
2020-11-08 13:02:10 +00:00
|
|
|
format.html do
|
2016-04-17 07:40:39 +00:00
|
|
|
flash[:notice] = l(:notice_successful_update)
|
|
|
|
|
redirect_back_or_default edit_custom_field_path(@custom_field)
|
2020-11-08 13:02:10 +00:00
|
|
|
end
|
2024-05-18 05:56:55 +00:00
|
|
|
format.js {head :ok}
|
2016-04-17 07:40:39 +00:00
|
|
|
end
|
2011-05-01 23:15:03 +00:00
|
|
|
else
|
2016-04-17 07:40:39 +00:00
|
|
|
respond_to do |format|
|
2020-11-18 16:15:50 +00:00
|
|
|
format.html {render :action => 'edit'}
|
2024-06-12 16:09:37 +00:00
|
|
|
format.js {head :unprocessable_content}
|
2016-04-17 07:40:39 +00:00
|
|
|
end
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
|
|
|
|
end
|
2011-08-31 12:11:19 +00:00
|
|
|
|
2006-06-28 18:11:03 +00:00
|
|
|
def destroy
|
2012-12-11 19:42:12 +00:00
|
|
|
begin
|
2017-03-02 19:41:00 +00:00
|
|
|
if @custom_field.destroy
|
|
|
|
|
flash[:notice] = l(:notice_successful_delete)
|
|
|
|
|
end
|
2012-12-11 19:42:12 +00:00
|
|
|
rescue
|
|
|
|
|
flash[:error] = l(:error_can_not_delete_custom_field)
|
|
|
|
|
end
|
2012-12-11 17:51:30 +00:00
|
|
|
redirect_to custom_fields_path(:tab => @custom_field.class.name)
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
2011-12-09 22:58:30 +00:00
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def build_new_custom_field
|
2016-07-17 07:15:25 +00:00
|
|
|
@custom_field = CustomField.new_subclass_instance(params[:type])
|
2011-12-09 22:58:30 +00:00
|
|
|
if @custom_field.nil?
|
2014-02-07 07:57:59 +00:00
|
|
|
render :action => 'select_type'
|
2016-07-17 07:15:25 +00:00
|
|
|
else
|
2020-12-26 01:36:19 +00:00
|
|
|
if params[:copy].present? && (@copy_from = CustomField.find_by(id: params[:copy]))
|
|
|
|
|
@custom_field.copy_from(@copy_from)
|
|
|
|
|
end
|
2016-07-17 07:15:25 +00:00
|
|
|
@custom_field.safe_attributes = params[:custom_field]
|
2011-12-09 22:58:30 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def find_custom_field
|
|
|
|
|
@custom_field = CustomField.find(params[:id])
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
render_404
|
|
|
|
|
end
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|