Commit 06376254 authored by Winnie Hellmann's avatar Winnie Hellmann

Make NamespaceSelect a module

parent 3ddffec0
...@@ -16,7 +16,7 @@ import CILintEditor from './ci_lint_editor'; ...@@ -16,7 +16,7 @@ import CILintEditor from './ci_lint_editor';
/* global GroupsSelect */ /* global GroupsSelect */
/* global Search */ /* global Search */
/* global Admin */ /* global Admin */
/* global NamespaceSelects */ import NamespaceSelect from './namespace_select';
/* global NewCommitForm */ /* global NewCommitForm */
/* global NewBranchForm */ /* global NewBranchForm */
/* global Project */ /* global Project */
...@@ -571,7 +571,8 @@ import Diff from './diff'; ...@@ -571,7 +571,8 @@ import Diff from './diff';
new UsersSelect(); new UsersSelect();
break; break;
case 'projects': case 'projects':
new NamespaceSelects(); document.querySelectorAll('.js-namespace-select')
.forEach(dropdown => new NamespaceSelect({ dropdown }));
break; break;
case 'labels': case 'labels':
switch (path[2]) { switch (path[2]) {
......
/* 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 */ /* 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 */
import Api from './api'; import Api from './api';
(function() { export default class NamespaceSelect {
window.NamespaceSelect = (function() { constructor(opts) {
function NamespaceSelect(opts) {
this.onSelectItem = this.onSelectItem.bind(this); this.onSelectItem = this.onSelectItem.bind(this);
var fieldName, showAny; var fieldName, showAny;
this.dropdown = opts.dropdown; this.dropdown = $(opts.dropdown);
showAny = true; showAny = true;
fieldName = 'namespace_id'; fieldName = 'namespace_id';
if (this.dropdown.attr('data-field-name')) { if (this.dropdown.attr('data-field-name')) {
...@@ -56,30 +55,8 @@ import Api from './api'; ...@@ -56,30 +55,8 @@ import Api from './api';
}); });
} }
NamespaceSelect.prototype.onSelectItem = function(options) { onSelectItem(options) {
const { e } = options; const { e } = options;
return e.preventDefault(); return e.preventDefault();
};
return NamespaceSelect;
})();
window.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 window.NamespaceSelect({
dropdown: $dropdown
});
});
}
return NamespaceSelects;
})();
}).call(window);
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