Commit 7b814822 authored by Filipa Lacerda's avatar Filipa Lacerda Committed by Phil Hughes

Remove AjaxLoadingSpinner and CreateLabelDropdown from global namespace

parent 1fd0668b
class AjaxLoadingSpinner { export default class AjaxLoadingSpinner {
static init() { static init() {
const $elements = $('.js-ajax-loading-spinner'); const $elements = $('.js-ajax-loading-spinner');
...@@ -30,6 +30,3 @@ class AjaxLoadingSpinner { ...@@ -30,6 +30,3 @@ class AjaxLoadingSpinner {
classList.toggle('fa-spin'); classList.toggle('fa-spin');
} }
} }
window.gl = window.gl || {};
gl.AjaxLoadingSpinner = AjaxLoadingSpinner;
/* eslint-disable comma-dangle, func-names, no-new, space-before-function-paren, one-var, /* eslint-disable func-names, no-new, space-before-function-paren, one-var,
promise/catch-or-return */ promise/catch-or-return */
import _ from 'underscore'; import _ from 'underscore';
import CreateLabelDropdown from '../../create_label';
window.gl = window.gl || {}; window.gl = window.gl || {};
window.gl.issueBoards = window.gl.issueBoards || {}; window.gl.issueBoards = window.gl.issueBoards || {};
...@@ -15,15 +16,15 @@ $(document).off('created.label').on('created.label', (e, label) => { ...@@ -15,15 +16,15 @@ $(document).off('created.label').on('created.label', (e, label) => {
label: { label: {
id: label.id, id: label.id,
title: label.title, title: label.title,
color: label.color color: label.color,
} },
}); });
}); });
gl.issueBoards.newListDropdownInit = () => { gl.issueBoards.newListDropdownInit = () => {
$('.js-new-board-list').each(function () { $('.js-new-board-list').each(function () {
const $this = $(this); const $this = $(this);
new gl.CreateLabelDropdown($this.closest('.dropdown').find('.dropdown-new-label'), $this.data('namespace-path'), $this.data('project-path')); new CreateLabelDropdown($this.closest('.dropdown').find('.dropdown-new-label'), $this.data('namespace-path'), $this.data('project-path'));
$this.glDropdown({ $this.glDropdown({
data(term, callback) { data(term, callback) {
...@@ -38,17 +39,17 @@ gl.issueBoards.newListDropdownInit = () => { ...@@ -38,17 +39,17 @@ gl.issueBoards.newListDropdownInit = () => {
const $a = $('<a />', { const $a = $('<a />', {
class: (active ? `is-active js-board-list-${active.id}` : ''), class: (active ? `is-active js-board-list-${active.id}` : ''),
text: label.title, text: label.title,
href: '#' href: '#',
}); });
const $labelColor = $('<span />', { const $labelColor = $('<span />', {
class: 'dropdown-label-box', class: 'dropdown-label-box',
style: `background-color: ${label.color}` style: `background-color: ${label.color}`,
}); });
return $li.append($a.prepend($labelColor)); return $li.append($a.prepend($labelColor));
}, },
search: { search: {
fields: ['title'] fields: ['title'],
}, },
filterable: true, filterable: true,
selectable: true, selectable: true,
...@@ -66,13 +67,13 @@ gl.issueBoards.newListDropdownInit = () => { ...@@ -66,13 +67,13 @@ gl.issueBoards.newListDropdownInit = () => {
label: { label: {
id: label.id, id: label.id,
title: label.title, title: label.title,
color: label.color color: label.color,
} },
}); });
Store.state.lists = _.sortBy(Store.state.lists, 'position'); Store.state.lists = _.sortBy(Store.state.lists, 'position');
} }
} },
}); });
}); });
}; };
/* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, comma-dangle, prefer-template, quotes, no-param-reassign, wrap-iife, max-len */ /* eslint-disable func-names, prefer-arrow-callback */
import Api from './api'; import Api from './api';
class CreateLabelDropdown { export default class CreateLabelDropdown {
constructor ($el, namespacePath, projectPath) { constructor($el, namespacePath, projectPath) {
this.$el = $el; this.$el = $el;
this.namespacePath = namespacePath; this.namespacePath = namespacePath;
this.projectPath = projectPath; this.projectPath = projectPath;
...@@ -22,7 +22,7 @@ class CreateLabelDropdown { ...@@ -22,7 +22,7 @@ class CreateLabelDropdown {
this.addBinding(); this.addBinding();
} }
cleanBinding () { cleanBinding() {
this.$colorSuggestions.off('click'); this.$colorSuggestions.off('click');
this.$newLabelField.off('keyup change'); this.$newLabelField.off('keyup change');
this.$newColorField.off('keyup change'); this.$newColorField.off('keyup change');
...@@ -31,7 +31,7 @@ class CreateLabelDropdown { ...@@ -31,7 +31,7 @@ class CreateLabelDropdown {
this.$newLabelCreateButton.off('click'); this.$newLabelCreateButton.off('click');
} }
addBinding () { addBinding() {
const self = this; const self = this;
this.$colorSuggestions.on('click', function (e) { this.$colorSuggestions.on('click', function (e) {
...@@ -44,7 +44,7 @@ class CreateLabelDropdown { ...@@ -44,7 +44,7 @@ class CreateLabelDropdown {
this.$dropdownBack.on('click', this.resetForm.bind(this)); this.$dropdownBack.on('click', this.resetForm.bind(this));
this.$cancelButton.on('click', function(e) { this.$cancelButton.on('click', function (e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
...@@ -55,7 +55,7 @@ class CreateLabelDropdown { ...@@ -55,7 +55,7 @@ class CreateLabelDropdown {
this.$newLabelCreateButton.on('click', this.saveLabel.bind(this)); this.$newLabelCreateButton.on('click', this.saveLabel.bind(this));
} }
addColorValue (e, $this) { addColorValue(e, $this) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
...@@ -66,7 +66,7 @@ class CreateLabelDropdown { ...@@ -66,7 +66,7 @@ class CreateLabelDropdown {
.addClass('is-active'); .addClass('is-active');
} }
enableLabelCreateButton () { enableLabelCreateButton() {
if (this.$newLabelField.val() !== '' && this.$newColorField.val() !== '') { if (this.$newLabelField.val() !== '' && this.$newColorField.val() !== '') {
this.$newLabelError.hide(); this.$newLabelError.hide();
this.$newLabelCreateButton.enable(); this.$newLabelCreateButton.enable();
...@@ -75,7 +75,7 @@ class CreateLabelDropdown { ...@@ -75,7 +75,7 @@ class CreateLabelDropdown {
} }
} }
resetForm () { resetForm() {
this.$newLabelField this.$newLabelField
.val('') .val('')
.trigger('change'); .trigger('change');
...@@ -90,13 +90,13 @@ class CreateLabelDropdown { ...@@ -90,13 +90,13 @@ class CreateLabelDropdown {
.removeClass('is-active'); .removeClass('is-active');
} }
saveLabel (e) { saveLabel(e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
Api.newLabel(this.namespacePath, this.projectPath, { Api.newLabel(this.namespacePath, this.projectPath, {
title: this.$newLabelField.val(), title: this.$newLabelField.val(),
color: this.$newColorField.val() color: this.$newColorField.val(),
}, (label) => { }, (label) => {
this.$newLabelCreateButton.enable(); this.$newLabelCreateButton.enable();
...@@ -107,8 +107,8 @@ class CreateLabelDropdown { ...@@ -107,8 +107,8 @@ class CreateLabelDropdown {
errors = label.message; errors = label.message;
} else { } else {
errors = Object.keys(label.message).map(key => errors = Object.keys(label.message).map(key =>
`${gl.text.humanize(key)} ${label.message[key].join(', ')}` `${gl.text.humanize(key)} ${label.message[key].join(', ')}`,
).join("<br/>"); ).join('<br/>');
} }
this.$newLabelError this.$newLabelError
...@@ -122,6 +122,3 @@ class CreateLabelDropdown { ...@@ -122,6 +122,3 @@ class CreateLabelDropdown {
}); });
} }
} }
window.gl = window.gl || {};
gl.CreateLabelDropdown = CreateLabelDropdown;
...@@ -76,6 +76,7 @@ import GpgBadges from './gpg_badges'; ...@@ -76,6 +76,7 @@ import GpgBadges from './gpg_badges';
import UserFeatureHelper from './helpers/user_feature_helper'; import UserFeatureHelper from './helpers/user_feature_helper';
import initChangesDropdown from './init_changes_dropdown'; import initChangesDropdown from './init_changes_dropdown';
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils'; import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
import AjaxLoadingSpinner from './ajax_loading_spinner';
(function() { (function() {
var Dispatcher; var Dispatcher;
...@@ -237,7 +238,7 @@ import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils'; ...@@ -237,7 +238,7 @@ import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
new NewBranchForm($('.js-create-branch-form'), JSON.parse(document.getElementById('availableRefs').innerHTML)); new NewBranchForm($('.js-create-branch-form'), JSON.parse(document.getElementById('availableRefs').innerHTML));
break; break;
case 'projects:branches:index': case 'projects:branches:index':
gl.AjaxLoadingSpinner.init(); AjaxLoadingSpinner.init();
new DeleteModal(); new DeleteModal();
break; break;
case 'projects:issues:new': case 'projects:issues:new':
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import _ from 'underscore'; import _ from 'underscore';
import IssuableBulkUpdateActions from './issuable_bulk_update_actions'; import IssuableBulkUpdateActions from './issuable_bulk_update_actions';
import DropdownUtils from './filtered_search/dropdown_utils'; import DropdownUtils from './filtered_search/dropdown_utils';
import CreateLabelDropdown from './create_label';
(function() { (function() {
this.LabelsSelect = (function() { this.LabelsSelect = (function() {
...@@ -61,7 +62,7 @@ import DropdownUtils from './filtered_search/dropdown_utils'; ...@@ -61,7 +62,7 @@ import DropdownUtils from './filtered_search/dropdown_utils';
$sidebarLabelTooltip.tooltip(); $sidebarLabelTooltip.tooltip();
if ($dropdown.closest('.dropdown').find('.dropdown-new-label').length) { if ($dropdown.closest('.dropdown').find('.dropdown-new-label').length) {
new gl.CreateLabelDropdown($dropdown.closest('.dropdown').find('.dropdown-new-label'), namespacePath, projectPath); new CreateLabelDropdown($dropdown.closest('.dropdown').find('.dropdown-new-label'), namespacePath, projectPath);
} }
saveLabelData = function() { saveLabelData = function() {
......
...@@ -57,7 +57,6 @@ import './u2f/util'; ...@@ -57,7 +57,6 @@ import './u2f/util';
import './abuse_reports'; import './abuse_reports';
import './activities'; import './activities';
import './admin'; import './admin';
import './ajax_loading_spinner';
import './api'; import './api';
import './aside'; import './aside';
import './autosave'; import './autosave';
...@@ -74,7 +73,6 @@ import './compare_autocomplete'; ...@@ -74,7 +73,6 @@ import './compare_autocomplete';
import './confirm_danger_modal'; import './confirm_danger_modal';
import './copy_as_gfm'; import './copy_as_gfm';
import './copy_to_clipboard'; import './copy_to_clipboard';
import './create_label';
import './diff'; import './diff';
import './dropzone_input'; import './dropzone_input';
import './due_date_select'; import './due_date_select';
......
import 'jquery'; import 'jquery';
import 'jquery-ujs'; import 'jquery-ujs';
import '~/ajax_loading_spinner'; import AjaxLoadingSpinner from '~/ajax_loading_spinner';
describe('Ajax Loading Spinner', () => { describe('Ajax Loading Spinner', () => {
const fixtureTemplate = 'static/ajax_loading_spinner.html.raw'; const fixtureTemplate = 'static/ajax_loading_spinner.html.raw';
...@@ -8,7 +8,7 @@ describe('Ajax Loading Spinner', () => { ...@@ -8,7 +8,7 @@ describe('Ajax Loading Spinner', () => {
beforeEach(() => { beforeEach(() => {
loadFixtures(fixtureTemplate); loadFixtures(fixtureTemplate);
gl.AjaxLoadingSpinner.init(); AjaxLoadingSpinner.init();
}); });
it('change current icon with spinner icon and disable link while waiting ajax response', (done) => { it('change current icon with spinner icon and disable link while waiting ajax response', (done) => {
......
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