From 76af7649fdf2d4490f2b9d7cf498bd2b88a20bbc Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Wed, 16 Jun 2021 11:28:00 +0200 Subject: [PATCH] Add `BanHandler` --- .../Core/Acp/Ui/User/Action/Handler/Ban.ts | 148 ++++++++++++++++++ .../Core/Acp/Ui/User/Action/Handler/Ban.js | 132 ++++++++++++++++ 2 files changed, 280 insertions(+) create mode 100644 ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.ts create mode 100644 wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.js diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.ts new file mode 100644 index 0000000000..b5654d755d --- /dev/null +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.ts @@ -0,0 +1,148 @@ +import { DialogCallbackSetup } from "../../../../../Ui/Dialog/Data"; +import * as Language from "../../../../../Language"; +import * as Ajax from "../../../../../Ajax"; +import { AjaxCallbackObject, DatabaseObjectActionResponse } from "../../../../../Ajax/Data"; +import UiDialog from "../../../../../Ui/Dialog"; + +/** + * @author Joshua Ruesweg + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/User/Action/Handler + * @since 5.5 + */ +export class BanHandler { + private userIDs: number[]; + private banCallback: () => void; + + public constructor(userIDs: number[]) { + this.userIDs = userIDs; + } + + ban(callback: () => void): void { + // Save the callback for later usage. + // We cannot easily give the callback to the dialog. + this.banCallback = callback; + + UiDialog.open(this); + } + + unban(callback: () => void): void { + Ajax.api( + { + _ajaxSetup: () => { + return { + data: { + actionName: "unban", + className: "wcf\\data\\user\\UserAction", + objectIDs: this.userIDs, + }, + }; + }, + _ajaxSuccess: callback, + } + ); + } + + private banSubmit(reason: string, userBanExpires: string): void { + Ajax.api( + { + _ajaxSetup: () => { + return { + data: { + actionName: "ban", + className: "wcf\\data\\user\\UserAction", + objectIDs: this.userIDs, + parameters: { + 'banReason': reason, + 'banExpires': userBanExpires, + }, + }, + }; + }, + _ajaxSuccess: this.banCallback, + } + ); + } + + _dialogSetup(): ReturnType { + return { + id: "userBanHandler", + options: { + onShow: (content: HTMLElement): void => { + const submit = content.querySelector(".formSubmitButton")! as HTMLElement; + const neverExpires = content.querySelector("#userBanNeverExpires")! as HTMLInputElement; + const userBanExpiresSettings = content.querySelector("#userBanExpiresSettings")! as HTMLElement; + + submit.addEventListener("click", (event) => { + event.preventDefault(); + + const reason = content.querySelector("#userBanReason")! as HTMLInputElement; + const neverExpires = content.querySelector("#userBanNeverExpires")! as HTMLInputElement; + const userBanExpires = content.querySelector("#userBanExpiresDatePicker")! as HTMLInputElement; + + this.banSubmit(reason.value, neverExpires.checked ? "" : userBanExpires.value); + + UiDialog.close(this); + + reason.value = ""; + neverExpires.checked = true; + // @TODO empty userBanExpires + userBanExpiresSettings.style.setProperty("display", "none", ""); + }); + + neverExpires.addEventListener("change", (event) => { + const checkbox = event.currentTarget as HTMLInputElement; + if (checkbox.checked) { + userBanExpiresSettings.style.setProperty("display", "none", ""); + } + else { + userBanExpiresSettings.style.removeProperty("display"); + } + }); + }, + title: Language.get('wcf.acp.user.ban.sure'), + }, + source: `
+
+
+
+ + ${Language.get('wcf.acp.user.banReason.description')} +
+
+
+
+
+ +
+
+ +
+
+ +
`, + }; + } +} + +export default BanHandler; \ No newline at end of file diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.js new file mode 100644 index 0000000000..7d0a0c519e --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.js @@ -0,0 +1,132 @@ +define(["require", "exports", "tslib", "../../../../../Language", "../../../../../Ajax", "../../../../../Ui/Dialog"], function (require, exports, tslib_1, Language, Ajax, Dialog_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.BanHandler = void 0; + Language = tslib_1.__importStar(Language); + Ajax = tslib_1.__importStar(Ajax); + Dialog_1 = tslib_1.__importDefault(Dialog_1); + /** + * @author Joshua Ruesweg + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/User/Action/Handler + * @since 5.5 + */ + class BanHandler { + constructor(userIDs) { + this.userIDs = userIDs; + } + ban(callback) { + // Save the callback for later usage. + // We cannot easily give the callback to the dialog. + this.banCallback = callback; + Dialog_1.default.open(this); + } + unban(callback) { + Ajax.api({ + _ajaxSetup: () => { + return { + data: { + actionName: "unban", + className: "wcf\\data\\user\\UserAction", + objectIDs: this.userIDs, + }, + }; + }, + _ajaxSuccess: callback, + }); + } + banSubmit(reason, userBanExpires) { + Ajax.api({ + _ajaxSetup: () => { + return { + data: { + actionName: "ban", + className: "wcf\\data\\user\\UserAction", + objectIDs: this.userIDs, + parameters: { + 'banReason': reason, + 'banExpires': userBanExpires, + }, + }, + }; + }, + _ajaxSuccess: this.banCallback, + }); + } + _dialogSetup() { + return { + id: "userBanHandler", + options: { + onShow: (content) => { + const submit = content.querySelector(".formSubmitButton"); + const neverExpires = content.querySelector("#userBanNeverExpires"); + const userBanExpiresSettings = content.querySelector("#userBanExpiresSettings"); + submit.addEventListener("click", (event) => { + event.preventDefault(); + const reason = content.querySelector("#userBanReason"); + const neverExpires = content.querySelector("#userBanNeverExpires"); + const userBanExpires = content.querySelector("#userBanExpiresDatePicker"); + this.banSubmit(reason.value, neverExpires.checked ? "" : userBanExpires.value); + Dialog_1.default.close(this); + reason.value = ""; + neverExpires.checked = true; + // @TODO empty userBanExpires + userBanExpiresSettings.style.setProperty("display", "none", ""); + }); + neverExpires.addEventListener("change", (event) => { + const checkbox = event.currentTarget; + if (checkbox.checked) { + userBanExpiresSettings.style.setProperty("display", "none", ""); + } + else { + userBanExpiresSettings.style.removeProperty("display"); + } + }); + }, + title: Language.get('wcf.acp.user.ban.sure'), + }, + source: `
+
+
+
+ + ${Language.get('wcf.acp.user.banReason.description')} +
+
+
+
+
+ +
+
+ +
+
+ +
`, + }; + } + } + exports.BanHandler = BanHandler; + exports.default = BanHandler; +}); -- 2.20.1