Commit 6fb19f77 authored by Filipa Lacerda's avatar Filipa Lacerda

Use ES6 modules in labels and labels manager

parent 9ac5338b
...@@ -29,7 +29,8 @@ import CILintEditor from './ci_lint_editor'; ...@@ -29,7 +29,8 @@ import CILintEditor from './ci_lint_editor';
/* global ProjectNew */ /* global ProjectNew */
/* global ProjectShow */ /* global ProjectShow */
/* global ProjectImport */ /* global ProjectImport */
/* global Labels */ import Labels from './labels';
import LabelManager from './label_manager';
/* global Shortcuts */ /* global Shortcuts */
/* global ShortcutsFindFile */ /* global ShortcutsFindFile */
/* global Sidebar */ /* global Sidebar */
...@@ -459,7 +460,7 @@ import U2FAuthenticate from './u2f/authenticate'; ...@@ -459,7 +460,7 @@ import U2FAuthenticate from './u2f/authenticate';
case 'groups:labels:index': case 'groups:labels:index':
case 'projects:labels:index': case 'projects:labels:index':
if ($('.prioritized-labels').length) { if ($('.prioritized-labels').length) {
new gl.LabelManager(); new LabelManager();
} }
$('.label-subscription').each((i, el) => { $('.label-subscription').each((i, el) => {
const $el = $(el); const $el = $(el);
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
import Flash from './flash'; import Flash from './flash';
((global) => { export default class LabelManager {
class LabelManager {
constructor({ togglePriorityButton, prioritizedLabels, otherLabels } = {}) { constructor({ togglePriorityButton, prioritizedLabels, otherLabels } = {}) {
this.togglePriorityButton = togglePriorityButton || $('.js-toggle-priority'); this.togglePriorityButton = togglePriorityButton || $('.js-toggle-priority');
this.prioritizedLabels = prioritizedLabels || $('.js-prioritized-labels'); this.prioritizedLabels = prioritizedLabels || $('.js-prioritized-labels');
...@@ -119,7 +118,4 @@ import Flash from './flash'; ...@@ -119,7 +118,4 @@ import Flash from './flash';
}); });
return sortedIds; return sortedIds;
} }
} }
gl.LabelManager = LabelManager;
})(window.gl || (window.gl = {}));
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, vars-on-top, no-unused-vars, max-len */ export default class Labels {
(function() { constructor() {
this.Labels = (function() {
function Labels() {
this.setSuggestedColor = this.setSuggestedColor.bind(this); this.setSuggestedColor = this.setSuggestedColor.bind(this);
this.updateColorPreview = this.updateColorPreview.bind(this); this.updateColorPreview = this.updateColorPreview.bind(this);
var form;
form = $('.label-form');
this.cleanBinding(); this.cleanBinding();
this.addBinding(); this.addBinding();
this.updateColorPreview(); this.updateColorPreview();
} }
Labels.prototype.addBinding = function() { addBinding() {
$(document).on('click', '.suggest-colors a', this.setSuggestedColor); $(document).on('click', '.suggest-colors a', this.setSuggestedColor);
return $(document).on('input', 'input#label_color', this.updateColorPreview); return $(document).on('input', 'input#label_color', this.updateColorPreview);
}; }
// eslint-disable-next-line class-methods-use-this
Labels.prototype.cleanBinding = function() { cleanBinding() {
$(document).off('click', '.suggest-colors a'); $(document).off('click', '.suggest-colors a');
return $(document).off('input', 'input#label_color'); return $(document).off('input', 'input#label_color');
}; }
// eslint-disable-next-line class-methods-use-this
Labels.prototype.updateColorPreview = function() { updateColorPreview() {
var previewColor; const previewColor = $('input#label_color').val();
previewColor = $('input#label_color').val();
return $('div.label-color-preview').css('background-color', previewColor); return $('div.label-color-preview').css('background-color', previewColor);
// Updates the the preview color with the hex-color input // Updates the the preview color with the hex-color input
}; }
// Updates the preview color with a click on a suggested color // Updates the preview color with a click on a suggested color
Labels.prototype.setSuggestedColor = function(e) { setSuggestedColor(e) {
var color; const color = $(e.currentTarget).data('color');
color = $(e.currentTarget).data('color');
$('input#label_color').val(color); $('input#label_color').val(color);
this.updateColorPreview(); this.updateColorPreview();
// Notify the form, that color has changed // Notify the form, that color has changed
$('.label-form').trigger('keyup'); $('.label-form').trigger('keyup');
return e.preventDefault(); return e.preventDefault();
}; }
}
return Labels;
})();
}).call(window);
...@@ -79,8 +79,6 @@ import './issuable_context'; ...@@ -79,8 +79,6 @@ import './issuable_context';
import './issuable_form'; import './issuable_form';
import './issue'; import './issue';
import './issue_status_select'; import './issue_status_select';
import './label_manager';
import './labels';
import './labels_select'; import './labels_select';
import './layout_nav'; import './layout_nav';
import LazyLoader from './lazy_loader'; import LazyLoader from './lazy_loader';
......
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