2017-01-11 23:27:41 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, one-var, vars-on-top, one-var-declaration-per-line, comma-dangle, object-shorthand, no-else-return, prefer-template, quotes, prefer-arrow-callback, no-param-reassign, no-cond-assign, max-len */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Api */
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
2017-01-11 23:27:41 -05:00
|
|
|
var bind = function(fn, me) { return function() { return fn.apply(me, arguments); }; };
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2016-12-14 00:26:26 -05:00
|
|
|
window.NamespaceSelect = (function() {
|
2016-07-24 16:45:11 -04:00
|
|
|
function NamespaceSelect(opts) {
|
|
|
|
this.onSelectItem = bind(this.onSelectItem, this);
|
|
|
|
var fieldName, showAny;
|
|
|
|
this.dropdown = opts.dropdown;
|
|
|
|
showAny = true;
|
|
|
|
fieldName = 'namespace_id';
|
|
|
|
if (this.dropdown.attr('data-field-name')) {
|
|
|
|
fieldName = this.dropdown.data('fieldName');
|
|
|
|
}
|
|
|
|
if (this.dropdown.attr('data-show-any')) {
|
|
|
|
showAny = this.dropdown.data('showAny');
|
|
|
|
}
|
|
|
|
this.dropdown.glDropdown({
|
|
|
|
filterable: true,
|
|
|
|
selectable: true,
|
|
|
|
filterRemote: true,
|
|
|
|
search: {
|
|
|
|
fields: ['path']
|
|
|
|
},
|
|
|
|
fieldName: fieldName,
|
|
|
|
toggleLabel: function(selected) {
|
|
|
|
if (selected.id == null) {
|
|
|
|
return selected.text;
|
|
|
|
} else {
|
2017-02-14 08:34:36 -05:00
|
|
|
return selected.kind + ": " + selected.full_path;
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data: function(term, dataCallback) {
|
|
|
|
return Api.namespaces(term, function(namespaces) {
|
|
|
|
var anyNamespace;
|
|
|
|
if (showAny) {
|
|
|
|
anyNamespace = {
|
|
|
|
text: 'Any namespace',
|
|
|
|
id: null
|
|
|
|
};
|
|
|
|
namespaces.unshift(anyNamespace);
|
|
|
|
namespaces.splice(1, 0, 'divider');
|
|
|
|
}
|
|
|
|
return dataCallback(namespaces);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
text: function(namespace) {
|
|
|
|
if (namespace.id == null) {
|
|
|
|
return namespace.text;
|
|
|
|
} else {
|
2017-02-14 08:34:36 -05:00
|
|
|
return namespace.kind + ": " + namespace.full_path;
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
renderRow: this.renderRow,
|
|
|
|
clicked: this.onSelectItem
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
NamespaceSelect.prototype.onSelectItem = function(item, el, e) {
|
|
|
|
return e.preventDefault();
|
|
|
|
};
|
|
|
|
|
|
|
|
return NamespaceSelect;
|
|
|
|
})();
|
|
|
|
|
2016-12-14 00:26:26 -05:00
|
|
|
window.NamespaceSelects = (function() {
|
2016-07-24 16:45:11 -04:00
|
|
|
function NamespaceSelects(opts) {
|
|
|
|
var ref;
|
|
|
|
if (opts == null) {
|
|
|
|
opts = {};
|
|
|
|
}
|
|
|
|
this.$dropdowns = (ref = opts.$dropdowns) != null ? ref : $('.js-namespace-select');
|
|
|
|
this.$dropdowns.each(function(i, dropdown) {
|
|
|
|
var $dropdown;
|
|
|
|
$dropdown = $(dropdown);
|
2016-12-14 00:26:26 -05:00
|
|
|
return new window.NamespaceSelect({
|
2016-07-24 16:45:11 -04:00
|
|
|
dropdown: $dropdown
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return NamespaceSelects;
|
|
|
|
})();
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|