Commit 32a7d49a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #8125 from cirosantilli/namespace-select-js-only-needed

Only run namespace select js when needed
parents f4178f96 ab1ad3bd
...@@ -78,7 +78,11 @@ class Dispatcher ...@@ -78,7 +78,11 @@ class Dispatcher
shortcut_handler = true shortcut_handler = true
switch path.first() switch path.first()
when 'admin' then new Admin() when 'admin'
new Admin()
switch path[1]
when 'projects'
new NamespaceSelect()
when 'dashboard' when 'dashboard'
shortcut_handler = new ShortcutsDashboardNavigation() shortcut_handler = new ShortcutsDashboardNavigation()
when 'projects' when 'projects'
......
$ -> class @NamespaceSelect
namespaceFormatResult = (namespace) -> constructor: ->
markup = "<div class='namespace-result'>" namespaceFormatResult = (namespace) ->
markup += "<span class='namespace-kind'>" + namespace.kind + "</span>" markup = "<div class='namespace-result'>"
markup += "<span class='namespace-path'>" + namespace.path + "</span>" markup += "<span class='namespace-kind'>" + namespace.kind + "</span>"
markup += "</div>" markup += "<span class='namespace-path'>" + namespace.path + "</span>"
markup markup += "</div>"
markup
formatSelection = (namespace) -> formatSelection = (namespace) ->
namespace.kind + ": " + namespace.path namespace.kind + ": " + namespace.path
$('.ajax-namespace-select').each (i, select) -> $('.ajax-namespace-select').each (i, select) ->
$(select).select2 $(select).select2
placeholder: "Search for namespace" placeholder: "Search for namespace"
multiple: $(select).hasClass('multiselect') multiple: $(select).hasClass('multiselect')
minimumInputLength: 0 minimumInputLength: 0
query: (query) -> query: (query) ->
Api.namespaces query.term, (namespaces) -> Api.namespaces query.term, (namespaces) ->
data = { results: namespaces } data = { results: namespaces }
query.callback(data) query.callback(data)
dropdownCssClass: "ajax-namespace-dropdown" dropdownCssClass: "ajax-namespace-dropdown"
formatResult: namespaceFormatResult formatResult: namespaceFormatResult
formatSelection: formatSelection formatSelection: formatSelection
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