From 439740f89896f42d56c9d02c3d28661a46c0108f Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 8 Apr 2025 17:22:30 +0200 Subject: [PATCH] Add generic disable interaction with confirmation --- .../Core/Component/Confirmation.ts | 18 ++++++++++++ .../Component/Interaction/Confirmation.ts | 7 +++++ .../Core/Component/Confirmation.js | 15 ++++++++++ .../Component/Interaction/Confirmation.js | 6 ++++ ...PreloadPhrasesCollectingListener.class.php | 2 ++ .../interaction/DisableInteraction.class.php | 28 +++++++++++++++++++ .../InteractionConfirmationType.class.php | 2 ++ wcfsetup/install/lang/de.xml | 2 ++ wcfsetup/install/lang/en.xml | 2 ++ 9 files changed, 82 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/interaction/DisableInteraction.class.php diff --git a/ts/WoltLabSuite/Core/Component/Confirmation.ts b/ts/WoltLabSuite/Core/Component/Confirmation.ts index 976b24158c0..968acc50cfd 100644 --- a/ts/WoltLabSuite/Core/Component/Confirmation.ts +++ b/ts/WoltLabSuite/Core/Component/Confirmation.ts @@ -62,6 +62,24 @@ class ConfirmationPrefab { }); } + async disable(title?: string): Promise { + const dialog = dialogFactory().withoutContent().asConfirmation(); + + let question: string; + if (title === undefined) { + question = getPhrase("wcf.dialog.confirmation.disable.indeterminate"); + } else { + question = getPhrase("wcf.dialog.confirmation.disable", { title }); + } + + dialog.show(question); + + return new Promise((resolve) => { + dialog.addEventListener("primary", () => resolve(true)); + dialog.addEventListener("cancel", () => resolve(false)); + }); + } + async restore(title?: string): Promise { const dialog = dialogFactory().withoutContent().asConfirmation(); diff --git a/ts/WoltLabSuite/Core/Component/Interaction/Confirmation.ts b/ts/WoltLabSuite/Core/Component/Interaction/Confirmation.ts index 8b127cb98df..cedc650d658 100644 --- a/ts/WoltLabSuite/Core/Component/Interaction/Confirmation.ts +++ b/ts/WoltLabSuite/Core/Component/Interaction/Confirmation.ts @@ -15,6 +15,7 @@ export enum ConfirmationType { SoftDeleteWithReason = "SoftDeleteWithReason", Restore = "Restore", Delete = "Delete", + Disable = "Disable", Custom = "Custom", } @@ -48,6 +49,12 @@ export async function handleConfirmation( }; } + if (confirmationType == ConfirmationType.Disable) { + return { + result: await confirmationFactory().disable(objectName ? objectName : undefined), + }; + } + if (confirmationType == ConfirmationType.Custom) { return { result: await confirmationFactory().custom(customMessage).withoutMessage(), diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Confirmation.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Confirmation.js index 4f635a567a4..3be90c2b796 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Confirmation.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Confirmation.js @@ -50,6 +50,21 @@ define(["require", "exports", "tslib", "./Dialog", "../Language", "../Dom/Util", dialog.addEventListener("cancel", () => resolve(false)); }); } + async disable(title) { + const dialog = (0, Dialog_1.dialogFactory)().withoutContent().asConfirmation(); + let question; + if (title === undefined) { + question = (0, Language_1.getPhrase)("wcf.dialog.confirmation.disable.indeterminate"); + } + else { + question = (0, Language_1.getPhrase)("wcf.dialog.confirmation.disable", { title }); + } + dialog.show(question); + return new Promise((resolve) => { + dialog.addEventListener("primary", () => resolve(true)); + dialog.addEventListener("cancel", () => resolve(false)); + }); + } async restore(title) { const dialog = (0, Dialog_1.dialogFactory)().withoutContent().asConfirmation(); let question; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/Confirmation.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/Confirmation.js index aeb05403918..dd224e14b81 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/Confirmation.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/Confirmation.js @@ -18,6 +18,7 @@ define(["require", "exports", "WoltLabSuite/Core/Component/Confirmation"], funct ConfirmationType["SoftDeleteWithReason"] = "SoftDeleteWithReason"; ConfirmationType["Restore"] = "Restore"; ConfirmationType["Delete"] = "Delete"; + ConfirmationType["Disable"] = "Disable"; ConfirmationType["Custom"] = "Custom"; })(ConfirmationType || (exports.ConfirmationType = ConfirmationType = {})); async function handleConfirmation(objectName, confirmationType, customMessage = "") { @@ -37,6 +38,11 @@ define(["require", "exports", "WoltLabSuite/Core/Component/Confirmation"], funct result: await (0, Confirmation_1.confirmationFactory)().delete(objectName ? objectName : undefined), }; } + if (confirmationType == ConfirmationType.Disable) { + return { + result: await (0, Confirmation_1.confirmationFactory)().disable(objectName ? objectName : undefined), + }; + } if (confirmationType == ConfirmationType.Custom) { return { result: await (0, Confirmation_1.confirmationFactory)().custom(customMessage).withoutMessage(), diff --git a/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php b/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php index 438761fa397..586f12bdf84 100644 --- a/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php +++ b/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php @@ -48,6 +48,8 @@ public function __invoke(PreloadPhrasesCollecting $event): void $event->preload('wcf.dialog.confirmation.cannotBeUndone'); $event->preload('wcf.dialog.confirmation.delete'); $event->preload('wcf.dialog.confirmation.delete.indeterminate'); + $event->preload('wcf.dialog.confirmation.disable'); + $event->preload('wcf.dialog.confirmation.disable.indeterminate'); $event->preload('wcf.dialog.confirmation.softDelete'); $event->preload('wcf.dialog.confirmation.softDelete.indeterminate'); $event->preload('wcf.dialog.confirmation.restore'); diff --git a/wcfsetup/install/files/lib/system/interaction/DisableInteraction.class.php b/wcfsetup/install/files/lib/system/interaction/DisableInteraction.class.php new file mode 100644 index 00000000000..5f0e76fa5d3 --- /dev/null +++ b/wcfsetup/install/files/lib/system/interaction/DisableInteraction.class.php @@ -0,0 +1,28 @@ + + * @since 6.2 + */ +class DisableInteraction extends RpcInteraction +{ + public function __construct( + string $endpoint, + ?\Closure $isAvailableCallback = null + ) { + parent::__construct( + 'disable', + $endpoint, + 'wcf.global.button.disable', + InteractionConfirmationType::Disable, + '', + $isAvailableCallback + ); + } +} diff --git a/wcfsetup/install/files/lib/system/interaction/InteractionConfirmationType.class.php b/wcfsetup/install/files/lib/system/interaction/InteractionConfirmationType.class.php index 30854d42ed4..5a30df97f4a 100644 --- a/wcfsetup/install/files/lib/system/interaction/InteractionConfirmationType.class.php +++ b/wcfsetup/install/files/lib/system/interaction/InteractionConfirmationType.class.php @@ -17,6 +17,7 @@ enum InteractionConfirmationType case SoftDeleteWithReason; case Restore; case Delete; + case Disable; case Custom; public function toString(): string @@ -27,6 +28,7 @@ public function toString(): string self::SoftDeleteWithReason => 'SoftDeleteWithReason', self::Restore => 'Restore', self::Delete => 'Delete', + self::Disable => 'Disable', self::Custom => 'Custom', }; } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index c5b41defab7..704a39692de 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3796,6 +3796,8 @@ Dateianhänge: + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 81bcc426330..05231fa767c 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3742,6 +3742,8 @@ Attachments: + +