From: joshuaruesweg Date: Mon, 9 Aug 2021 12:47:35 +0000 (+0200) Subject: Apply suggestions from code review X-Git-Tag: 5.5.0_Alpha_1~479^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=abbeb78e80103c781c83844291bfd4de9ab69166;p=GitHub%2FWoltLab%2FWCF.git Apply suggestions from code review --- diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Abstract.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Abstract.ts new file mode 100644 index 0000000000..835c437d16 --- /dev/null +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Abstract.ts @@ -0,0 +1,23 @@ +/** + * An abstract action, to handle user actions. + * + * @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 abstract class AbstractUserAction { + protected readonly button: HTMLElement; + protected readonly userDataElement: HTMLElement; + protected readonly userId: number; + + public constructor(button: HTMLElement, userId: number, userDataElement: HTMLElement) { + this.button = button; + this.userId = userId; + this.userDataElement = userDataElement; + } +} + +export default AbstractUserAction; diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/AbstractUserAction.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/AbstractUserAction.ts deleted file mode 100644 index 75a3ace37f..0000000000 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/AbstractUserAction.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @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 abstract class AbstractUserAction { - protected readonly button: HTMLElement; - protected readonly userDataElement: HTMLElement; - protected readonly userId: number; - - public constructor(button: HTMLElement, userId: number, userDataElement: HTMLElement) { - this.button = button; - this.userId = userId; - this.userDataElement = userDataElement; - - this.init(); - } - - protected abstract init(): void; -} - -export default AbstractUserAction; diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.ts index 6085667bac..4c3e69baef 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/BanAction.ts @@ -1,4 +1,6 @@ /** + * Handles a user ban button. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License @@ -7,7 +9,7 @@ */ import * as Core from "../../../../Core"; -import AbstractUserAction from "./AbstractUserAction"; +import AbstractUserAction from "./Abstract"; import BanHandler from "./Handler/Ban"; import * as UiNotification from "../../../../Ui/Notification"; import * as EventHandler from "../../../../Event/Handler"; @@ -15,7 +17,9 @@ import * as EventHandler from "../../../../Event/Handler"; export class BanAction extends AbstractUserAction { private banHandler: BanHandler; - protected init(): void { + public constructor(button: HTMLElement, userId: number, userDataElement: HTMLElement) { + super(button, userId, userDataElement); + this.banHandler = new BanHandler([this.userId]); this.button.addEventListener("click", (event) => { diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.ts index 37efb572fc..21ee45287a 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.ts @@ -1,4 +1,6 @@ /** + * Handles a user delete button. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License @@ -6,24 +8,26 @@ * @since 5.5 */ -import AbstractUserAction from "./AbstractUserAction"; +import AbstractUserAction from "./Abstract"; import Delete from "./Handler/Delete"; export class DeleteAction extends AbstractUserAction { - protected init(): void { + public constructor(button: HTMLElement, userId: number, userDataElement: HTMLElement) { + super(button, userId, userDataElement); + + if (typeof this.button.dataset.confirmMessage !== "string") { + throw new Error("The button does not provide a confirmMessage."); + } + this.button.addEventListener("click", (event) => { event.preventDefault(); - if (!(typeof this.button.dataset.confirmMessage === "string")) { - throw new Error("The button does not provides a confirmMessage."); - } - const deleteHandler = new Delete( [this.userId], () => { this.userDataElement.remove(); }, - this.button.dataset.confirmMessage, + this.button.dataset.confirmMessage!, ); deleteHandler.delete(); }); diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DisableAction.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DisableAction.ts index fe842dd31d..d5baf0ff70 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DisableAction.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DisableAction.ts @@ -1,4 +1,6 @@ /** + * Handles a user disable/enable button. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License @@ -10,11 +12,13 @@ import * as Ajax from "../../../../Ajax"; import * as Core from "../../../../Core"; import { AjaxCallbackObject, AjaxCallbackSetup, DatabaseObjectActionResponse } from "../../../../Ajax/Data"; import * as UiNotification from "../../../../Ui/Notification"; -import AbstractUserAction from "./AbstractUserAction"; +import AbstractUserAction from "./Abstract"; import * as EventHandler from "../../../../Event/Handler"; export class DisableAction extends AbstractUserAction implements AjaxCallbackObject { - protected init(): void { + public constructor(button: HTMLElement, userId: number, userDataElement: HTMLElement) { + super(button, userId, userDataElement); + this.button.addEventListener("click", (event) => { event.preventDefault(); const isEnabled = Core.stringToBool(this.userDataElement.dataset.enabled!); 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 f3968348e3..8628704c62 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban.ts @@ -1,4 +1,6 @@ /** + * Handles a user ban. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License @@ -7,21 +9,22 @@ */ import * as Ajax from "../../../../../Ajax"; -import BanDialog from "./Dialog/Ban"; +import BanDialog from "./Ban/Dialog"; + +type Callback = () => void; export class BanHandler { private userIDs: number[]; - private banCallback: () => void; public constructor(userIDs: number[]) { this.userIDs = userIDs; } - public ban(callback: () => void): void { + public ban(callback: Callback): void { BanDialog.open(this.userIDs, callback); } - public unban(callback: () => void): void { + public unban(callback: Callback): void { Ajax.api({ _ajaxSetup: () => { return { @@ -32,7 +35,7 @@ export class BanHandler { }, }; }, - _ajaxSuccess: callback, + _ajaxSuccess: () => callback(), }); } } diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban/Dialog.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban/Dialog.ts new file mode 100644 index 0000000000..c5c7ffe748 --- /dev/null +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban/Dialog.ts @@ -0,0 +1,150 @@ +/** + * Creates and handles the dialog to ban a user. + * + * @author Joshua Ruesweg + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban + * @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"; + +type Callback = () => void; + +export class BanDialog { + private static instance: BanDialog; + + private banCallback: Callback; + private userIDs: number[]; + private submitElement: HTMLElement; + private neverExpiresCheckbox: HTMLInputElement; + private reasonInput: HTMLInputElement; + private userBanExpiresSettingsElement: HTMLElement; + private dialogContent: HTMLElement; + + public static open(userIDs: number[], callback: Callback): 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: Callback): void { + this.banCallback = callback; + } + + private setUserIDs(userIDs: number[]): void { + 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/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.ts index 551912f01e..9ee1a7f6ab 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.ts @@ -1,4 +1,6 @@ /** + * Deletes a given user. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License 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 deleted file mode 100644 index 51caf7a842..0000000000 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog/Ban.ts +++ /dev/null @@ -1,145 +0,0 @@ -/** - * @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/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/SendNewPassword.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/SendNewPassword.ts index 0578c44e9d..fa954d3881 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/SendNewPassword.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/SendNewPassword.ts @@ -1,4 +1,6 @@ /** + * Handles a send new password action. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/SendNewPasswordAction.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/SendNewPasswordAction.ts index 9e2024a279..819f80381a 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/SendNewPasswordAction.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/SendNewPasswordAction.ts @@ -1,4 +1,6 @@ /** + * Handles a send new password button. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License @@ -6,11 +8,13 @@ * @since 5.5 */ -import AbstractUserAction from "./AbstractUserAction"; +import AbstractUserAction from "./Abstract"; import SendNewPassword from "./Handler/SendNewPassword"; export class SendNewPasswordAction extends AbstractUserAction { - protected init(): void { + public constructor(button: HTMLElement, userId: number, userDataElement: HTMLElement) { + super(button, userId, userDataElement); + this.button.addEventListener("click", (event) => { event.preventDefault(); diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/ToggleConfirmEmailAction.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/ToggleConfirmEmailAction.ts index 584eb9a86f..3da9abb7dd 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/ToggleConfirmEmailAction.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/ToggleConfirmEmailAction.ts @@ -1,4 +1,6 @@ /** + * Handles a toggle confirm email button. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License @@ -6,20 +8,22 @@ * @since 5.5 */ -import AbstractUserAction from "./AbstractUserAction"; +import AbstractUserAction from "./Abstract"; import * as Ajax from "../../../../Ajax"; import * as Core from "../../../../Core"; import { AjaxCallbackSetup, DatabaseObjectActionResponse } from "../../../../Ajax/Data"; import * as UiNotification from "../../../../Ui/Notification"; export class ToggleConfirmEmailAction extends AbstractUserAction { - protected init(): void { + public constructor(button: HTMLElement, userId: number, userDataElement: HTMLElement) { + super(button, userId, userDataElement); + this.button.addEventListener("click", (event) => { event.preventDefault(); const isEmailConfirmed = Core.stringToBool(this.userDataElement.dataset.emailConfirmed!); Ajax.api(this, { - actionName: (isEmailConfirmed ? "un" : "") + "confirmEmail", + actionName: isEmailConfirmed ? "unconfirmEmail" : "confirmEmail", }); }); } diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Handler.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Handler.ts index 3e84f9e938..bc3cfba36d 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Handler.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Handler.ts @@ -34,12 +34,12 @@ interface AjaxResponse { class AcpUserContentRemoveHandler { private readonly dialogId: string; private readonly userId: number; - private readonly callbackSuccess: CallbackSuccess | null | undefined; + private readonly callbackSuccess?: CallbackSuccess; /** * Initializes the content remove handler. */ - constructor(element: HTMLElement, userId: number, callbackSuccess?: CallbackSuccess | null) { + constructor(element: HTMLElement, userId: number, callbackSuccess?: CallbackSuccess) { this.userId = userId; this.dialogId = `userRemoveContentHandler-${this.userId}`; this.callbackSuccess = callbackSuccess; diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Editor.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Editor.ts index 9b8db74b35..62d8d55c66 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Editor.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Editor.ts @@ -66,34 +66,34 @@ class AcpUiUserEditor { }); } - const deleteContent = dropdownMenu.querySelector(".jsDeleteContent") as HTMLAnchorElement; + const deleteContent = dropdownMenu.querySelector(".jsDeleteContent"); if (deleteContent !== null) { - new AcpUserContentRemoveHandler(deleteContent, userId); + new AcpUserContentRemoveHandler(deleteContent as HTMLAnchorElement, userId); } - const sendNewPassword = dropdownMenu.querySelector(".jsSendNewPassword") as HTMLAnchorElement; + const sendNewPassword = dropdownMenu.querySelector(".jsSendNewPassword"); if (sendNewPassword !== null) { - new SendNewPasswordAction(sendNewPassword, userId, userRow); + new SendNewPasswordAction(sendNewPassword as HTMLAnchorElement, userId, userRow); } - const toggleConfirmEmail = dropdownMenu.querySelector(".jsConfirmEmailToggle") as HTMLAnchorElement; + const toggleConfirmEmail = dropdownMenu.querySelector(".jsConfirmEmailToggle"); if (toggleConfirmEmail !== null) { - new ToggleConfirmEmailAction(toggleConfirmEmail, userId, userRow); + new ToggleConfirmEmailAction(toggleConfirmEmail as HTMLAnchorElement, userId, userRow); } - const enableUser = dropdownMenu.querySelector(".jsEnable") as HTMLAnchorElement; + const enableUser = dropdownMenu.querySelector(".jsEnable"); if (enableUser !== null) { - new DisableAction(enableUser, userId, userRow); + new DisableAction(enableUser as HTMLAnchorElement, userId, userRow); } - const banUser = dropdownMenu.querySelector(".jsBan") as HTMLAnchorElement; + const banUser = dropdownMenu.querySelector(".jsBan"); if (banUser !== null) { - new BanAction(banUser, userId, userRow); + new BanAction(banUser as HTMLAnchorElement, userId, userRow); } - const deleteUser = dropdownMenu.querySelector(".jsDelete") as HTMLAnchorElement; + const deleteUser = dropdownMenu.querySelector(".jsDelete"); if (deleteUser !== null) { - new DeleteAction(deleteUser, userId, userRow); + new DeleteAction(deleteUser as HTMLAnchorElement, userId, userRow); } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Abstract.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Abstract.js new file mode 100644 index 0000000000..a6cf02ac98 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Abstract.js @@ -0,0 +1,23 @@ +/** + * An abstract action, to handle user actions. + * + * @author Joshua Ruesweg + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/User/Action + * @since 5.5 + */ +define(["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.AbstractUserAction = void 0; + class AbstractUserAction { + constructor(button, userId, userDataElement) { + this.button = button; + this.userId = userId; + this.userDataElement = userDataElement; + } + } + exports.AbstractUserAction = AbstractUserAction; + exports.default = AbstractUserAction; +}); 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 index de99615fa0..47163afb60 100644 --- 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 @@ -1,21 +1,24 @@ /** + * Handles a user ban button. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License * @module WoltLabSuite/Core/Acp/Ui/User/Action * @since 5.5 */ -define(["require", "exports", "tslib", "../../../../Core", "./AbstractUserAction", "./Handler/Ban", "../../../../Ui/Notification", "../../../../Event/Handler"], function (require, exports, tslib_1, Core, AbstractUserAction_1, Ban_1, UiNotification, EventHandler) { +define(["require", "exports", "tslib", "../../../../Core", "./Abstract", "./Handler/Ban", "../../../../Ui/Notification", "../../../../Event/Handler"], function (require, exports, tslib_1, Core, Abstract_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); + Abstract_1 = tslib_1.__importDefault(Abstract_1); Ban_1 = tslib_1.__importDefault(Ban_1); UiNotification = tslib_1.__importStar(UiNotification); EventHandler = tslib_1.__importStar(EventHandler); - class BanAction extends AbstractUserAction_1.default { - init() { + class BanAction extends Abstract_1.default { + constructor(button, userId, userDataElement) { + super(button, userId, userDataElement); this.banHandler = new Ban_1.default([this.userId]); this.button.addEventListener("click", (event) => { event.preventDefault(); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.js index dd726758d6..82e8533ee0 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.js @@ -1,23 +1,26 @@ /** + * Handles a user delete button. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License * @module WoltLabSuite/Core/Acp/Ui/User/Action * @since 5.5 */ -define(["require", "exports", "tslib", "./AbstractUserAction", "./Handler/Delete"], function (require, exports, tslib_1, AbstractUserAction_1, Delete_1) { +define(["require", "exports", "tslib", "./Abstract", "./Handler/Delete"], function (require, exports, tslib_1, Abstract_1, Delete_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeleteAction = void 0; - AbstractUserAction_1 = tslib_1.__importDefault(AbstractUserAction_1); + Abstract_1 = tslib_1.__importDefault(Abstract_1); Delete_1 = tslib_1.__importDefault(Delete_1); - class DeleteAction extends AbstractUserAction_1.default { - init() { + class DeleteAction extends Abstract_1.default { + constructor(button, userId, userDataElement) { + super(button, userId, userDataElement); + if (typeof this.button.dataset.confirmMessage !== "string") { + throw new Error("The button does not provide a confirmMessage."); + } this.button.addEventListener("click", (event) => { event.preventDefault(); - if (!(typeof this.button.dataset.confirmMessage === "string")) { - throw new Error("The button does not provides a confirmMessage."); - } const deleteHandler = new Delete_1.default([this.userId], () => { this.userDataElement.remove(); }, this.button.dataset.confirmMessage); 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 index 19a37bee22..5636c96eeb 100644 --- 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 @@ -1,21 +1,24 @@ /** + * Handles a user disable/enable button. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License * @module WoltLabSuite/Core/Acp/Ui/User/Action * @since 5.5 */ -define(["require", "exports", "tslib", "../../../../Ajax", "../../../../Core", "../../../../Ui/Notification", "./AbstractUserAction", "../../../../Event/Handler"], function (require, exports, tslib_1, Ajax, Core, UiNotification, AbstractUserAction_1, EventHandler) { +define(["require", "exports", "tslib", "../../../../Ajax", "../../../../Core", "../../../../Ui/Notification", "./Abstract", "../../../../Event/Handler"], function (require, exports, tslib_1, Ajax, Core, UiNotification, Abstract_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); + Abstract_1 = tslib_1.__importDefault(Abstract_1); EventHandler = tslib_1.__importStar(EventHandler); - class DisableAction extends AbstractUserAction_1.default { - init() { + class DisableAction extends Abstract_1.default { + constructor(button, userId, userDataElement) { + super(button, userId, userDataElement); this.button.addEventListener("click", (event) => { event.preventDefault(); const isEnabled = Core.stringToBool(this.userDataElement.dataset.enabled); 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 5da6793d65..34144ce2c0 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 @@ -1,22 +1,24 @@ /** + * Handles a user ban. + * * @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 */ -define(["require", "exports", "tslib", "../../../../../Ajax", "./Dialog/Ban"], function (require, exports, tslib_1, Ajax, Ban_1) { +define(["require", "exports", "tslib", "../../../../../Ajax", "./Ban/Dialog"], function (require, exports, tslib_1, Ajax, Dialog_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BanHandler = void 0; Ajax = tslib_1.__importStar(Ajax); - Ban_1 = tslib_1.__importDefault(Ban_1); + Dialog_1 = tslib_1.__importDefault(Dialog_1); class BanHandler { constructor(userIDs) { this.userIDs = userIDs; } ban(callback) { - Ban_1.default.open(this.userIDs, callback); + Dialog_1.default.open(this.userIDs, callback); } unban(callback) { Ajax.api({ @@ -29,7 +31,7 @@ define(["require", "exports", "tslib", "../../../../../Ajax", "./Dialog/Ban"], f }, }; }, - _ajaxSuccess: callback, + _ajaxSuccess: () => callback(), }); } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban/Dialog.js new file mode 100644 index 0000000000..43bd7f5932 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban/Dialog.js @@ -0,0 +1,129 @@ +/** + * Creates and handles the dialog to ban a user. + * + * @author Joshua Ruesweg + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Ban + * @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; +}); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.js index 076cadf887..61d6c30e8e 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.js @@ -1,4 +1,6 @@ /** + * Deletes a given user. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License 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 deleted file mode 100644 index aec65ef656..0000000000 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog/Ban.js +++ /dev/null @@ -1,127 +0,0 @@ -/** - * @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; -}); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/SendNewPassword.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/SendNewPassword.js index 929e785b0a..0bb45be553 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/SendNewPassword.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/SendNewPassword.js @@ -1,4 +1,6 @@ /** + * Handles a send new password action. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/SendNewPasswordAction.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/SendNewPasswordAction.js index b75cfdb6df..9f61c127aa 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/SendNewPasswordAction.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/SendNewPasswordAction.js @@ -1,18 +1,21 @@ /** + * Handles a send new password button. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License * @module WoltLabSuite/Core/Acp/Ui/User/Action * @since 5.5 */ -define(["require", "exports", "tslib", "./AbstractUserAction", "./Handler/SendNewPassword"], function (require, exports, tslib_1, AbstractUserAction_1, SendNewPassword_1) { +define(["require", "exports", "tslib", "./Abstract", "./Handler/SendNewPassword"], function (require, exports, tslib_1, Abstract_1, SendNewPassword_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SendNewPasswordAction = void 0; - AbstractUserAction_1 = tslib_1.__importDefault(AbstractUserAction_1); + Abstract_1 = tslib_1.__importDefault(Abstract_1); SendNewPassword_1 = tslib_1.__importDefault(SendNewPassword_1); - class SendNewPasswordAction extends AbstractUserAction_1.default { - init() { + class SendNewPasswordAction extends Abstract_1.default { + constructor(button, userId, userDataElement) { + super(button, userId, userDataElement); this.button.addEventListener("click", (event) => { event.preventDefault(); const sendNewPasswordHandler = new SendNewPassword_1.default([this.userId], () => { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/ToggleConfirmEmailAction.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/ToggleConfirmEmailAction.js index 3ca6146c9c..242b9e285b 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/ToggleConfirmEmailAction.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/ToggleConfirmEmailAction.js @@ -1,25 +1,28 @@ /** + * Handles a toggle confirm email button. + * * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH * @license GNU Lesser General Public License * @module WoltLabSuite/Core/Acp/Ui/User/Action * @since 5.5 */ -define(["require", "exports", "tslib", "./AbstractUserAction", "../../../../Ajax", "../../../../Core", "../../../../Ui/Notification"], function (require, exports, tslib_1, AbstractUserAction_1, Ajax, Core, UiNotification) { +define(["require", "exports", "tslib", "./Abstract", "../../../../Ajax", "../../../../Core", "../../../../Ui/Notification"], function (require, exports, tslib_1, Abstract_1, Ajax, Core, UiNotification) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ToggleConfirmEmailAction = void 0; - AbstractUserAction_1 = tslib_1.__importDefault(AbstractUserAction_1); + Abstract_1 = tslib_1.__importDefault(Abstract_1); Ajax = tslib_1.__importStar(Ajax); Core = tslib_1.__importStar(Core); UiNotification = tslib_1.__importStar(UiNotification); - class ToggleConfirmEmailAction extends AbstractUserAction_1.default { - init() { + class ToggleConfirmEmailAction extends Abstract_1.default { + constructor(button, userId, userDataElement) { + super(button, userId, userDataElement); this.button.addEventListener("click", (event) => { event.preventDefault(); const isEmailConfirmed = Core.stringToBool(this.userDataElement.dataset.emailConfirmed); Ajax.api(this, { - actionName: (isEmailConfirmed ? "un" : "") + "confirmEmail", + actionName: isEmailConfirmed ? "unconfirmEmail" : "confirmEmail", }); }); }