2018-08-18 11:19:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-02-13 14:08:26 +00:00
|
|
|
module SelectsHelper
|
|
|
|
def users_select_tag(id, opts = {})
|
2018-08-18 11:19:57 +00:00
|
|
|
css_class = ["ajax-users-select"]
|
|
|
|
css_class << "multiselect" if opts[:multiple]
|
|
|
|
css_class << "skip_ldap" if opts[:skip_ldap]
|
2014-02-13 14:08:26 +00:00
|
|
|
css_class << (opts[:class] || '')
|
|
|
|
value = opts[:selected] || ''
|
2015-03-27 02:13:49 +00:00
|
|
|
html = {
|
2018-08-18 11:19:57 +00:00
|
|
|
class: css_class.join(' '),
|
2016-07-13 14:38:21 +00:00
|
|
|
data: users_select_data_attributes(opts)
|
2015-03-27 02:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unless opts[:scope] == :all
|
2016-04-19 10:00:38 +00:00
|
|
|
project = opts[:project] || @project
|
|
|
|
|
2015-05-20 03:46:48 +00:00
|
|
|
if project
|
|
|
|
html['data-project-id'] = project.id
|
2015-03-27 02:13:49 +00:00
|
|
|
elsif @group
|
|
|
|
html['data-group-id'] = @group.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hidden_field_tag(id, value, html)
|
2014-02-13 14:08:26 +00:00
|
|
|
end
|
2014-12-30 09:32:24 +00:00
|
|
|
|
|
|
|
def groups_select_tag(id, opts = {})
|
2018-08-18 11:19:57 +00:00
|
|
|
classes = Array.wrap(opts[:class])
|
|
|
|
classes << 'ajax-groups-select'
|
|
|
|
|
|
|
|
opts[:class] = classes.join(' ')
|
|
|
|
|
2015-11-16 19:40:57 +00:00
|
|
|
select2_tag(id, opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
def namespace_select_tag(id, opts = {})
|
2018-08-18 11:19:57 +00:00
|
|
|
opts[:class] = [*opts[:class], 'ajax-namespace-select'].join(' ')
|
2015-11-16 19:40:57 +00:00
|
|
|
select2_tag(id, opts)
|
|
|
|
end
|
|
|
|
|
2015-12-07 16:12:04 +00:00
|
|
|
def project_select_tag(id, opts = {})
|
2018-08-18 11:19:57 +00:00
|
|
|
opts[:class] = [*opts[:class], 'ajax-project-select'].join(' ')
|
2015-12-07 16:12:04 +00:00
|
|
|
|
|
|
|
unless opts.delete(:scope) == :all
|
|
|
|
if @group
|
|
|
|
opts['data-group-id'] = @group.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-30 04:35:49 +00:00
|
|
|
with_feature_enabled_data_attribute =
|
|
|
|
case opts.delete(:with_feature_enabled)
|
|
|
|
when 'issues' then 'data-with-issues-enabled'
|
|
|
|
when 'merge_requests' then 'data-with-merge-requests-enabled'
|
|
|
|
end
|
|
|
|
|
|
|
|
opts[with_feature_enabled_data_attribute] = true
|
|
|
|
|
2015-12-07 16:12:04 +00:00
|
|
|
hidden_field_tag(id, opts[:selected], opts)
|
|
|
|
end
|
|
|
|
|
2015-11-16 19:40:57 +00:00
|
|
|
def select2_tag(id, opts = {})
|
2018-08-18 11:19:57 +00:00
|
|
|
klass_opts = [opts[:class]]
|
|
|
|
klass_opts << 'multiselect' if opts[:multiple]
|
|
|
|
|
|
|
|
opts[:class] = klass_opts.join(' ')
|
2014-12-30 09:32:24 +00:00
|
|
|
value = opts[:selected] || ''
|
|
|
|
|
2016-09-01 17:23:39 +00:00
|
|
|
hidden_field_tag(id, value, opts)
|
2014-12-30 09:32:24 +00:00
|
|
|
end
|
2016-07-13 14:38:21 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def users_select_data_attributes(opts)
|
|
|
|
{
|
|
|
|
placeholder: opts[:placeholder] || 'Search for a user',
|
|
|
|
null_user: opts[:null_user] || false,
|
|
|
|
any_user: opts[:any_user] || false,
|
|
|
|
email_user: opts[:email_user] || false,
|
|
|
|
first_user: opts[:first_user] && current_user ? current_user.username : false,
|
|
|
|
current_user: opts[:current_user] || false,
|
|
|
|
author_id: opts[:author_id] || '',
|
2017-05-03 11:22:03 +00:00
|
|
|
skip_users: opts[:skip_users] ? opts[:skip_users].map(&:id) : nil
|
2016-07-13 14:38:21 +00:00
|
|
|
}
|
|
|
|
end
|
2014-02-13 14:08:26 +00:00
|
|
|
end
|