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 $ from 'jquery';
import { rstrip } from './lib/utils/common_utils'; import { rstrip } from './lib/utils/common_utils';
window.ConfirmDangerModal = (function() { export default function initConfirmDangerModal($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');
$('.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));
}
return ConfirmDangerModal; $('.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());
}
/* eslint-disable import/first */ /* eslint-disable import/first */
/* global ConfirmDangerModal */
/* global $ */ /* global $ */
import jQuery from 'jquery'; import jQuery from 'jquery';
...@@ -21,7 +20,7 @@ import './behaviors/'; ...@@ -21,7 +20,7 @@ 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 initConfirmDangerModal from './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';
...@@ -215,13 +214,11 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -215,13 +214,11 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
$document.on('click', '.js-confirm-danger', (e) => { $document.on('click', '.js-confirm-danger', (e) => {
const btn = $(e.target);
const form = btn.closest('form');
const text = btn.data('confirmDangerMessage');
e.preventDefault(); e.preventDefault();
const $btn = $(e.target);
// eslint-disable-next-line no-new const $form = $btn.closest('form');
new ConfirmDangerModal(form, text); const text = $btn.data('confirmDangerMessage');
initConfirmDangerModal($form, text);
}); });
$document.on('breakpoint:change', (e, breakpoint) => { $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