2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-09-06 04:01:01 -04:00
|
|
|
import { rstrip } from './lib/utils/common_utils';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2018-03-20 11:50:26 -04:00
|
|
|
function openConfirmDangerModal($form, text) {
|
2018-07-06 10:14:31 -04:00
|
|
|
const $input = $('.js-confirm-danger-input');
|
|
|
|
$input.val('');
|
|
|
|
|
2018-03-20 01:37:16 -04:00
|
|
|
$('.js-confirm-text').text(text || '');
|
|
|
|
$('#modal-confirm-danger').modal('show');
|
|
|
|
|
|
|
|
const confirmTextMatch = $('.js-confirm-danger-match').text();
|
|
|
|
const $submit = $('.js-confirm-danger-submit');
|
|
|
|
$submit.disable();
|
2018-07-06 10:14:31 -04:00
|
|
|
$input.focus();
|
2017-03-11 02:30:44 -05:00
|
|
|
|
2018-10-24 15:17:03 -04:00
|
|
|
$('.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());
|
2018-03-20 01:37:16 -04:00
|
|
|
}
|
2018-03-20 11:50:26 -04:00
|
|
|
|
|
|
|
export default function initConfirmDangerModal() {
|
2018-10-24 15:17:03 -04:00
|
|
|
$(document).on('click', '.js-confirm-danger', e => {
|
2018-03-20 11:50:26 -04:00
|
|
|
e.preventDefault();
|
|
|
|
const $btn = $(e.target);
|
|
|
|
const $form = $btn.closest('form');
|
|
|
|
const text = $btn.data('confirmDangerMessage');
|
|
|
|
openConfirmDangerModal($form, text);
|
|
|
|
});
|
|
|
|
}
|