debian-mirror-gitlab/app/assets/javascripts/confirm_danger_modal.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import { rstrip } from './lib/utils/common_utils';
2016-09-13 17:45:13 +05:30
2018-05-09 12:01:36 +05:30
function openConfirmDangerModal($form, text) {
2018-11-18 11:00:15 +05:30
const $input = $('.js-confirm-danger-input');
$input.val('');
2018-05-09 12:01:36 +05:30
$('.js-confirm-text').text(text || '');
$('#modal-confirm-danger').modal('show');
2016-09-13 17:45:13 +05:30
2018-05-09 12:01:36 +05:30
const confirmTextMatch = $('.js-confirm-danger-match').text();
const $submit = $('.js-confirm-danger-submit');
$submit.disable();
2018-11-18 11:00:15 +05:30
$input.focus();
2018-05-09 12:01:36 +05:30
2018-12-13 13:39:08 +05:30
$('.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-05-09 12:01:36 +05:30
}
export default function initConfirmDangerModal() {
2018-12-13 13:39:08 +05:30
$(document).on('click', '.js-confirm-danger', e => {
2018-05-09 12:01:36 +05:30
e.preventDefault();
const $btn = $(e.target);
const $form = $btn.closest('form');
const text = $btn.data('confirmDangerMessage');
openConfirmDangerModal($form, text);
});
}