From e4da9285d0d840eec2304b1b8cc76541d184cc37 Mon Sep 17 00:00:00 2001 From: DianaXWiki <139217939+DianaXWiki@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:40:44 +0300 Subject: [PATCH] Implement review fixes - change modal constructor and add translation keys --- customize.dist/messages.js | 3 +- www/admin/inner.js | 89 +++++++++++--------------------------- 2 files changed, 27 insertions(+), 65 deletions(-) diff --git a/customize.dist/messages.js b/customize.dist/messages.js index 2459a246f..0e748c98e 100755 --- a/customize.dist/messages.js +++ b/customize.dist/messages.js @@ -133,7 +133,8 @@ define(req, function(AppConfig, Default, Language) { return text; } }; - + Messages.admin_mfa_confirm_enable = "Are you sure you want to enable Multi-Factor Authentication?"; // XXX + Messages.admin_mfa_confirm_disable = "Are you sure you want to disable Multi-Factor Authentication?"; // XXX return Messages; }); diff --git a/www/admin/inner.js b/www/admin/inner.js index 5ae30471a..0d66c52c1 100644 --- a/www/admin/inner.js +++ b/www/admin/inner.js @@ -579,71 +579,32 @@ define([ }, query: function (val, setState) { var isChecked = APP.instanceStatus.enforceMFA; - var confirmationContent = isChecked - ? 'Are you sure you want to disable enforced MFA? This action would lessen the security of your account.' - : 'Are you sure you want to enforce MFA? This action would require to set up an authenticator app.'; - - function showConfirmationModal(callback) { - var modal = UI.dialog.customModal(confirmationContent, { - buttons: [{ - className: 'cancel', - name: Messages.cancel, - onClick: function () { - if (!isChecked) { - sFrameChan.query('Q_ADMIN_RPC', { - cmd: 'ADMIN_DECREE', - data: ['ENFORCE_MFA', [false]] - }, function (e, response) { - if (e || response.error) { - UI.warn(Messages.error); - console.error(e, response); - } else { - APP.updateStatus(function () { - setState(false); - flushCache(); - }); - } - }); - } - //check the checkbox again - else { - APP.updateStatus(function () { - setState(APP.instanceStatus.enforceMFA); - flushCache(); - }); - } - }, - keys: [27] // Esc key to close modal - }, { - className: 'primary', - name: Messages.settings_save, - onClick: function () { - sFrameChan.query('Q_ADMIN_RPC', { - cmd: 'ADMIN_DECREE', - data: ['ENFORCE_MFA', [val]] - }, function (e, response) { - if (e || response.error) { - UI.warn(Messages.error); - console.error(e, response); - } else { - APP.updateStatus(function () { - setState(APP.instanceStatus.enforceMFA); - flushCache(); - }); - } - }); - }, - keys: [13] // Enter key to confirm - }] + function showConfirmation(isChecked, setState) { + const confirmationContent = isChecked ? Messages.admin_mfa_confirm_disable : Messages.admin_mfa_confirm_enable; + UI.confirm(confirmationContent, function (confirmed) { + if (!confirmed) { + // User canceled their changes, restore the checkbox value + setState(isChecked); + return; + } + // User confirmed their changes, call the command and update the state + sFrameChan.query('Q_ADMIN_RPC', { + cmd: 'ADMIN_DECREE', + data: ['ENFORCE_MFA', [val]] + }, function (e, response) { + if (e || response.error) { + UI.warn(Messages.error); + console.error(e, response); + } else { + APP.updateStatus(function () { + setState(APP.instanceStatus.enforceMFA); + flushCache(); + }); + } }); - var $modal = $(modal); - UI.openCustomModal(modal); - $modal.closest('.alertify').on('mousedown', function (e) { - e.stopPropagation(); - }); - } - - showConfirmationModal(); + }); + } + showConfirmation(isChecked, setState); } });