--- /dev/null
+/**
+ * Handles execution of DBO actions within grid views.
+ *
+ * @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(
+ row: HTMLTableRowElement,
+ 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(row.dataset.objectId!)])
+ .payload(confirmationResult.reason ? { reason: confirmationResult.reason } : {})
+ .dispatch();
+
+ if (confirmationType == ConfirmationType.Delete) {
+ row.remove();
+ } else {
+ row.dispatchEvent(
+ new CustomEvent("refresh", {
+ bubbles: true,
+ }),
+ );
+
+ // TODO: This shows a generic success message and should be replaced with a more specific message.
+ showNotification();
+ }
+}
+
+export function setup(table: HTMLTableElement): void {
+ table.addEventListener("action", (event: CustomEvent) => {
+ if (event.detail.action === "legacy-dbo-action") {
+ void handleDboAction(
+ event.target as HTMLTableRowElement,
+ event.detail.objectName,
+ event.detail.className,
+ event.detail.actionName,
+ event.detail.confirmationType,
+ event.detail.confirmationMessage,
+ );
+ }
+ });
+}
--- /dev/null
+/**
+ * Handles execution of DBO actions within grid views.
+ *
+ * @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.
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax", "WoltLabSuite/Core/Ui/Notification", "./Confirmation"], function (require, exports, Ajax_1, Notification_1, Confirmation_1) {
+ "use strict";
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.setup = setup;
+ async function handleDboAction(row, objectName, className, actionName, confirmationType, customConfirmationMessage = "") {
+ const confirmationResult = await (0, Confirmation_1.handleConfirmation)(objectName, confirmationType, customConfirmationMessage);
+ if (!confirmationResult.result) {
+ return;
+ }
+ await (0, Ajax_1.dboAction)(actionName, className)
+ .objectIds([parseInt(row.dataset.objectId)])
+ .payload(confirmationResult.reason ? { reason: confirmationResult.reason } : {})
+ .dispatch();
+ if (confirmationType == Confirmation_1.ConfirmationType.Delete) {
+ row.remove();
+ }
+ else {
+ row.dispatchEvent(new CustomEvent("refresh", {
+ bubbles: true,
+ }));
+ // TODO: This shows a generic success message and should be replaced with a more specific message.
+ (0, Notification_1.show)();
+ }
+ }
+ function setup(table) {
+ table.addEventListener("action", (event) => {
+ if (event.detail.action === "legacy-dbo-action") {
+ void handleDboAction(event.target, event.detail.objectName, event.detail.className, event.detail.actionName, event.detail.confirmationType, event.detail.confirmationMessage);
+ }
+ });
+ }
+});
--- /dev/null
+<?php
+
+namespace wcf\system\gridView\action;
+
+use Closure;
+use wcf\data\DatabaseObject;
+use wcf\data\ITitledObject;
+use wcf\system\gridView\AbstractGridView;
+use wcf\system\WCF;
+use wcf\util\StringUtil;
+
+/**
+ * Represents an action that executes a dbo action.
+ *
+ * @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.
+ */
+class LegacyDboAction extends AbstractAction
+{
+ public function __construct(
+ protected readonly string $className,
+ protected readonly string $actionName,
+ protected readonly string|Closure $languageItem,
+ protected readonly ActionConfirmationType $confirmationType = ActionConfirmationType::None,
+ protected readonly string|Closure $confirmationMessage = '',
+ ?Closure $isAvailableCallback = null
+ ) {
+ parent::__construct($isAvailableCallback);
+ }
+
+ #[\Override]
+ public function render(mixed $row): string
+ {
+ \assert($row instanceof DatabaseObject);
+
+ if (\is_string($this->languageItem)) {
+ $label = WCF::getLanguage()->get($this->languageItem);
+ } else {
+ $label = ($this->languageItem)($row);
+ }
+
+ if (\is_string($this->confirmationMessage)) {
+ $confirmationMessage = WCF::getLanguage()->get($this->confirmationMessage);
+ } else {
+ $confirmationMessage = ($this->confirmationMessage)($row);
+ }
+
+ if ($row instanceof ITitledObject) {
+ $objectName = StringUtil::encodeHTML($row->getTitle());
+ } else {
+ $objectName = '';
+ }
+
+ $className = StringUtil::encodeHTML($this->className);
+ $actionName = StringUtil::encodeHTML($this->actionName);
+
+ return <<<HTML
+ <button
+ type="button"
+ data-action="legacy-dbo-action"
+ data-object-name="{$objectName}"
+ data-class-name="{$className}"
+ data-action-name="{$actionName}"
+ data-confirmation-type="{$this->confirmationType->toString()}"
+ data-confirmation-message="{$confirmationMessage}"
+ >
+ {$label}
+ </button>
+ HTML;
+ }
+
+ #[\Override]
+ public function renderInitialization(AbstractGridView $gridView): ?string
+ {
+ $id = StringUtil::encodeJS($gridView->getID());
+
+ return <<<HTML
+ <script data-relocate="true">
+ require(['WoltLabSuite/Core/Component/GridView/Action/LegacyDboAction'], ({ setup }) => {
+ setup(document.getElementById('{$id}_table'));
+ });
+ </script>
+ HTML;
+ }
+}