From 8735fafe0ddfd3b1e7d9b8c3062585a3ea0f7bfc Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 4 May 2021 14:39:37 +0200 Subject: [PATCH] Restrict registration UI --- www/admin/inner.js | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/www/admin/inner.js b/www/admin/inner.js index 332ff1fe3..d0ee5412e 100644 --- a/www/admin/inner.js +++ b/www/admin/inner.js @@ -253,36 +253,32 @@ define([ create['registration'] = function () { var key = 'registration'; - var $div = makeBlock(key, true); // Msg.admin_registrationHint, .admin_registrationTitle, .admin_registrationButton - var $button = $div.find('button'); + var $div = makeBlock(key); // Msg.admin_registrationHint, .admin_registrationTitle, .admin_registrationButton + var state = APP.instanceStatus.restrictRegistration; - if (state) { - $button.text(Messages.admin_registrationAllow); - } else { - $button.removeClass('btn-primary').addClass('btn-danger'); - } - var called = false; - $div.find('button').click(function () { - called = true; + var $cbox = $(UI.createCheckbox('cp-settings-userfeedback', + Messages.admin_registrationTitle, + state, { label: { class: 'noTitle' } })); + var spinner = UI.makeSpinner($cbox); + var $checkbox = $cbox.find('input').on('change', function() { + spinner.spin(); + var val = $checkbox.is(':checked') || false; + $checkbox.attr('disabled', 'disabled'); sFrameChan.query('Q_ADMIN_RPC', { cmd: 'ADMIN_DECREE', - data: ['RESTRICT_REGISTRATION', [!state]] + data: ['RESTRICT_REGISTRATION', [val]] }, function (e) { if (e) { UI.warn(Messages.error); console.error(e); } APP.updateStatus(function () { - called = false; + spinner.done(); state = APP.instanceStatus.restrictRegistration; - if (state) { - console.log($button); - $button.text(Messages.admin_registrationAllow); - $button.addClass('btn-primary').removeClass('btn-danger'); - } else { - $button.text(Messages.admin_registrationButton); - $button.removeClass('btn-primary').addClass('btn-danger'); - } + $checkbox[0].checked = state; + $checkbox.removeAttr('disabled'); }); }); }); + $cbox.appendTo($div); + return $div; };