Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-07-24 23:45:11 +0300
committerFatih Acet <acetfatih@gmail.com>2016-07-24 23:45:11 +0300
commitaaa9509d120524573085e94af9de5cdde83e3271 (patch)
tree3824cffd4cdd132ee9cf75a00a7624f5ccc0dabd /app/assets/javascripts/namespace_select.js
parent56b79181adc0bd6e9abef97ea075c14be971a01a (diff)
ES6ify all the things!
Diffstat (limited to 'app/assets/javascripts/namespace_select.js')
-rw-r--r--app/assets/javascripts/namespace_select.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/app/assets/javascripts/namespace_select.js b/app/assets/javascripts/namespace_select.js
new file mode 100644
index 00000000000..10f4fd106d8
--- /dev/null
+++ b/app/assets/javascripts/namespace_select.js
@@ -0,0 +1,86 @@
+(function() {
+ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+
+ this.NamespaceSelect = (function() {
+ 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 {
+ return selected.kind + ": " + selected.path;
+ }
+ },
+ 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 {
+ return namespace.kind + ": " + namespace.path;
+ }
+ },
+ renderRow: this.renderRow,
+ clicked: this.onSelectItem
+ });
+ }
+
+ NamespaceSelect.prototype.onSelectItem = function(item, el, e) {
+ return e.preventDefault();
+ };
+
+ return NamespaceSelect;
+
+ })();
+
+ this.NamespaceSelects = (function() {
+ 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);
+ return new NamespaceSelect({
+ dropdown: $dropdown
+ });
+ });
+ }
+
+ return NamespaceSelects;
+
+ })();
+
+}).call(this);