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