BigW Consortium Gitlab

Commit 115d4a41 by Kushal Pandya

Convert to pure ES6 class

parent 678672b0
/* eslint-disable arrow-parens, no-param-reassign, object-shorthand, no-else-return, comma-dangle, max-len */ export default class ProtectedTagAccessDropdown {
(global => {
global.gl = global.gl || {};
gl.ProtectedTagAccessDropdown = class {
constructor(options) { constructor(options) {
const { $dropdown, data, onSelect } = options; this.options = options;
this.initDropdown();
}
$dropdown.glDropdown({ initDropdown() {
data: data, const { onSelect } = this.options;
this.options.$dropdown.glDropdown({
data: this.options.data,
selectable: true, selectable: true,
inputId: $dropdown.data('input-id'), inputId: this.options.$dropdown.data('input-id'),
fieldName: $dropdown.data('field-name'), fieldName: this.options.$dropdown.data('field-name'),
toggleLabel(item, el) { toggleLabel(item, el) {
if (el.is('.is-active')) { if (el.is('.is-active')) {
return item.text; return item.text;
} else {
return 'Select';
} }
return 'Select';
}, },
clicked(item, $el, e) { clicked(item, $el, e) {
e.preventDefault(); e.preventDefault();
onSelect(); onSelect();
} },
}); });
} }
}; }
})(window);
/* eslint-disable no-new, arrow-parens, no-param-reassign, comma-dangle, max-len */ import ProtectedTagAccessDropdown from './protected_tag_access_dropdown';
/* global ProtectedTagDropdown */ import ProtectedTagDropdown from './protected_tag_dropdown';
(global => { export default class ProtectedTagCreate {
global.gl = global.gl || {};
gl.ProtectedTagCreate = class {
constructor() { constructor() {
this.$wrap = this.$form = $('.new_protected_tag'); this.$form = $('.new_protected_tag');
this.buildDropdowns(); this.buildDropdowns();
} }
buildDropdowns() { buildDropdowns() {
const $allowedToCreateDropdown = this.$wrap.find('.js-allowed-to-create'); const $allowedToCreateDropdown = this.$form.find('.js-allowed-to-create');
// Cache callback // Cache callback
this.onSelectCallback = this.onSelect.bind(this); this.onSelectCallback = this.onSelect.bind(this);
// Allowed to Create dropdown // Allowed to Create dropdown
new gl.ProtectedTagAccessDropdown({ this.protectedTagAccessDropdown = new ProtectedTagAccessDropdown({
$dropdown: $allowedToCreateDropdown, $dropdown: $allowedToCreateDropdown,
data: gon.create_access_levels, data: gon.create_access_levels,
onSelect: this.onSelectCallback onSelect: this.onSelectCallback,
}); });
// Select default // Select default
$allowedToCreateDropdown.data('glDropdown').selectRowAtIndex(0); $allowedToCreateDropdown.data('glDropdown').selectRowAtIndex(0);
// Protected tag dropdown // Protected tag dropdown
new ProtectedTagDropdown({ this.protectedTagDropdown = new ProtectedTagDropdown({
$dropdown: this.$wrap.find('.js-protected-tag-select'), $dropdown: this.$form.find('.js-protected-tag-select'),
onSelect: this.onSelectCallback onSelect: this.onSelectCallback,
}); });
} }
// This will run after clicked callback // This will run after clicked callback
onSelect() { onSelect() {
// Enable submit button // Enable submit button
const $tagInput = this.$wrap.find('input[name="protected_tag[name]"]'); const $tagInput = this.$form.find('input[name="protected_tag[name]"]');
const $allowedToCreateInput = this.$wrap.find('input[name="protected_tag[create_access_levels_attributes][0][access_level]"]'); const $allowedToCreateInput = this.$form.find('input[name="protected_tag[create_access_levels_attributes][0][access_level]"]');
this.$form.find('input[type="submit"]').attr('disabled', !($tagInput.val() && $allowedToCreateInput.length)); this.$form.find('input[type="submit"]').attr('disabled', !($tagInput.val() && $allowedToCreateInput.length));
} }
}; }
})(window);
/* eslint-disable comma-dangle, no-unused-vars */ export default class ProtectedTagDropdown {
class ProtectedTagDropdown {
constructor(options) { constructor(options) {
this.onSelect = options.onSelect; this.onSelect = options.onSelect;
this.$dropdown = options.$dropdown; this.$dropdown = options.$dropdown;
...@@ -21,7 +19,7 @@ class ProtectedTagDropdown { ...@@ -21,7 +19,7 @@ class ProtectedTagDropdown {
filterable: true, filterable: true,
remote: false, remote: false,
search: { search: {
fields: ['title'] fields: ['title'],
}, },
selectable: true, selectable: true,
toggleLabel(selected) { toggleLabel(selected) {
...@@ -38,7 +36,7 @@ class ProtectedTagDropdown { ...@@ -38,7 +36,7 @@ class ProtectedTagDropdown {
clicked: (item, $el, e) => { clicked: (item, $el, e) => {
e.preventDefault(); e.preventDefault();
this.onSelect(); this.onSelect();
} },
}); });
} }
...@@ -63,7 +61,7 @@ class ProtectedTagDropdown { ...@@ -63,7 +61,7 @@ class ProtectedTagDropdown {
this.selectedTag = { this.selectedTag = {
title: tagName, title: tagName,
id: tagName, id: tagName,
text: tagName text: tagName,
}; };
if (tagName) { if (tagName) {
...@@ -75,5 +73,3 @@ class ProtectedTagDropdown { ...@@ -75,5 +73,3 @@ class ProtectedTagDropdown {
this.$dropdownFooter.toggleClass('hidden', !tagName); this.$dropdownFooter.toggleClass('hidden', !tagName);
} }
} }
window.ProtectedTagDropdown = ProtectedTagDropdown;
/* eslint-disable no-new, arrow-parens, no-param-reassign, comma-dangle, max-len */ /* eslint-disable no-new */
/* global Flash */ /* global Flash */
(global => { import ProtectedTagAccessDropdown from './protected_tag_access_dropdown';
global.gl = global.gl || {};
gl.ProtectedTagEdit = class { export default class ProtectedTagEdit {
constructor(options) { constructor(options) {
this.$wrap = options.$wrap; this.$wrap = options.$wrap;
this.$allowedToCreateDropdown = this.$wrap.find('.js-allowed-to-create'); this.$allowedToCreateDropdown = this.$wrap.find('.js-allowed-to-create');
...@@ -14,10 +13,10 @@ ...@@ -14,10 +13,10 @@
buildDropdowns() { buildDropdowns() {
// Allowed to create dropdown // Allowed to create dropdown
new gl.ProtectedTagAccessDropdown({ this.protectedTagAccessDropdown = new ProtectedTagAccessDropdown({
$dropdown: this.$allowedToCreateDropdown, $dropdown: this.$allowedToCreateDropdown,
data: gon.create_access_levels, data: gon.create_access_levels,
onSelect: this.onSelect.bind(this) onSelect: this.onSelect.bind(this),
}); });
} }
...@@ -38,17 +37,16 @@ ...@@ -38,17 +37,16 @@
protected_tag: { protected_tag: {
create_access_levels_attributes: [{ create_access_levels_attributes: [{
id: this.$allowedToCreateDropdown.data('access-level-id'), id: this.$allowedToCreateDropdown.data('access-level-id'),
access_level: $allowedToCreateInput.val() access_level: $allowedToCreateInput.val(),
}] }],
} },
}, },
error() { error() {
$.scrollTo(0); $.scrollTo(0);
new Flash('Failed to update tag!'); new Flash('Failed to update tag!');
} },
}).always(() => { }).always(() => {
this.$allowedToCreateDropdown.enable(); this.$allowedToCreateDropdown.enable();
}); });
} }
}; }
})(window);
/* eslint-disable arrow-parens, no-param-reassign, no-new, comma-dangle */ import ProtectedTagEdit from './protected_tag_edit';
(global => { export default class ProtectedTagEditList {
global.gl = global.gl || {};
gl.ProtectedTagEditList = class {
constructor() { constructor() {
this.$wrap = $('.protected-tags-list'); this.$wrap = $('.protected-tags-list');
this.protectedTagList = [];
this.initEditForm();
}
// Build edit forms initEditForm() {
this.$wrap.find('.js-protected-tag-edit-form').each((i, el) => { this.$wrap.find('.js-protected-tag-edit-form').each((i, el) => {
new gl.ProtectedTagEdit({ this.protectedTagList[i] = new ProtectedTagEdit({
$wrap: $(el) $wrap: $(el),
}); });
}); });
} }
}; }
})(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