Skip to content

Commit 761e6b5

Browse files
authored
Merge pull request #6263 from WoltLab/6.2-disable-interaction
Add generic disable interaction with confirmation
2 parents 29a9707 + 439740f commit 761e6b5

9 files changed

Lines changed: 82 additions & 0 deletions

File tree

ts/WoltLabSuite/Core/Component/Confirmation.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ class ConfirmationPrefab {
6262
});
6363
}
6464

65+
async disable(title?: string): Promise<boolean> {
66+
const dialog = dialogFactory().withoutContent().asConfirmation();
67+
68+
let question: string;
69+
if (title === undefined) {
70+
question = getPhrase("wcf.dialog.confirmation.disable.indeterminate");
71+
} else {
72+
question = getPhrase("wcf.dialog.confirmation.disable", { title });
73+
}
74+
75+
dialog.show(question);
76+
77+
return new Promise<boolean>((resolve) => {
78+
dialog.addEventListener("primary", () => resolve(true));
79+
dialog.addEventListener("cancel", () => resolve(false));
80+
});
81+
}
82+
6583
async restore(title?: string): Promise<boolean> {
6684
const dialog = dialogFactory().withoutContent().asConfirmation();
6785

ts/WoltLabSuite/Core/Component/Interaction/Confirmation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export enum ConfirmationType {
1515
SoftDeleteWithReason = "SoftDeleteWithReason",
1616
Restore = "Restore",
1717
Delete = "Delete",
18+
Disable = "Disable",
1819
Custom = "Custom",
1920
}
2021

@@ -48,6 +49,12 @@ export async function handleConfirmation(
4849
};
4950
}
5051

52+
if (confirmationType == ConfirmationType.Disable) {
53+
return {
54+
result: await confirmationFactory().disable(objectName ? objectName : undefined),
55+
};
56+
}
57+
5158
if (confirmationType == ConfirmationType.Custom) {
5259
return {
5360
result: await confirmationFactory().custom(customMessage).withoutMessage(),

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Confirmation.js

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/Confirmation.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function __invoke(PreloadPhrasesCollecting $event): void
4848
$event->preload('wcf.dialog.confirmation.cannotBeUndone');
4949
$event->preload('wcf.dialog.confirmation.delete');
5050
$event->preload('wcf.dialog.confirmation.delete.indeterminate');
51+
$event->preload('wcf.dialog.confirmation.disable');
52+
$event->preload('wcf.dialog.confirmation.disable.indeterminate');
5153
$event->preload('wcf.dialog.confirmation.softDelete');
5254
$event->preload('wcf.dialog.confirmation.softDelete.indeterminate');
5355
$event->preload('wcf.dialog.confirmation.restore');
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace wcf\system\interaction;
4+
5+
/**
6+
* Represents a disable interaction.
7+
*
8+
* @author Marcel Werk
9+
* @copyright 2001-2025 WoltLab GmbH
10+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11+
* @since 6.2
12+
*/
13+
class DisableInteraction extends RpcInteraction
14+
{
15+
public function __construct(
16+
string $endpoint,
17+
?\Closure $isAvailableCallback = null
18+
) {
19+
parent::__construct(
20+
'disable',
21+
$endpoint,
22+
'wcf.global.button.disable',
23+
InteractionConfirmationType::Disable,
24+
'',
25+
$isAvailableCallback
26+
);
27+
}
28+
}

wcfsetup/install/files/lib/system/interaction/InteractionConfirmationType.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum InteractionConfirmationType
1717
case SoftDeleteWithReason;
1818
case Restore;
1919
case Delete;
20+
case Disable;
2021
case Custom;
2122

2223
public function toString(): string
@@ -27,6 +28,7 @@ public function toString(): string
2728
self::SoftDeleteWithReason => 'SoftDeleteWithReason',
2829
self::Restore => 'Restore',
2930
self::Delete => 'Delete',
31+
self::Disable => 'Disable',
3032
self::Custom => 'Custom',
3133
};
3234
}

wcfsetup/install/lang/de.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3796,6 +3796,8 @@ Dateianhänge:
37963796
<item name="wcf.dialog.confirmation.cannotBeUndone"><![CDATA[Dieser Vorgang kann nicht rückgängig gemacht werden.]]></item>
37973797
<item name="wcf.dialog.confirmation.delete"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} „{$title}“ wirklich löschen?]]></item>
37983798
<item name="wcf.dialog.confirmation.delete.indeterminate"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} dies wirklich löschen?]]></item>
3799+
<item name="wcf.dialog.confirmation.disable"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Möchtest du{else}Möchten Sie{/if} „{$title}“ wirklich deaktivieren?]]></item>
3800+
<item name="wcf.dialog.confirmation.disable.indeterminate"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Möchtest du{else}Möchten Sie{/if} dies wirklich deaktivieren?]]></item>
37993801
<item name="wcf.dialog.confirmation.softDelete"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Möchtest du{else}Möchten Sie{/if} „{$title}“ in den Papierkorb verschieben?]]></item>
38003802
<item name="wcf.dialog.confirmation.softDelete.indeterminate"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Möchtest du{else}Möchten Sie{/if} dies in den Papierkorb verschieben?]]></item>
38013803
<item name="wcf.dialog.confirmation.restore"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Möchtest du{else}Möchten Sie{/if} „{$title}“ wiederherstellen?]]></item>

wcfsetup/install/lang/en.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,6 +3742,8 @@ Attachments:
37423742
<item name="wcf.dialog.confirmation.cannotBeUndone"><![CDATA[This process cannot be undone.]]></item>
37433743
<item name="wcf.dialog.confirmation.delete"><![CDATA[Are you sure you want to delete “{$title}”?]]></item>
37443744
<item name="wcf.dialog.confirmation.delete.indeterminate"><![CDATA[Are you sure you want to delete this?]]></item>
3745+
<item name="wcf.dialog.confirmation.disable"><![CDATA[Do you want to disable “{$title}”?]]></item>
3746+
<item name="wcf.dialog.confirmation.disable.indeterminate"><![CDATA[Do you want to disable this?]]></item>
37453747
<item name="wcf.dialog.confirmation.softDelete"><![CDATA[Do you want to move “{$title}” to the trash bin?]]></item>
37463748
<item name="wcf.dialog.confirmation.softDelete.indeterminate"><![CDATA[Do you want to move this to the trash bin?]]></item>
37473749
<item name="wcf.dialog.confirmation.restore"><![CDATA[Do you want to restore “{$title}”?]]></item>

0 commit comments

Comments
 (0)