From 9fcfd90ed9db4e2d36484072c93c77fb068b3576 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Wed, 30 Jun 2021 15:22:22 +0200 Subject: [PATCH] Add new BanDialog --- .../Core/Acp/Ui/User/Action/Handler/Ban.ts | 109 +------------ .../Acp/Ui/User/Action/Handler/Dialog/Ban.ts | 146 ++++++++++++++++++ .../Core/Acp/Ui/User/Action/Handler/Ban.js | 100 +----------- .../Acp/Ui/User/Action/Handler/Dialog/Ban.js | 126 +++++++++++++++ 4 files changed, 277 insertions(+), 204 deletions(-) create mode 100644 ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog/Ban.ts create mode 100644 wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog/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 index 06c288ae24..f3968348e3 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.ts @@ -6,10 +6,8 @@ * @since 5.5 */ -import { DialogCallbackSetup } from "../../../../../Ui/Dialog/Data"; -import * as Language from "../../../../../Language"; import * as Ajax from "../../../../../Ajax"; -import UiDialog from "../../../../../Ui/Dialog"; +import BanDialog from "./Dialog/Ban"; export class BanHandler { private userIDs: number[]; @@ -20,11 +18,7 @@ export class BanHandler { } public 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); + BanDialog.open(this.userIDs, callback); } public unban(callback: () => void): void { @@ -41,105 +35,6 @@ export class BanHandler { _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: { - onSetup: (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; diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog/Ban.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog/Ban.ts new file mode 100644 index 0000000000..4430eadee5 --- /dev/null +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog/Ban.ts @@ -0,0 +1,146 @@ +/** + * @author Joshua Ruesweg + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog + * @since 5.5 + */ + +import UiDialog from "../../../../../../Ui/Dialog"; +import { DialogCallbackSetup } from "../../../../../../Ui/Dialog/Data"; +import * as Language from "../../../../../../Language"; +import * as Ajax from "../../../../../../Ajax"; +import DatePicker from "../../../../../../Date/Picker"; + +export class BanDialog { + private static instance: BanDialog; + + private banCallback: () => void; + private userIDs: number[]; + private submitElement: HTMLElement; + private neverExpiresCheckbox: HTMLInputElement; + private reasonInput: HTMLInputElement; + private userBanExpiresSettingsElement: HTMLElement; + private dialogContent: HTMLElement; + public static open(userIDs: number[], callback: () => void): void { + if (!BanDialog.instance) { + BanDialog.instance = new BanDialog(); + } + + BanDialog.instance.setCallback(callback); + BanDialog.instance.setUserIDs(userIDs); + BanDialog.instance.openDialog(); + } + + private openDialog(): void { + UiDialog.open(this); + } + + private setCallback(callback: () => void): void { + this.banCallback = callback; + } + + private setUserIDs(userIDs: number[]) { + this.userIDs = userIDs; + } + + private banSubmit(reason: string, expires: string): void { + Ajax.apiOnce({ + data: { + actionName: "ban", + className: "wcf\\data\\user\\UserAction", + objectIDs: this.userIDs, + parameters: { + banReason: reason, + banExpires: expires, + }, + }, + success: this.banCallback, + }); + } + + private cleanupDialog(): void { + this.reasonInput.value = ""; + this.neverExpiresCheckbox.checked = true; + DatePicker.clear("userBanExpires"); + this.userBanExpiresSettingsElement.style.setProperty("display", "none", ""); + } + + _dialogSetup(): ReturnType { + return { + id: "userBanHandler", + options: { + onSetup: (content: HTMLElement): void => { + this.dialogContent = content; + this.submitElement = content.querySelector(".formSubmitButton")! as HTMLElement; + this.reasonInput = content.querySelector("#userBanReason")! as HTMLInputElement; + this.neverExpiresCheckbox = content.querySelector("#userBanNeverExpires")! as HTMLInputElement; + this.userBanExpiresSettingsElement = content.querySelector("#userBanExpiresSettings")! as HTMLElement; + + this.submitElement.addEventListener("click", (event) => { + event.preventDefault(); + + const expires = this.neverExpiresCheckbox.checked ? "" : DatePicker.getValue("userBanExpires"); + this.banSubmit(this.reasonInput.value, expires); + + UiDialog.close(this); + + this.cleanupDialog(); + }); + + this.neverExpiresCheckbox.addEventListener("change", (event) => { + const checkbox = event.currentTarget as HTMLInputElement; + if (checkbox.checked) { + this.userBanExpiresSettingsElement.style.setProperty("display", "none", ""); + } else { + this.userBanExpiresSettingsElement.style.removeProperty("display"); + } + }); + }, + title: Language.get("wcf.acp.user.ban.sure"), + }, + source: `
+
+
+
+ + ${Language.get("wcf.acp.user.banReason.description")} +
+
+
+
+
+ +
+
+ +
+
+ +
`, + }; + } +} + +export default BanDialog; 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 index 2bf06609b4..5da6793d65 100644 --- 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 @@ -5,22 +5,18 @@ * @module WoltLabSuite/Core/Acp/Ui/User/Action/Handler * @since 5.5 */ -define(["require", "exports", "tslib", "../../../../../Language", "../../../../../Ajax", "../../../../../Ui/Dialog"], function (require, exports, tslib_1, Language, Ajax, Dialog_1) { +define(["require", "exports", "tslib", "../../../../../Ajax", "./Dialog/Ban"], function (require, exports, tslib_1, Ajax, Ban_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); + Ban_1 = tslib_1.__importDefault(Ban_1); 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); + Ban_1.default.open(this.userIDs, callback); } unban(callback) { Ajax.api({ @@ -36,96 +32,6 @@ define(["require", "exports", "tslib", "../../../../../Language", "../../../../. _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: { - onSetup: (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; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog/Ban.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog/Ban.js new file mode 100644 index 0000000000..921ba376d8 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog/Ban.js @@ -0,0 +1,126 @@ +/** + * @author Joshua Ruesweg + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog + * @since 5.5 + */ +define(["require", "exports", "tslib", "../../../../../../Ui/Dialog", "../../../../../../Language", "../../../../../../Ajax", "../../../../../../Date/Picker"], function (require, exports, tslib_1, Dialog_1, Language, Ajax, Picker_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.BanDialog = void 0; + Dialog_1 = tslib_1.__importDefault(Dialog_1); + Language = tslib_1.__importStar(Language); + Ajax = tslib_1.__importStar(Ajax); + Picker_1 = tslib_1.__importDefault(Picker_1); + class BanDialog { + static open(userIDs, callback) { + if (!BanDialog.instance) { + BanDialog.instance = new BanDialog(); + } + BanDialog.instance.setCallback(callback); + BanDialog.instance.setUserIDs(userIDs); + BanDialog.instance.openDialog(); + } + openDialog() { + Dialog_1.default.open(this); + } + setCallback(callback) { + this.banCallback = callback; + } + setUserIDs(userIDs) { + this.userIDs = userIDs; + } + banSubmit(reason, expires) { + Ajax.apiOnce({ + data: { + actionName: "ban", + className: "wcf\\data\\user\\UserAction", + objectIDs: this.userIDs, + parameters: { + banReason: reason, + banExpires: expires, + }, + }, + success: this.banCallback, + }); + } + cleanupDialog() { + this.reasonInput.value = ""; + this.neverExpiresCheckbox.checked = true; + Picker_1.default.clear("userBanExpires"); + this.userBanExpiresSettingsElement.style.setProperty("display", "none", ""); + } + _dialogSetup() { + return { + id: "userBanHandler", + options: { + onSetup: (content) => { + this.dialogContent = content; + this.submitElement = content.querySelector(".formSubmitButton"); + this.reasonInput = content.querySelector("#userBanReason"); + this.neverExpiresCheckbox = content.querySelector("#userBanNeverExpires"); + this.userBanExpiresSettingsElement = content.querySelector("#userBanExpiresSettings"); + this.submitElement.addEventListener("click", (event) => { + event.preventDefault(); + const expires = this.neverExpiresCheckbox.checked ? "" : Picker_1.default.getValue("userBanExpires"); + this.banSubmit(this.reasonInput.value, expires); + Dialog_1.default.close(this); + this.cleanupDialog(); + }); + this.neverExpiresCheckbox.addEventListener("change", (event) => { + const checkbox = event.currentTarget; + if (checkbox.checked) { + this.userBanExpiresSettingsElement.style.setProperty("display", "none", ""); + } + else { + this.userBanExpiresSettingsElement.style.removeProperty("display"); + } + }); + }, + title: Language.get("wcf.acp.user.ban.sure"), + }, + source: `
+
+
+
+ + ${Language.get("wcf.acp.user.banReason.description")} +
+
+
+
+
+ +
+
+ +
+
+ +
`, + }; + } + } + exports.BanDialog = BanDialog; + exports.default = BanDialog; +}); -- 2.20.1