debian-mirror-gitlab/app/helpers/selects_helper.rb

46 lines
1.3 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
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] || ''
2015-04-26 12:48:37 +05:30
placeholder = opts[:placeholder] || 'Search for a user'
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
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
2015-09-11 14:41:01 +05:30
current_user = opts[:current_user] || false
project = opts[:project] || @project
2015-04-26 12:48:37 +05:30
html = {
class: css_class,
'data-placeholder' => placeholder,
'data-null-user' => null_user,
'data-any-user' => any_user,
'data-email-user' => email_user,
2015-09-11 14:41:01 +05:30
'data-first-user' => first_user,
'data-current-user' => current_user
2015-04-26 12:48:37 +05:30
}
unless opts[:scope] == :all
2015-09-11 14:41:01 +05:30
if project
html['data-project-id'] = project.id
2015-04-26 12:48:37 +05:30
elsif @group
html['data-group-id'] = @group.id
end
end
hidden_field_tag(id, value, html)
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
def groups_select_tag(id, opts = {})
css_class = "ajax-groups-select "
2014-09-02 18:07:02 +05:30
css_class << "multiselect " if opts[:multiple]
css_class << (opts[:class] || '')
value = opts[:selected] || ''
2015-04-26 12:48:37 +05:30
hidden_field_tag(id, value, class: css_class)
2014-09-02 18:07:02 +05:30
end
end