2014-10-21 16:52:38 -04:00
|
|
|
class @NamespaceSelect
|
|
|
|
constructor: ->
|
|
|
|
namespaceFormatResult = (namespace) ->
|
|
|
|
markup = "<div class='namespace-result'>"
|
|
|
|
markup += "<span class='namespace-kind'>" + namespace.kind + "</span>"
|
|
|
|
markup += "<span class='namespace-path'>" + namespace.path + "</span>"
|
|
|
|
markup += "</div>"
|
|
|
|
markup
|
2013-11-15 08:25:09 -05:00
|
|
|
|
2014-10-21 16:52:38 -04:00
|
|
|
formatSelection = (namespace) ->
|
|
|
|
namespace.kind + ": " + namespace.path
|
2013-11-15 08:25:09 -05:00
|
|
|
|
2014-10-21 16:52:38 -04:00
|
|
|
$('.ajax-namespace-select').each (i, select) ->
|
|
|
|
$(select).select2
|
|
|
|
placeholder: "Search for namespace"
|
|
|
|
multiple: $(select).hasClass('multiselect')
|
|
|
|
minimumInputLength: 0
|
|
|
|
query: (query) ->
|
|
|
|
Api.namespaces query.term, (namespaces) ->
|
|
|
|
data = { results: namespaces }
|
|
|
|
query.callback(data)
|
2013-11-15 08:25:09 -05:00
|
|
|
|
2014-10-21 16:52:38 -04:00
|
|
|
dropdownCssClass: "ajax-namespace-dropdown"
|
|
|
|
formatResult: namespaceFormatResult
|
|
|
|
formatSelection: formatSelection
|