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]
|
2016-06-02 11:05:42 +05:30
|
|
|
css_class << "skip_ldap " if opts[:skip_ldap]
|
2014-09-02 18:07:02 +05:30
|
|
|
css_class << (opts[:class] || '')
|
|
|
|
value = opts[:selected] || ''
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
first_user = opts[:first_user] && current_user ? current_user.username : false
|
|
|
|
|
|
|
|
html = {
|
|
|
|
class: css_class,
|
2015-12-23 02:04:40 +05:30
|
|
|
data: {
|
2016-06-02 11:05:42 +05:30
|
|
|
placeholder: opts[:placeholder] || 'Search for a user',
|
|
|
|
null_user: opts[:null_user] || false,
|
|
|
|
any_user: opts[:any_user] || false,
|
|
|
|
email_user: opts[:email_user] || false,
|
2015-12-23 02:04:40 +05:30
|
|
|
first_user: first_user,
|
2016-06-02 11:05:42 +05:30
|
|
|
current_user: opts[:current_user] || false,
|
|
|
|
"push-code-to-protected-branches" => opts[:push_code_to_protected_branches],
|
|
|
|
author_id: opts[:author_id] || ''
|
2015-12-23 02:04:40 +05:30
|
|
|
}
|
2015-04-26 12:48:37 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
unless opts[:scope] == :all
|
2016-06-02 11:05:42 +05:30
|
|
|
project = opts[:project] || @project
|
|
|
|
|
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 = {})
|
2015-12-23 02:04:40 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def select2_tag(id, opts = {})
|
|
|
|
css_class = ''
|
|
|
|
css_class << 'multiselect ' if opts[:multiple]
|
2014-09-02 18:07:02 +05:30
|
|
|
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
|