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) =>
if @groupId
Api.groupProjects @groupId, options.term, @createCallback(options)
else
Api.projects options.term, @orderBy, @createCallback(options)
id: (project) =>
project[@selectId]
text: (project) ->
project.name_with_namespace || project.name
dropdownCssClass: "ajax-project-dropdown"
createCallback: (options) =>
query: (query) =>
finalCallback = (projects) ->
options.callback({ results: projects })
@withoutIdCallbackDecorator(
@accessLevelCallbackDecorator(
@groupsCallbackDecorator(
finalCallback
)
)
)
data = { results: projects }
query.callback(data)
groupsCallbackDecorator: (callback) =>
return callback unless @includeGroups
(projects) =>
Api.groups options.term, false, (groups) =>
if @includeGroups
projectsCallback = (projects) ->
groupsCallback = (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)
finalCallback(data)
max >= @accessLevel
Api.groups query.term, false, groupsCallback
else
projectsCallback = finalCallback
callback(data)
if @groupId
Api.groupProjects @groupId, query.term, projectsCallback
else
Api.projects query.term, @orderBy, projectsCallback
withoutIdCallbackDecorator: (callback) =>
return callback unless @withoutId
id: (project) ->
project.web_url
(projects) =>
data = projects.filter (p) =>
p.id != @withoutId
text: (project) ->
project.name_with_namespace || project.name
callback(data)
dropdownCssClass: "ajax-project-dropdown"
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