Add `BanAction`
authorjoshuaruesweg <ruesweg@woltlab.com>
Wed, 16 Jun 2021 09:28:14 +0000 (11:28 +0200)
committerjoshuaruesweg <ruesweg@woltlab.com>
Mon, 28 Jun 2021 15:28:45 +0000 (17:28 +0200)
ts/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.ts [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.js [new file with mode: 0644]

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 (file)
index 0000000..ab70349
--- /dev/null
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 0000000..137e010
--- /dev/null
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
+     * @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;
+});