From 835354e55da5151fbfc4e48322e26f2250486f08 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 21 Nov 2017 12:48:43 +0100 Subject: [PATCH] Improved rebuild data UI/UX Actions no longer force a page reload with the exception to the database encoding conversion after an import. Successfully completed actions will now display a notice adjacent to the button, making it easier to tell already executed actions apart. --- wcfsetup/install/files/acp/js/WCF.ACP.js | 120 ++------------- .../files/acp/templates/rebuildData.tpl | 55 +++++-- .../js/WoltLabSuite/Core/Acp/Ui/Worker.js | 143 ++++++++++++++++++ wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 5 files changed, 201 insertions(+), 119 deletions(-) create mode 100644 wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Worker.js diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index a5760d3ff6..7cca145c9a 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -1567,44 +1567,10 @@ WCF.ACP.PluginStore.PurchasedItems.Search = Class.extend({ * @param string title * @param object parameters * @param object callback + * + * @deprecated 3.1 - please use `WoltLabSuite/Core/Acp/Ui/Worker` instead */ WCF.ACP.Worker = Class.extend({ - /** - * worker aborted - * @var boolean - */ - _aborted: false, - - /** - * callback invoked after worker completed - * @var object - */ - _callback: null, - - /** - * dialog id - * @var string - */ - _dialogID: null, - - /** - * dialog object - * @var jQuery - */ - _dialog: null, - - /** - * action proxy - * @var WCF.Action.Proxy - */ - _proxy: null, - - /** - * dialog title - * @var string - */ - _title: '', - /** * Initializes a new worker instance. * @@ -1613,81 +1579,23 @@ WCF.ACP.Worker = Class.extend({ * @param string title * @param object parameters * @param object callback - * @param object confirmMessage */ init: function(dialogID, className, title, parameters, callback) { - this._aborted = false; - this._callback = callback || null; - this._dialogID = dialogID + 'Worker'; - this._dialog = null; - this._proxy = new WCF.Action.Proxy({ - autoSend: true, - data: { - className: className, - parameters: parameters || { } - }, - showLoadingOverlay: false, - success: $.proxy(this._success, this), - url: 'index.php?worker-proxy/&t=' + SECURITY_TOKEN - }); - this._title = title; - }, - - /** - * Handles response from server. - * - * @param object data - */ - _success: function(data) { - // init binding - if (this._dialog === null) { - this._dialog = $('
').hide().appendTo(document.body); - this._dialog.wcfDialog({ - closeConfirmMessage: WCF.Language.get('wcf.acp.worker.abort.confirmMessage'), - closeViaModal: false, - onClose: $.proxy(function() { - this._aborted = true; - this._proxy.abortPrevious(); - - window.location.reload(); - }, this), - title: this._title - }); - } - - if (this._aborted) { - return; + if (typeof callback === 'function') { + throw new Error("The callback parameter is no longer supported, please migrate to 'WoltLabSuite/Core/Acp/Ui/Worker'."); } - if (data.template) { - this._dialog.html(data.template); - } - - // update progress - this._dialog.find('progress').attr('value', data.progress).text(data.progress + '%').next('span').text(data.progress + '%'); - - // worker is still busy with its business, carry on - if (data.progress < 100) { - // send request for next loop - this._proxy.setOption('data', { - className: data.className, - loopCount: data.loopCount, - parameters: data.parameters + require(['WoltLabSuite/Core/Acp/Ui/Worker'], function(AcpUiWorker) { + new AcpUiWorker({ + // dialog + dialogId: dialogID, + dialogTitle: title, + + // ajax + className: className, + parameters: parameters }); - this._proxy.sendRequest(); - } - else if (this._callback !== null) { - this._callback(this, data); - } - else { - this._dialog.find('.fa-spinner').removeClass('fa-spinner').addClass('fa-check'); - - // display continue button - var $formSubmit = $('
').appendTo(this._dialog); - $('').appendTo($formSubmit).focus().click(function() { window.location = data.proceedURL; }); - - this._dialog.wcfDialog('render'); - } + }); } }); diff --git a/wcfsetup/install/files/acp/templates/rebuildData.tpl b/wcfsetup/install/files/acp/templates/rebuildData.tpl index fc50f88e75..61a92ee3ca 100644 --- a/wcfsetup/install/files/acp/templates/rebuildData.tpl +++ b/wcfsetup/install/files/acp/templates/rebuildData.tpl @@ -1,9 +1,45 @@ {include file='header' pageTitle='wcf.acp.rebuildData'}
@@ -38,18 +74,11 @@
- {lang}wcf.acp.rebuildData.{@$objectType->objectType}{/lang} + {lang}wcf.acp.rebuildData.{@$objectType->objectType}{/lang} {lang}wcf.acp.rebuildData.{@$objectType->objectType}.description{/lang} - - {if $_allowRebuild} - - {/if}
{/foreach} diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Worker.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Worker.js new file mode 100644 index 0000000000..1a54ba24bd --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Worker.js @@ -0,0 +1,143 @@ +/** + * Worker manager with support for custom callbacks and loop counts. + * + * @author Alexander Ebert + * @copyright 2001-2017 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/Worker + */ +define(['Ajax', 'Core', 'Language', 'Ui/Dialog'], function(Ajax, Core, Language, UiDialog) { + "use strict"; + + /** + * Creates a new worker instance. + * + * @param {Object} options configuration options + * @constructor + */ + function AcpUiWorker(options) { this.init(options); } + AcpUiWorker.prototype = { + /** + * Creates a new worker instance. + * + * @param {Object} options configuration options + */ + init: function (options) { + this._aborted = false; + this._options = Core.extend({ + // dialog + dialogId: '', + dialogTitle: '', + + // ajax + className: '', + loopCount: -1, + parameters: {}, + + // callbacks + callbackAbort: null, + callbackFailure: null, + callbackSuccess: null + }, options); + this._options.dialogId += 'Worker'; + + this._request = Ajax.api(this); + }, + + _ajaxSuccess: function (data) { + if (this._aborted) return; + + if (typeof data.template === 'string') { + UiDialog.open(this, data.template); + } + + var content = UiDialog.getDialog(this).content; + + // update progress + var progress = elBySel('progress', content); + progress.value = data.progress; + progress.nextElementSibling.textContent = data.progress + '%'; + + // worker is still busy + if (data.progress < 100) { + Ajax.api(this, { + loopCount: data.loopCount, + parameters: data.parameters + }); + } + else { + var spinner = elBySel('.fa-spinner', content); + spinner.classList.remove('fa-spinner'); + spinner.classList.add('fa-check'); + spinner.classList.add('green'); + + var formSubmit = elCreate('div'); + formSubmit.className = 'formSubmit'; + formSubmit.innerHTML = ''; + + content.appendChild(formSubmit); + UiDialog.rebuild(this); + + var button = formSubmit.children[0]; + button.addEventListener(WCF_CLICK_EVENT, (function(event) { + event.preventDefault(); + + if (typeof this._options.callbackSuccess === 'function') { + this._options.callbackSuccess(data); + + UiDialog.close(this); + } + else { + window.location = data.proceedURL; + } + }).bind(this)); + } + }, + + _ajaxFailure: function () { + var dialog = UiDialog.getDialog(this); + if (dialog !== null) { + var spinner = elBySel('.fa-spinner', dialog.content); + spinner.classList.remove('fa-spinner'); + spinner.classList.add('fa-times'); + spinner.classList.add('red'); + } + }, + + _ajaxSetup: function () { + return { + data: { + className: this._options.className, + loopCount: this._options.loopCount, + parameters: this._options.parameters + }, + silent: true, + url: 'index.php?worker-proxy/&t=' + SECURITY_TOKEN + }; + }, + + _dialogSetup: function () { + return { + id: this._options.dialogId, + onClose: (function () { + this._aborted = true; + this._request.abortPrevious(); + + if (typeof this._options.callbackAbort === 'function') { + this._options.callbackAbort(); + } + else { + window.location.reload(); + } + }).bind(this), + options: { + backdropCloseOnClick: false, + title: this._options.dialogTitle + }, + source: null + } + } + }; + + return AcpUiWorker; +}); diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index e81a1b5150..60493870b2 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2268,6 +2268,7 @@ Benutzerkontos nun in vollem Umfang nutzen.]]> + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index d8aa440713..11c926ee44 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2204,6 +2204,7 @@ full extend.]]> + -- 2.20.1