Commit bba6676c authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'fix-confirm-danger-modal' into 'master'

Refactor ConfirmDangerModal into ES module

See merge request gitlab-org/gitlab-ce!17874
parents a9a31ce3 1fff345e
/* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, camelcase, one-var-declaration-per-line, no-else-return, max-len */
import $ from 'jquery'; import $ from 'jquery';
import { rstrip } from './lib/utils/common_utils'; import { rstrip } from './lib/utils/common_utils';
window.ConfirmDangerModal = (function() { function openConfirmDangerModal($form, text) {
function ConfirmDangerModal(form, text) { $('.js-confirm-text').text(text || '');
var project_path, submit; $('.js-confirm-danger-input').val('');
this.form = form; $('#modal-confirm-danger').modal('show');
$('.js-confirm-text').text(text || '');
$('.js-confirm-danger-input').val(''); const confirmTextMatch = $('.js-confirm-danger-match').text();
$('#modal-confirm-danger').modal('show'); const $submit = $('.js-confirm-danger-submit');
project_path = $('.js-confirm-danger-match').text(); $submit.disable();
submit = $('.js-confirm-danger-submit');
submit.disable(); $('.js-confirm-danger-input').off('input').on('input', function handleInput() {
$('.js-confirm-danger-input').off('input'); const confirmText = rstrip($(this).val());
$('.js-confirm-danger-input').on('input', function() { if (confirmText === confirmTextMatch) {
if (rstrip($(this).val()) === project_path) { $submit.enable();
return submit.enable(); } else {
} else { $submit.disable();
return submit.disable(); }
} });
}); $('.js-confirm-danger-submit').off('click').on('click', () => $form.submit());
$('.js-confirm-danger-submit').off('click'); }
$('.js-confirm-danger-submit').on('click', (function(_this) {
return function() {
return _this.form.submit();
};
})(this));
}
return ConfirmDangerModal; export default function initConfirmDangerModal() {
})(); $(document).on('click', '.js-confirm-danger', (e) => {
e.preventDefault();
const $btn = $(e.target);
const $form = $btn.closest('form');
const text = $btn.data('confirmDangerMessage');
openConfirmDangerModal($form, text);
});
}
/* eslint-disable import/first */ /* eslint-disable import/first */
/* global ConfirmDangerModal */
/* global $ */ /* global $ */
import jQuery from 'jquery'; import jQuery from 'jquery';
...@@ -21,7 +20,6 @@ import './behaviors/'; ...@@ -21,7 +20,6 @@ import './behaviors/';
// everything else // everything else
import loadAwardsHandler from './awards_handler'; import loadAwardsHandler from './awards_handler';
import bp from './breakpoints'; import bp from './breakpoints';
import './confirm_danger_modal';
import Flash, { removeFlashClickListener } from './flash'; import Flash, { removeFlashClickListener } from './flash';
import './gl_dropdown'; import './gl_dropdown';
import initTodoToggle from './header'; import initTodoToggle from './header';
...@@ -214,16 +212,6 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -214,16 +212,6 @@ document.addEventListener('DOMContentLoaded', () => {
$(document).trigger('toggle.comments'); $(document).trigger('toggle.comments');
}); });
$document.on('click', '.js-confirm-danger', (e) => {
const btn = $(e.target);
const form = btn.closest('form');
const text = btn.data('confirmDangerMessage');
e.preventDefault();
// eslint-disable-next-line no-new
new ConfirmDangerModal(form, text);
});
$document.on('breakpoint:change', (e, breakpoint) => { $document.on('breakpoint:change', (e, breakpoint) => {
if (breakpoint === 'sm' || breakpoint === 'xs') { if (breakpoint === 'sm' || breakpoint === 'xs') {
const $gutterIcon = $sidebarGutterToggle.find('i'); const $gutterIcon = $sidebarGutterToggle.find('i');
......
import groupAvatar from '~/group_avatar'; import groupAvatar from '~/group_avatar';
import TransferDropdown from '~/groups/transfer_dropdown'; import TransferDropdown from '~/groups/transfer_dropdown';
import initConfirmDangerModal from '~/confirm_danger_modal';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
groupAvatar(); groupAvatar();
new TransferDropdown(); // eslint-disable-line no-new new TransferDropdown(); // eslint-disable-line no-new
initConfirmDangerModal();
}); });
import initSettingsPanels from '~/settings_panels'; import initSettingsPanels from '~/settings_panels';
import setupProjectEdit from '~/project_edit'; import setupProjectEdit from '~/project_edit';
import initConfirmDangerModal from '~/confirm_danger_modal';
import ProjectNew from '../shared/project_new'; import ProjectNew from '../shared/project_new';
import projectAvatar from '../shared/project_avatar'; import projectAvatar from '../shared/project_avatar';
import initProjectPermissionsSettings from '../shared/permissions'; import initProjectPermissionsSettings from '../shared/permissions';
...@@ -11,4 +12,5 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -11,4 +12,5 @@ document.addEventListener('DOMContentLoaded', () => {
initSettingsPanels(); initSettingsPanels();
projectAvatar(); projectAvatar();
initProjectPermissionsSettings(); initProjectPermissionsSettings();
initConfirmDangerModal();
}); });
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