From: Alexander Ebert Date: Sun, 21 Feb 2021 11:20:48 +0000 (+0100) Subject: Clear a dialog callback on runtime X-Git-Tag: 5.4.0_Alpha_1~250 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=293f92978ff273e62a8371288c6ab17352116496;p=GitHub%2FWoltLab%2FWCF.git Clear a dialog callback on runtime See #3932 --- diff --git a/ts/WoltLabSuite/Core/Acp/Ui/Worker.ts b/ts/WoltLabSuite/Core/Acp/Ui/Worker.ts index 43f425d6d1..55c1d1f651 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/Worker.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/Worker.ts @@ -100,7 +100,7 @@ class AcpUiWorker implements AjaxCallbackObject, DialogCallbackObject { parameters: data.parameters, }); } else { - UiDialog.setCallback(this, "onClose", () => {}); + UiDialog.removeCallback(this, "onClose"); const spinner = content.querySelector(".fa-spinner") as HTMLSpanElement; spinner.classList.remove("fa-spinner"); diff --git a/ts/WoltLabSuite/Core/Ui/Dialog.ts b/ts/WoltLabSuite/Core/Ui/Dialog.ts index d09f55f71c..2541f196d5 100644 --- a/ts/WoltLabSuite/Core/Ui/Dialog.ts +++ b/ts/WoltLabSuite/Core/Ui/Dialog.ts @@ -332,6 +332,29 @@ const UiDialog = { data[key] = value; }, + /** + * Clears a callback function on runtime. + */ + removeCallback(id: ElementIdOrCallbackObject, key: string): void { + if (typeof id === "object") { + const dialogData = _dialogObjects.get(id); + if (dialogData !== undefined) { + id = dialogData.id; + } + } + + const data = _dialogs.get(id as string); + if (data === undefined) { + throw new Error(`Expected a valid dialog id, '${id as string}' does not match any active dialog.`); + } + + if (_validCallbacks.indexOf(key) === -1) { + throw new Error("Invalid callback identifier, '" + key + "' is not recognized."); + } + + data[key] = undefined; + }, + /** * Creates the DOM for a new dialog and opens it. */ diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Worker.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Worker.js index 7868d55ea6..561718e469 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Worker.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Worker.js @@ -57,7 +57,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Langua }); } else { - Dialog_1.default.setCallback(this, "onClose", () => { }); + Dialog_1.default.removeCallback(this, "onClose"); const spinner = content.querySelector(".fa-spinner"); spinner.classList.remove("fa-spinner"); spinner.classList.add("fa-check", "green"); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js index 5ed9e232f6..be131e6595 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js @@ -275,6 +275,25 @@ define(["require", "exports", "tslib", "../Core", "../Dom/Change/Listener", "./S } data[key] = value; }, + /** + * Clears a callback function on runtime. + */ + removeCallback(id, key) { + if (typeof id === "object") { + const dialogData = _dialogObjects.get(id); + if (dialogData !== undefined) { + id = dialogData.id; + } + } + const data = _dialogs.get(id); + if (data === undefined) { + throw new Error(`Expected a valid dialog id, '${id}' does not match any active dialog.`); + } + if (_validCallbacks.indexOf(key) === -1) { + throw new Error("Invalid callback identifier, '" + key + "' is not recognized."); + } + data[key] = undefined; + }, /** * Creates the DOM for a new dialog and opens it. */