BigW Consortium Gitlab

selects_helper.rb 1.3 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 18 19 20
    html = {
      class: css_class,
      'data-placeholder' => placeholder,
      'data-null-user' => null_user,
      'data-any-user' => any_user,
21
      'data-email-user' => email_user,
22 23
      'data-first-user' => first_user,
      'data-current-user' => current_user
24 25 26
    }

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

    hidden_field_tag(id, value, html)
35
  end
36 37 38 39 40 41 42 43 44

  def groups_select_tag(id, opts = {})
    css_class = "ajax-groups-select "
    css_class << "multiselect " if opts[:multiple]
    css_class << (opts[:class] || '')
    value = opts[:selected] || ''

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