Merge branch 'fix-confirm-danger-modal' into 'master'
Refactor ConfirmDangerModal into ES module See merge request gitlab-org/gitlab-ce!17874
This commit is contained in:
commit
bba6676cca
4 changed files with 32 additions and 41 deletions
|
@ -1,33 +1,32 @@
|
|||
/* 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 { rstrip } from './lib/utils/common_utils';
|
||||
|
||||
window.ConfirmDangerModal = (function() {
|
||||
function ConfirmDangerModal(form, text) {
|
||||
var project_path, submit;
|
||||
this.form = form;
|
||||
$('.js-confirm-text').text(text || '');
|
||||
$('.js-confirm-danger-input').val('');
|
||||
$('#modal-confirm-danger').modal('show');
|
||||
project_path = $('.js-confirm-danger-match').text();
|
||||
submit = $('.js-confirm-danger-submit');
|
||||
submit.disable();
|
||||
$('.js-confirm-danger-input').off('input');
|
||||
$('.js-confirm-danger-input').on('input', function() {
|
||||
if (rstrip($(this).val()) === project_path) {
|
||||
return submit.enable();
|
||||
} else {
|
||||
return submit.disable();
|
||||
}
|
||||
});
|
||||
$('.js-confirm-danger-submit').off('click');
|
||||
$('.js-confirm-danger-submit').on('click', (function(_this) {
|
||||
return function() {
|
||||
return _this.form.submit();
|
||||
};
|
||||
})(this));
|
||||
}
|
||||
function openConfirmDangerModal($form, text) {
|
||||
$('.js-confirm-text').text(text || '');
|
||||
$('.js-confirm-danger-input').val('');
|
||||
$('#modal-confirm-danger').modal('show');
|
||||
|
||||
return ConfirmDangerModal;
|
||||
})();
|
||||
const confirmTextMatch = $('.js-confirm-danger-match').text();
|
||||
const $submit = $('.js-confirm-danger-submit');
|
||||
$submit.disable();
|
||||
|
||||
$('.js-confirm-danger-input').off('input').on('input', function handleInput() {
|
||||
const confirmText = rstrip($(this).val());
|
||||
if (confirmText === confirmTextMatch) {
|
||||
$submit.enable();
|
||||
} else {
|
||||
$submit.disable();
|
||||
}
|
||||
});
|
||||
$('.js-confirm-danger-submit').off('click').on('click', () => $form.submit());
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
/* eslint-disable import/first */
|
||||
/* global ConfirmDangerModal */
|
||||
/* global $ */
|
||||
|
||||
import jQuery from 'jquery';
|
||||
|
@ -21,7 +20,6 @@ import './behaviors/';
|
|||
// everything else
|
||||
import loadAwardsHandler from './awards_handler';
|
||||
import bp from './breakpoints';
|
||||
import './confirm_danger_modal';
|
||||
import Flash, { removeFlashClickListener } from './flash';
|
||||
import './gl_dropdown';
|
||||
import initTodoToggle from './header';
|
||||
|
@ -214,16 +212,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
$(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) => {
|
||||
if (breakpoint === 'sm' || breakpoint === 'xs') {
|
||||
const $gutterIcon = $sidebarGutterToggle.find('i');
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import groupAvatar from '~/group_avatar';
|
||||
import TransferDropdown from '~/groups/transfer_dropdown';
|
||||
import initConfirmDangerModal from '~/confirm_danger_modal';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
groupAvatar();
|
||||
new TransferDropdown(); // eslint-disable-line no-new
|
||||
initConfirmDangerModal();
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import initSettingsPanels from '~/settings_panels';
|
||||
import setupProjectEdit from '~/project_edit';
|
||||
import initConfirmDangerModal from '~/confirm_danger_modal';
|
||||
import ProjectNew from '../shared/project_new';
|
||||
import projectAvatar from '../shared/project_avatar';
|
||||
import initProjectPermissionsSettings from '../shared/permissions';
|
||||
|
@ -11,4 +12,5 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
initSettingsPanels();
|
||||
projectAvatar();
|
||||
initProjectPermissionsSettings();
|
||||
initConfirmDangerModal();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue