Revert changes in js used to create project select
This will preserve those changes in history, we may need them in future. Currently we will use a issues helpers to create options to choose project whem moving issue to it.
This commit is contained in:
parent
15d32b6a11
commit
4145589393
1 changed files with 22 additions and 52 deletions
|
@ -1,12 +1,9 @@
|
|||
class @ProjectSelect
|
||||
constructor: ->
|
||||
$('.ajax-project-select').each (i, select) =>
|
||||
$('.ajax-project-select').each (i, select) ->
|
||||
@groupId = $(select).data('group-id')
|
||||
@includeGroups = $(select).data('include-groups')
|
||||
@orderBy = $(select).data('order-by') || 'id'
|
||||
@selectId = $(select).data('select-id') || 'web_url'
|
||||
@accessLevel = $(select).data('access-level')
|
||||
@withoutId = $(select).data('without-id')
|
||||
|
||||
placeholder = "Search for project"
|
||||
placeholder += " or group" if @includeGroups
|
||||
|
@ -14,57 +11,30 @@ class @ProjectSelect
|
|||
$(select).select2
|
||||
placeholder: placeholder
|
||||
minimumInputLength: 0
|
||||
query: (options) =>
|
||||
if @groupId
|
||||
Api.groupProjects @groupId, options.term, @createCallback(options)
|
||||
else
|
||||
Api.projects options.term, @orderBy, @createCallback(options)
|
||||
query: (query) =>
|
||||
finalCallback = (projects) ->
|
||||
data = { results: projects }
|
||||
query.callback(data)
|
||||
|
||||
id: (project) =>
|
||||
project[@selectId]
|
||||
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
|
||||
Api.projects query.term, @orderBy, projectsCallback
|
||||
|
||||
id: (project) ->
|
||||
project.web_url
|
||||
|
||||
text: (project) ->
|
||||
project.name_with_namespace || project.name
|
||||
|
||||
dropdownCssClass: "ajax-project-dropdown"
|
||||
|
||||
createCallback: (options) =>
|
||||
finalCallback = (projects) ->
|
||||
options.callback({ results: projects })
|
||||
|
||||
@withoutIdCallbackDecorator(
|
||||
@accessLevelCallbackDecorator(
|
||||
@groupsCallbackDecorator(
|
||||
finalCallback
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
groupsCallbackDecorator: (callback) =>
|
||||
return callback unless @includeGroups
|
||||
|
||||
(projects) =>
|
||||
Api.groups options.term, false, (groups) =>
|
||||
data = groups.concat(projects)
|
||||
callback(data)
|
||||
|
||||
accessLevelCallbackDecorator: (callback) =>
|
||||
return callback unless @accessLevel
|
||||
|
||||
(projects) =>
|
||||
data = projects.filter (p) =>
|
||||
max = Math.max(p.permissions.group_access?.access_level ? 0,
|
||||
p.permissions.project_access?.access_level ? 0)
|
||||
|
||||
max >= @accessLevel
|
||||
|
||||
callback(data)
|
||||
|
||||
withoutIdCallbackDecorator: (callback) =>
|
||||
return callback unless @withoutId
|
||||
|
||||
(projects) =>
|
||||
data = projects.filter (p) =>
|
||||
p.id != @withoutId
|
||||
|
||||
callback(data)
|
||||
|
|
Loading…
Reference in a new issue