2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
module SelectsHelper
|
2015-04-26 12:48:37 +05:30
|
|
|
def groups_select_tag(id, opts = {})
|
2018-12-05 23:21:45 +05:30
|
|
|
classes = Array.wrap(opts[:class])
|
|
|
|
classes << 'ajax-groups-select'
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
# EE requires this line to be present, but there is no easy way of injecting
|
|
|
|
# this into EE without causing merge conflicts. Given this line is very
|
|
|
|
# simple and not really EE specific on its own, we just include it in CE.
|
|
|
|
classes << 'multiselect' if opts[:multiple]
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
opts[:class] = classes.join(' ')
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
select2_tag(id, opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_select_tag(id, opts = {})
|
2018-12-05 23:21:45 +05:30
|
|
|
opts[:class] = [*opts[:class], 'ajax-project-select'].join(' ')
|
2015-12-23 02:04:40 +05:30
|
|
|
|
|
|
|
unless opts.delete(:scope) == :all
|
|
|
|
if @group
|
|
|
|
opts['data-group-id'] = @group.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
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-23 02:04:40 +05:30
|
|
|
hidden_field_tag(id, opts[:selected], opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
def select2_tag(id, opts = {})
|
2018-12-05 23:21:45 +05:30
|
|
|
klass_opts = [opts[:class]]
|
|
|
|
klass_opts << 'multiselect' if opts[:multiple]
|
|
|
|
|
|
|
|
opts[:class] = klass_opts.join(' ')
|
2014-09-02 18:07:02 +05:30
|
|
|
value = opts[:selected] || ''
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
hidden_field_tag(id, value, opts)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
SelectsHelper.prepend_mod_with('SelectsHelper')
|