2014-02-13 09:08:26 -05:00
|
|
|
module SelectsHelper
|
|
|
|
def users_select_tag(id, opts = {})
|
|
|
|
css_class = "ajax-users-select "
|
|
|
|
css_class << "multiselect " if opts[:multiple]
|
2016-04-19 06:00:38 -04:00
|
|
|
css_class << "skip_ldap " if opts[:skip_ldap]
|
2014-02-13 09:08:26 -05:00
|
|
|
css_class << (opts[:class] || '')
|
|
|
|
value = opts[:selected] || ''
|
2015-03-26 22:13:49 -04:00
|
|
|
html = {
|
|
|
|
class: css_class,
|
2016-07-13 10:38:21 -04:00
|
|
|
data: users_select_data_attributes(opts)
|
2015-03-26 22:13:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
unless opts[:scope] == :all
|
2016-04-19 06:00:38 -04:00
|
|
|
project = opts[:project] || @project
|
|
|
|
|
2015-05-19 23:46:48 -04:00
|
|
|
if project
|
|
|
|
html['data-project-id'] = project.id
|
2015-03-26 22:13:49 -04:00
|
|
|
elsif @group
|
|
|
|
html['data-group-id'] = @group.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hidden_field_tag(id, value, html)
|
2014-02-13 09:08:26 -05:00
|
|
|
end
|
2014-12-30 04:32:24 -05:00
|
|
|
|
|
|
|
def groups_select_tag(id, opts = {})
|
2015-11-16 14:40:57 -05:00
|
|
|
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
|
|
|
|
|
2015-12-07 11:12:04 -05:00
|
|
|
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
|
|
|
|
|
2015-11-16 14:40:57 -05:00
|
|
|
def select2_tag(id, opts = {})
|
2016-09-01 13:23:39 -04:00
|
|
|
opts[:class] << ' multiselect' if opts[:multiple]
|
2014-12-30 04:32:24 -05:00
|
|
|
value = opts[:selected] || ''
|
|
|
|
|
2016-09-01 13:23:39 -04:00
|
|
|
hidden_field_tag(id, value, opts)
|
2014-12-30 04:32:24 -05:00
|
|
|
end
|
2016-07-13 10:38:21 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def users_select_data_attributes(opts)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
first_user: opts[:first_user] && current_user ? current_user.username : false,
|
|
|
|
current_user: opts[:current_user] || false,
|
|
|
|
"push-code-to-protected-branches" => opts[:push_code_to_protected_branches],
|
|
|
|
author_id: opts[:author_id] || '',
|
|
|
|
skip_users: opts[:skip_users] ? opts[:skip_users].map(&:id) : nil,
|
|
|
|
}
|
|
|
|
end
|
2014-02-13 09:08:26 -05:00
|
|
|
end
|