Commit 41455893 authored by Grzegorz Bizon's avatar Grzegorz Bizon

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.
parent 15d32b6a
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) =>
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, options.term, @createCallback(options)
Api.groupProjects @groupId, query.term, projectsCallback
else
Api.projects options.term, @orderBy, @createCallback(options)
Api.projects query.term, @orderBy, projectsCallback
id: (project) =>
project[@selectId]
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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment