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 class @ProjectSelect
constructor: -> constructor: ->
$('.ajax-project-select').each (i, select) => $('.ajax-project-select').each (i, select) ->
@groupId = $(select).data('group-id') @groupId = $(select).data('group-id')
@includeGroups = $(select).data('include-groups') @includeGroups = $(select).data('include-groups')
@orderBy = $(select).data('order-by') || 'id' @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 = "Search for project"
placeholder += " or group" if @includeGroups placeholder += " or group" if @includeGroups
...@@ -14,57 +11,30 @@ class @ProjectSelect ...@@ -14,57 +11,30 @@ class @ProjectSelect
$(select).select2 $(select).select2
placeholder: placeholder placeholder: placeholder
minimumInputLength: 0 minimumInputLength: 0
query: (options) => query: (query) =>
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) =>
finalCallback = (projects) -> finalCallback = (projects) ->
options.callback({ results: projects }) data = { results: projects }
query.callback(data)
@withoutIdCallbackDecorator(
@accessLevelCallbackDecorator(
@groupsCallbackDecorator(
finalCallback
)
)
)
groupsCallbackDecorator: (callback) => if @includeGroups
return callback unless @includeGroups projectsCallback = (projects) ->
groupsCallback = (groups) ->
(projects) =>
Api.groups options.term, false, (groups) =>
data = groups.concat(projects) data = groups.concat(projects)
callback(data) finalCallback(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 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) => id: (project) ->
return callback unless @withoutId project.web_url
(projects) => text: (project) ->
data = projects.filter (p) => project.name_with_namespace || project.name
p.id != @withoutId
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