Commit 43ff14e0 authored by Mike Greiling's avatar Mike Greiling

refactor ConfirmDangerModal into ES module

parent 5f675418
/* 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;
export default function initConfirmDangerModal($form, text) {
$('.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();
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 {
return submit.disable();
$submit.disable();
}
});
$('.js-confirm-danger-submit').off('click');
$('.js-confirm-danger-submit').on('click', (function(_this) {
return function() {
return _this.form.submit();
};
})(this));
}
return ConfirmDangerModal;
})();
$('.js-confirm-danger-submit').off('click').on('click', () => $form.submit());
}
/* eslint-disable import/first */
/* global ConfirmDangerModal */
/* global $ */
import jQuery from 'jquery';
......@@ -21,7 +20,7 @@ import './behaviors/';
// everything else
import loadAwardsHandler from './awards_handler';
import bp from './breakpoints';
import './confirm_danger_modal';
import initConfirmDangerModal from './confirm_danger_modal';
import Flash, { removeFlashClickListener } from './flash';
import './gl_dropdown';
import initTodoToggle from './header';
......@@ -215,13 +214,11 @@ document.addEventListener('DOMContentLoaded', () => {
});
$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);
const $btn = $(e.target);
const $form = $btn.closest('form');
const text = $btn.data('confirmDangerMessage');
initConfirmDangerModal($form, text);
});
$document.on('breakpoint:change', (e, breakpoint) => {
......
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