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) {
var project_path, submit;
this.form = form;
$('.js-confirm-text').text(text || ''); $('.js-confirm-text').text(text || '');
$('.js-confirm-danger-input').val(''); $('.js-confirm-danger-input').val('');
$('#modal-confirm-danger').modal('show'); $('#modal-confirm-danger').modal('show');
project_path = $('.js-confirm-danger-match').text();
submit = $('.js-confirm-danger-submit'); const confirmTextMatch = $('.js-confirm-danger-match').text();
submit.disable(); const $submit = $('.js-confirm-danger-submit');
$('.js-confirm-danger-input').off('input'); $submit.disable();
$('.js-confirm-danger-input').on('input', function() {
if (rstrip($(this).val()) === project_path) { $('.js-confirm-danger-input').off('input').on('input', function handleInput() {
return submit.enable(); const confirmText = rstrip($(this).val());
if (confirmText === confirmTextMatch) {
$submit.enable();
} else { } else {
return submit.disable(); $submit.disable();
} }
}); });
$('.js-confirm-danger-submit').off('click'); $('.js-confirm-danger-submit').off('click').on('click', () => $form.submit());
$('.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