From 7922f3eb5ba4d7f736ac3d13a47e2ee02225db84 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Wed, 16 Jun 2021 11:28:14 +0200 Subject: [PATCH] Add `BanAction` --- .../Core/Acp/Ui/User/Action/BanAction.ts | 53 +++++++++++++++++++ .../Core/Acp/Ui/User/Action/BanAction.js | 48 +++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 ts/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.ts create mode 100644 wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.js diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.ts new file mode 100644 index 0000000000..ab70349d75 --- /dev/null +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.ts @@ -0,0 +1,53 @@ +import * as Core from "../../../../Core"; +import AbstractUserAction from "./AbstractUserAction"; +import BanHandler from "./Handler/Ban"; +import * as UiNotification from "../../../../Ui/Notification"; +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 BanAction extends AbstractUserAction { + private banHandler: BanHandler; + + protected init() { + this.banHandler = new BanHandler([this.userId]); + + this.button.addEventListener("click", (event) => { + event.preventDefault(); + + const isBanned = Core.stringToBool(this.userData.dataset.banned!); + + if (isBanned) { + this.banHandler.unban(() => { + this.userData.dataset.banned = "false"; + this.button.textContent = this.button.dataset.banMessage!; + + UiNotification.show(); + + EventHandler.fire("com.woltlab.wcf.acp.user", "refresh", { + userIds: [this.userId] + }); + }); + } + else { + this.banHandler.ban(() => { + this.userData.dataset.banned = "true"; + this.button.textContent = this.button.dataset.unbanMessage!; + + UiNotification.show(); + + EventHandler.fire("com.woltlab.wcf.acp.user", "refresh", { + userIds: [this.userId] + }); + }); + } + }); + } +} + +export default BanAction; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.js new file mode 100644 index 0000000000..137e010c66 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.js @@ -0,0 +1,48 @@ +define(["require", "exports", "tslib", "../../../../Core", "./AbstractUserAction", "./Handler/Ban", "../../../../Ui/Notification", "../../../../Event/Handler"], function (require, exports, tslib_1, Core, AbstractUserAction_1, Ban_1, UiNotification, EventHandler) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.BanAction = void 0; + Core = tslib_1.__importStar(Core); + AbstractUserAction_1 = tslib_1.__importDefault(AbstractUserAction_1); + Ban_1 = tslib_1.__importDefault(Ban_1); + UiNotification = tslib_1.__importStar(UiNotification); + 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 BanAction extends AbstractUserAction_1.default { + init() { + this.banHandler = new Ban_1.default([this.userId]); + this.button.addEventListener("click", (event) => { + event.preventDefault(); + const isBanned = Core.stringToBool(this.userData.dataset.banned); + if (isBanned) { + this.banHandler.unban(() => { + this.userData.dataset.banned = "false"; + this.button.textContent = this.button.dataset.banMessage; + UiNotification.show(); + EventHandler.fire("com.woltlab.wcf.acp.user", "refresh", { + userIds: [this.userId] + }); + }); + } + else { + this.banHandler.ban(() => { + this.userData.dataset.banned = "true"; + this.button.textContent = this.button.dataset.unbanMessage; + UiNotification.show(); + EventHandler.fire("com.woltlab.wcf.acp.user", "refresh", { + userIds: [this.userId] + }); + }); + } + }); + } + } + exports.BanAction = BanAction; + exports.default = BanAction; +}); -- 2.20.1