Welcome to mirror list, hosted at ThFree Co, Russian Federation.

selects_helper.rb « helpers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 99da9a7af6cb3a0b9adcf3012cc4430cc132366b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

module SelectsHelper
  def groups_select_tag(id, opts = {})
    classes = Array.wrap(opts[:class])
    classes << 'ajax-groups-select'

    # 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]

    opts[:class] = classes.join(' ')

    select2_tag(id, opts)
  end

  def project_select_tag(id, opts = {})
    opts[:class] = [*opts[:class], 'ajax-project-select'].join(' ')

    unless opts.delete(:scope) == :all
      if @group
        opts['data-group-id'] = @group.id
      end
    end

    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

    hidden_field_tag(id, opts[:selected], opts)
  end

  def select2_tag(id, opts = {})
    klass_opts = [opts[:class]]
    klass_opts << 'multiselect' if opts[:multiple]

    opts[:class] = klass_opts.join(' ')
    value = opts[:selected] || ''

    hidden_field_tag(id, value, opts)
  end
end

SelectsHelper.prepend_mod_with('SelectsHelper')