BigW Consortium Gitlab

selects_helper.rb 1.81 KB
Newer Older
1 2 3 4 5 6
module SelectsHelper
  def users_select_tag(id, opts = {})
    css_class = "ajax-users-select "
    css_class << "multiselect " if opts[:multiple]
    css_class << (opts[:class] || '')
    value = opts[:selected] || ''
7
    placeholder = opts[:placeholder] || 'Search for a user'
8

9 10
    null_user = opts[:null_user] || false
    any_user = opts[:any_user] || false
11
    email_user = opts[:email_user] || false
12
    first_user = opts[:first_user] && current_user ? current_user.username : false
13
    current_user = opts[:current_user] || false
14
    project = opts[:project] || @project
15

16 17
    html = {
      class: css_class,
18 19 20 21 22 23 24 25
      data: {
        placeholder: placeholder,
        null_user: null_user,
        any_user: any_user,
        email_user: email_user,
        first_user: first_user,
        current_user: current_user
      }
26 27 28
    }

    unless opts[:scope] == :all
29 30
      if project
        html['data-project-id'] = project.id
31 32 33 34 35 36
      elsif @group
        html['data-group-id'] = @group.id
      end
    end

    hidden_field_tag(id, value, html)
37
  end
38 39

  def groups_select_tag(id, opts = {})
40 41 42 43 44 45 46 47 48 49 50
    opts[:class] ||= ''
    opts[:class] << ' ajax-groups-select'
    select2_tag(id, opts)
  end

  def namespace_select_tag(id, opts = {})
    opts[:class] ||= ''
    opts[:class] << ' ajax-namespace-select'
    select2_tag(id, opts)
  end

51 52 53 54 55 56 57 58 59 60 61 62 63
  def project_select_tag(id, opts = {})
    opts[:class] ||= ''
    opts[:class] << ' ajax-project-select'

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

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

64 65 66
  def select2_tag(id, opts = {})
    css_class = ''
    css_class << 'multiselect ' if opts[:multiple]
67 68 69 70 71
    css_class << (opts[:class] || '')
    value = opts[:selected] || ''

    hidden_field_tag(id, value, class: css_class)
  end
72
end