debian-mirror-gitlab/app/helpers/form_helper.rb

77 lines
2.2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
module FormHelper
2019-12-04 20:38:33 +05:30
prepend_if_ee('::EE::FormHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule
2018-03-17 18:26:18 +05:30
def form_errors(model, type: 'form')
2016-06-02 11:05:42 +05:30
return unless model.errors.any?
2019-07-07 11:18:12 +05:30
headline = n_('The %{type} contains the following error:', 'The %{type} contains the following errors:', model.errors.count) % { type: type }
2016-06-02 11:05:42 +05:30
content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do
content_tag(:h4, headline) <<
2017-08-17 22:00:37 +05:30
content_tag(:ul) do
2017-09-10 17:25:29 +05:30
model.errors.full_messages
.map { |msg| content_tag(:li, msg) }
.join
.html_safe
2017-08-17 22:00:37 +05:30
end
2016-06-02 11:05:42 +05:30
end
end
2017-08-17 22:00:37 +05:30
2019-07-31 22:56:46 +05:30
def assignees_dropdown_options(issuable_type)
dropdown_data = {
2017-08-17 22:00:37 +05:30
toggle_class: 'js-user-search js-assignee-search js-multiselect js-save-user-data',
title: 'Select assignee',
filter: true,
dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-assignee',
2019-07-07 11:18:12 +05:30
placeholder: _('Search users'),
2017-08-17 22:00:37 +05:30
data: {
first_user: current_user&.username,
null_user: true,
current_user: true,
2019-07-31 22:56:46 +05:30
project_id: (@target_project || @project)&.id,
field_name: "#{issuable_type}[assignee_ids][]",
2017-09-10 17:25:29 +05:30
default_label: 'Unassigned',
2017-08-17 22:00:37 +05:30
'max-select': 1,
'dropdown-header': 'Assignee',
multi_select: true,
'input-meta': 'name',
'always-show-selectbox': true,
2018-03-17 18:26:18 +05:30
current_user_info: UserSerializer.new.represent(current_user)
2017-08-17 22:00:37 +05:30
}
}
2019-07-31 22:56:46 +05:30
type = issuable_type.to_s
if type == 'issue' && issue_supports_multiple_assignees? ||
type == 'merge_request' && merge_request_supports_multiple_assignees?
dropdown_data = multiple_assignees_dropdown_options(dropdown_data)
end
dropdown_data
end
# Overwritten
def issue_supports_multiple_assignees?
false
end
# Overwritten
def merge_request_supports_multiple_assignees?
false
end
private
def multiple_assignees_dropdown_options(options)
new_options = options.dup
new_options[:title] = 'Select assignee(s)'
new_options[:data][:'dropdown-header'] = 'Assignee(s)'
new_options[:data].delete(:'max-select')
new_options
2017-08-17 22:00:37 +05:30
end
2016-06-02 11:05:42 +05:30
end