2015-12-07 11:12:04 -05:00
|
|
|
class @ProjectSelect
|
|
|
|
constructor: ->
|
|
|
|
$('.ajax-project-select').each (i, select) ->
|
|
|
|
@groupId = $(select).data('group-id')
|
2015-12-07 11:24:15 -05:00
|
|
|
@includeGroups = $(select).data('include-groups')
|
2016-02-03 17:27:00 -05:00
|
|
|
@orderBy = $(select).data('order-by') || 'id'
|
2015-12-07 11:24:15 -05:00
|
|
|
|
|
|
|
placeholder = "Search for project"
|
|
|
|
placeholder += " or group" if @includeGroups
|
2015-12-07 11:12:04 -05:00
|
|
|
|
|
|
|
$(select).select2
|
2015-12-07 11:24:15 -05:00
|
|
|
placeholder: placeholder
|
2015-12-07 11:12:04 -05:00
|
|
|
minimumInputLength: 0
|
|
|
|
query: (query) =>
|
2015-12-07 11:24:15 -05:00
|
|
|
finalCallback = (projects) ->
|
2015-12-07 11:12:04 -05:00
|
|
|
data = { results: projects }
|
|
|
|
query.callback(data)
|
|
|
|
|
2015-12-07 11:24:15 -05:00
|
|
|
if @includeGroups
|
|
|
|
projectsCallback = (projects) ->
|
|
|
|
groupsCallback = (groups) ->
|
|
|
|
data = groups.concat(projects)
|
|
|
|
finalCallback(data)
|
|
|
|
|
|
|
|
Api.groups query.term, false, groupsCallback
|
|
|
|
else
|
|
|
|
projectsCallback = finalCallback
|
|
|
|
|
2015-12-07 11:12:04 -05:00
|
|
|
if @groupId
|
2015-12-07 11:24:15 -05:00
|
|
|
Api.groupProjects @groupId, query.term, projectsCallback
|
2015-12-07 11:12:04 -05:00
|
|
|
else
|
2016-02-03 17:27:00 -05:00
|
|
|
Api.projects query.term, @orderBy, projectsCallback
|
2015-12-07 11:12:04 -05:00
|
|
|
|
|
|
|
id: (project) ->
|
|
|
|
project.web_url
|
|
|
|
|
|
|
|
text: (project) ->
|
2015-12-07 11:24:15 -05:00
|
|
|
project.name_with_namespace || project.name
|
2015-12-07 11:12:04 -05:00
|
|
|
|
|
|
|
dropdownCssClass: "ajax-project-dropdown"
|