/**
* Contact Forms - Deactivation Modal
*
* Intercepts the plugin "Deactivate" link on the Plugins page and shows
* a modal asking the user what to do with existing data.
*
* @package ContactForms
* @since 2.0.0-beta.70
*/
(function ($) {
'use strict';
var settings = accuaFormsDeactivation;
var deactivateUrl = '';
function createModal() {
var modalHtml =
'
' +
'
' +
'
' +
'
' + settings.i18n.title + '
' +
'
' + settings.i18n.description + '
' +
'
' +
'
' +
'' +
'' +
'' +
'
' +
'' +
'
' +
'
';
var modalCss =
'';
$('body').append(modalCss + modalHtml);
}
function showModal() {
$('#accua-deactivation-overlay').fadeIn(200);
}
function hideModal() {
$('#accua-deactivation-overlay').fadeOut(200);
}
function init() {
var $deactivateLink = $('tr[data-plugin="' + settings.pluginBasename + '"] .deactivate a');
if (!$deactivateLink.length) {
return;
}
createModal();
// Intercept the Deactivate click
$deactivateLink.on('click', function (e) {
e.preventDefault();
deactivateUrl = $(this).attr('href');
showModal();
});
// Cancel
$('#accua-deact-cancel').on('click', hideModal);
$('#accua-deactivation-overlay').on('click', function (e) {
if (e.target === this) {
hideModal();
}
});
// Option buttons
$('.accua-deact-option').on('click', function () {
var mode = $(this).data('mode');
var $allOptions = $('.accua-deact-option');
var $cancelBtn = $('#accua-deact-cancel');
var $clicked = $(this);
// "Skip" - just deactivate, no AJAX
if (mode === 'skip') {
window.location.href = deactivateUrl;
return;
}
// Extra confirmation for anonymize
if (mode === 'anonymize') {
if (!confirm(settings.i18n.confirmAnonymize)) {
return;
}
}
// Extra confirmation for delete
if (mode === 'delete') {
if (!confirm(settings.i18n.confirmDelete)) {
return;
}
}
// Disable all buttons and show processing state
$allOptions.prop('disabled', true);
$cancelBtn.prop('disabled', true);
$clicked.find('.accua-deact-option__label').text(settings.i18n.processing);
$.ajax({
url: settings.ajaxUrl,
type: 'POST',
data: {
action: 'accua_forms_deactivation_cleanup',
nonce: settings.nonce,
mode: mode
},
success: function () {
window.location.href = deactivateUrl;
},
error: function () {
// Proceed with deactivation even if cleanup fails
window.location.href = deactivateUrl;
}
});
});
}
$(document).ready(init);
})(jQuery);