From: joshuaruesweg Date: Wed, 16 Jun 2021 09:27:21 +0000 (+0200) Subject: Add `DisableAction` X-Git-Tag: 5.5.0_Alpha_1~479^2~17 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=727c2ef9627ba2857bac3a19d8ec91442efcf17d;p=GitHub%2FWoltLab%2FWCF.git Add `DisableAction` --- diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DisableAction.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DisableAction.ts new file mode 100644 index 0000000000..f132404333 --- /dev/null +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DisableAction.ts @@ -0,0 +1,64 @@ +import * as Ajax from "../../../../Ajax"; +import * as Core from "../../../../Core"; +import { AjaxCallbackObject, DatabaseObjectActionResponse } from "../../../../Ajax/Data"; +import * as UiNotification from "../../../../Ui/Notification"; +import AbstractUserAction from "./AbstractUserAction"; +import * as EventHandler from "../../../../Event/Handler"; + +/** + * @author Joshua Ruesweg + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/User/Action + * @since 5.5 + */ +export class DisableAction extends AbstractUserAction { + protected init() { + this.button.addEventListener("click", (event) => { + event.preventDefault(); + + Ajax.api( + { + _ajaxSetup: () => { + const isEnabled = Core.stringToBool(this.userData.dataset.enabled!); + + return { + data: { + actionName: (isEnabled ? "disable" : "enable"), + className: "wcf\\data\\user\\UserAction", + objectIDs: [this.userId], + }, + }; + }, + + _ajaxSuccess: (data: DatabaseObjectActionResponse) => { + if (data.objectIDs.includes(this.userId)) { + switch (data.actionName) { + case "enable": + this.userData.dataset.enabled = "true"; + this.button.textContent = this.button.dataset.disableMessage!; + break; + + case "disable": + this.userData.dataset.enabled = "false"; + this.button.textContent = this.button.dataset.enableMessage!; + break; + + default: + throw new Error("Unreachable"); + } + } + + UiNotification.show(); + + EventHandler.fire("com.woltlab.wcf.acp.user", "refresh", { + userIds: [this.userId] + }); + }, + } + ); + }); + } +} + +export default DisableAction; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/DisableAction.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/DisableAction.js new file mode 100644 index 0000000000..aa967c63f2 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/DisableAction.js @@ -0,0 +1,57 @@ +define(["require", "exports", "tslib", "../../../../Ajax", "../../../../Core", "../../../../Ui/Notification", "./AbstractUserAction", "../../../../Event/Handler"], function (require, exports, tslib_1, Ajax, Core, UiNotification, AbstractUserAction_1, EventHandler) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.DisableAction = void 0; + Ajax = tslib_1.__importStar(Ajax); + Core = tslib_1.__importStar(Core); + UiNotification = tslib_1.__importStar(UiNotification); + AbstractUserAction_1 = tslib_1.__importDefault(AbstractUserAction_1); + EventHandler = tslib_1.__importStar(EventHandler); + /** + * @author Joshua Ruesweg + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/User/Action + * @since 5.5 + */ + class DisableAction extends AbstractUserAction_1.default { + init() { + this.button.addEventListener("click", (event) => { + event.preventDefault(); + Ajax.api({ + _ajaxSetup: () => { + const isEnabled = Core.stringToBool(this.userData.dataset.enabled); + return { + data: { + actionName: (isEnabled ? "disable" : "enable"), + className: "wcf\\data\\user\\UserAction", + objectIDs: [this.userId], + }, + }; + }, + }, undefined, (data) => { + if (data.objectIDs.includes(this.userId)) { + switch (data.actionName) { + case "enable": + this.userData.dataset.enabled = "true"; + this.button.textContent = this.button.dataset.disableMessage; + break; + case "disable": + this.userData.dataset.enabled = "false"; + this.button.textContent = this.button.dataset.enableMessage; + break; + default: + throw new Error("Unreachable"); + } + } + UiNotification.show(); + EventHandler.fire("com.woltlab.wcf.acp.user", "refresh", { + userIds: [this.userId] + }); + }); + }); + } + } + exports.DisableAction = DisableAction; + exports.default = DisableAction; +});