-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathLegacyDboAction.ts
More file actions
67 lines (61 loc) · 2.13 KB
/
LegacyDboAction.ts
File metadata and controls
67 lines (61 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Handles interactions that call legacy DBO actions.
*
* @author Marcel Werk
* @copyright 2001-2024 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
* @deprecated 6.2 DBO actions are considered outdated and should be migrated to RPC endpoints.
*/
import { dboAction } from "WoltLabSuite/Core/Ajax";
import { show as showNotification } from "WoltLabSuite/Core/Ui/Notification";
import { ConfirmationType, handleConfirmation } from "./Confirmation";
async function handleDboAction(
element: HTMLElement,
objectName: string,
className: string,
actionName: string,
confirmationType: ConfirmationType,
customConfirmationMessage: string = "",
): Promise<void> {
const confirmationResult = await handleConfirmation(objectName, confirmationType, customConfirmationMessage);
if (!confirmationResult.result) {
return;
}
await dboAction(actionName, className)
.objectIds([parseInt(element.dataset.objectId!)])
.payload(confirmationResult.reason ? { reason: confirmationResult.reason } : {})
.dispatch();
if (confirmationType == ConfirmationType.Delete) {
// TODO: This shows a generic success message and should be replaced with a more specific message.
showNotification(undefined, () => {
element.dispatchEvent(
new CustomEvent("interaction:remove", {
bubbles: true,
}),
);
});
} else {
element.dispatchEvent(
new CustomEvent("interaction:invalidate", {
bubbles: true,
}),
);
// TODO: This shows a generic success message and should be replaced with a more specific message.
showNotification();
}
}
export function setup(identifier: string, container: HTMLElement): void {
container.addEventListener("interaction:execute", (event: CustomEvent) => {
if (event.detail.interaction === identifier) {
void handleDboAction(
event.target as HTMLElement,
event.detail.objectName,
event.detail.className,
event.detail.actionName,
event.detail.confirmationType,
event.detail.confirmationMessage,
);
}
});
}