From: joshuaruesweg Date: Wed, 23 Jun 2021 13:06:38 +0000 (+0200) Subject: Add UserDelete Handler X-Git-Tag: 5.5.0_Alpha_1~479^2~11 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=743e150ba3e268bcd092ae2c4f689326b580f0f5;p=GitHub%2FWoltLab%2FWCF.git Add UserDelete Handler --- diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.ts new file mode 100644 index 0000000000..559527d5dd --- /dev/null +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.ts @@ -0,0 +1,25 @@ +import AbstractUserAction from "./AbstractUserAction"; +import * as Language from "../../../../Language"; +import Delete from "./Handler/Delete"; + +/** + * @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 DeleteAction extends AbstractUserAction { + protected init() { + this.button.addEventListener("click", (event) => { + event.preventDefault(); + + let deleteHandler = new Delete([this.userId], () => { + this.userData.remove(); + }, this.button.dataset.confirmMessage); + deleteHandler.delete(); + }); + } +} + +export default DeleteAction; diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.ts new file mode 100644 index 0000000000..3a6a58abd1 --- /dev/null +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.ts @@ -0,0 +1,53 @@ +import * as Language from "../../../../../Language"; +import * as UiConfirmation from "../../../../../Ui/Confirmation"; +import * as Ajax from "../../../../../Ajax"; +import { CallbackSuccess } from "../../../../../Ajax/Data"; + +/** + * @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 Delete { + private userIDs: number[]; + private successCallback: CallbackSuccess; + private deleteMessage: string; + + public constructor(userIDs: number[], successCallback: CallbackSuccess, deleteMessage?: string) { + this.userIDs = userIDs; + this.successCallback = successCallback; + if (deleteMessage) { + this.deleteMessage = deleteMessage; + } + else { + this.deleteMessage = Language.get("wcf.button.delete.confirmMessage"); // @todo find better variable for a generic message + } + } + + delete(): void { + UiConfirmation.show({ + confirm: () => { + Ajax.api( + { + _ajaxSetup: () => { + return { + data: { + actionName: "delete", + className: "wcf\\data\\user\\UserAction", + objectIDs: this.userIDs, + }, + }; + }, + _ajaxSuccess: this.successCallback, + } + ); + }, + message: this.deleteMessage, + messageIsHtml: true, + }); + } +} + +export default Delete; diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Editor.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Editor.ts index 0bf7cd6194..406d795eec 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/User/Editor.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Editor.ts @@ -18,6 +18,7 @@ import SendNewPasswordAction from "./Action/SendNewPasswordAction"; import ToggleConfirmEmailAction from "./Action/ToggleConfirmEmailAction"; import DisableAction from "./Action/DisableAction"; import BanAction from "./Action/BanAction"; +import DeleteAction from "./Action/DeleteAction"; interface RefreshUsersData { userIds: number[]; @@ -89,6 +90,11 @@ class AcpUiUserEditor { if (banUser !== null) { new BanAction(banUser, userId, userRow); } + + const deleteUser = dropdownMenu.querySelector(".jsDelete") as HTMLAnchorElement; + if (deleteUser !== null) { + new DeleteAction(deleteUser, userId, userRow); + } } /** @@ -102,12 +108,6 @@ class AcpUiUserEditor { const items: HTMLLIElement[] = []; let deleteButton: HTMLAnchorElement | null = null; Array.from(legacyButtonContainer.children).forEach((button: HTMLAnchorElement) => { - if (button.classList.contains("jsObjectAction") && button.dataset.objectAction === "delete") { - deleteButton = button; - - return; - } - const item = document.createElement("li"); item.className = "jsLegacyItem"; item.innerHTML = ''; @@ -132,15 +132,6 @@ class AcpUiUserEditor { dropdownMenu.insertAdjacentElement("afterbegin", item); }); - if (deleteButton !== null) { - const dispatchDeleteButton = dropdownMenu.querySelector(".jsDispatchDelete") as HTMLAnchorElement; - dispatchDeleteButton.addEventListener("click", (event) => { - event.preventDefault(); - - deleteButton!.click(); - }); - } - // check if there are visible items before each divider const listItems = Array.from(dropdownMenu.children) as HTMLElement[]; listItems.forEach((element) => DomUtil.show(element)); diff --git a/wcfsetup/install/files/acp/templates/userList.tpl b/wcfsetup/install/files/acp/templates/userList.tpl index e0b314dc72..fcb9179880 100644 --- a/wcfsetup/install/files/acp/templates/userList.tpl +++ b/wcfsetup/install/files/acp/templates/userList.tpl @@ -135,7 +135,7 @@ {if $user->deletable} -
  • {lang}wcf.global.button.delete{/lang}
  • +
  • {lang}wcf.global.button.delete{/lang}
  • {lang}wcf.acp.content.removeContent{/lang}
  • {/if} @@ -152,10 +152,6 @@ based insert calls. Clicks are forwarded to them anyway, thus there is no significant downside, other than "just" some more legacy code. *} - {if $user->deletable} - {objectAction action="delete" objectTitle=$user->getTitle()} - {/if} - {event name='rowButtons'} 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 new file mode 100644 index 0000000000..f1b4ab105e --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/DeleteAction.js @@ -0,0 +1,27 @@ +define(["require", "exports", "tslib", "./AbstractUserAction", "./Handler/Delete"], function (require, exports, tslib_1, AbstractUserAction_1, Delete_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.DeleteAction = void 0; + AbstractUserAction_1 = tslib_1.__importDefault(AbstractUserAction_1); + Delete_1 = tslib_1.__importDefault(Delete_1); + /** + * @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 DeleteAction extends AbstractUserAction_1.default { + init() { + this.button.addEventListener("click", (event) => { + event.preventDefault(); + let deleteHandler = new Delete_1.default([this.userId], () => { + this.userData.remove(); + }, this.button.dataset.confirmMessage); + deleteHandler.delete(); + }); + } + } + exports.DeleteAction = DeleteAction; + exports.default = DeleteAction; +}); 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 aa967c63f2..efceca214d 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 @@ -29,25 +29,26 @@ define(["require", "exports", "tslib", "../../../../Ajax", "../../../../Core", " }, }; }, - }, undefined, (data) => { - if (data.objectIDs.includes(this.userId)) { - switch (data.actionName) { - case "enable": - this.userData.dataset.enabled = "true"; - this.button.textContent = this.button.dataset.disableMessage; - break; - case "disable": - this.userData.dataset.enabled = "false"; - this.button.textContent = this.button.dataset.enableMessage; - break; - default: - throw new Error("Unreachable"); + _ajaxSuccess: (data) => { + if (data.objectIDs.includes(this.userId)) { + switch (data.actionName) { + case "enable": + this.userData.dataset.enabled = "true"; + this.button.textContent = this.button.dataset.disableMessage; + break; + case "disable": + this.userData.dataset.enabled = "false"; + this.button.textContent = this.button.dataset.enableMessage; + break; + default: + throw new Error("Unreachable"); + } } - } - UiNotification.show(); - EventHandler.fire("com.woltlab.wcf.acp.user", "refresh", { - userIds: [this.userId] - }); + UiNotification.show(); + EventHandler.fire("com.woltlab.wcf.acp.user", "refresh", { + userIds: [this.userId] + }); + }, }); }); } 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 new file mode 100644 index 0000000000..f0ecfe250e --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Delete.js @@ -0,0 +1,49 @@ +define(["require", "exports", "tslib", "../../../../../Language", "../../../../../Ui/Confirmation", "../../../../../Ajax"], function (require, exports, tslib_1, Language, UiConfirmation, Ajax) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.Delete = void 0; + Language = tslib_1.__importStar(Language); + UiConfirmation = tslib_1.__importStar(UiConfirmation); + Ajax = tslib_1.__importStar(Ajax); + /** + * @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 Delete { + constructor(userIDs, successCallback, deleteMessage) { + this.userIDs = userIDs; + this.successCallback = successCallback; + if (deleteMessage) { + this.deleteMessage = deleteMessage; + } + else { + this.deleteMessage = Language.get("wcf.button.delete.confirmMessage"); // @todo find better variable for a generic message + } + } + delete() { + UiConfirmation.show({ + confirm: () => { + Ajax.api({ + _ajaxSetup: () => { + return { + data: { + actionName: "delete", + className: "wcf\\data\\user\\UserAction", + objectIDs: this.userIDs, + }, + }; + }, + _ajaxSuccess: this.successCallback, + }); + }, + message: this.deleteMessage, + messageIsHtml: true, + }); + } + } + exports.Delete = Delete; + exports.default = Delete; +}); 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 20bdb65974..3243b6245b 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 @@ -28,22 +28,23 @@ define(["require", "exports", "tslib", "./AbstractUserAction", "../../../../Ajax }, }; }, - }, undefined, (data) => { - if (data.objectIDs.includes(this.userId)) { - switch (data.actionName) { - case "confirmEmail": - this.userData.dataset.emailConfirmed = "true"; - this.button.textContent = this.button.dataset.unconfirmEmailMessage; - break; - case "unconfirmEmail": - this.userData.dataset.emailConfirmed = "false"; - this.button.textContent = this.button.dataset.confirmEmailMessage; - break; - default: - throw new Error("Unreachable"); + _ajaxSuccess: (data) => { + if (data.objectIDs.includes(this.userId)) { + switch (data.actionName) { + case "confirmEmail": + this.userData.dataset.emailConfirmed = "true"; + this.button.textContent = this.button.dataset.unconfirmEmailMessage; + break; + case "unconfirmEmail": + this.userData.dataset.emailConfirmed = "false"; + this.button.textContent = this.button.dataset.confirmEmailMessage; + break; + default: + throw new Error("Unreachable"); + } } - } - UiNotification.show(); + UiNotification.show(); + }, }); }); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Editor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Editor.js index 97b69e6870..eda27b916d 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Editor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Editor.js @@ -7,7 +7,7 @@ * @module WoltLabSuite/Core/Acp/Ui/User/Editor * @since 3.1 */ -define(["require", "exports", "tslib", "./Content/Remove/Handler", "../../../Core", "../../../Event/Handler", "../../../Language", "../../../Ui/Dropdown/Simple", "../../../Dom/Util", "./Action/SendNewPasswordAction", "./Action/ToggleConfirmEmailAction", "./Action/DisableAction", "./Action/BanAction"], function (require, exports, tslib_1, Handler_1, Core, EventHandler, Language, Simple_1, Util_1, SendNewPasswordAction_1, ToggleConfirmEmailAction_1, DisableAction_1, BanAction_1) { +define(["require", "exports", "tslib", "./Content/Remove/Handler", "../../../Core", "../../../Event/Handler", "../../../Language", "../../../Ui/Dropdown/Simple", "../../../Dom/Util", "./Action/SendNewPasswordAction", "./Action/ToggleConfirmEmailAction", "./Action/DisableAction", "./Action/BanAction", "./Action/DeleteAction"], function (require, exports, tslib_1, Handler_1, Core, EventHandler, Language, Simple_1, Util_1, SendNewPasswordAction_1, ToggleConfirmEmailAction_1, DisableAction_1, BanAction_1, DeleteAction_1) { "use strict"; Handler_1 = tslib_1.__importDefault(Handler_1); Core = tslib_1.__importStar(Core); @@ -19,6 +19,7 @@ define(["require", "exports", "tslib", "./Content/Remove/Handler", "../../../Cor ToggleConfirmEmailAction_1 = tslib_1.__importDefault(ToggleConfirmEmailAction_1); DisableAction_1 = tslib_1.__importDefault(DisableAction_1); BanAction_1 = tslib_1.__importDefault(BanAction_1); + DeleteAction_1 = tslib_1.__importDefault(DeleteAction_1); class AcpUiUserEditor { /** * Initializes the edit dropdown for each user. @@ -73,6 +74,10 @@ define(["require", "exports", "tslib", "./Content/Remove/Handler", "../../../Cor if (banUser !== null) { new BanAction_1.default(banUser, userId, userRow); } + const deleteUser = dropdownMenu.querySelector(".jsDelete"); + if (deleteUser !== null) { + new DeleteAction_1.default(deleteUser, userId, userRow); + } } /** * Rebuilds the dropdown by adding wrapper links for legacy buttons, @@ -84,10 +89,6 @@ define(["require", "exports", "tslib", "./Content/Remove/Handler", "../../../Cor const items = []; let deleteButton = null; Array.from(legacyButtonContainer.children).forEach((button) => { - if (button.classList.contains("jsObjectAction") && button.dataset.objectAction === "delete") { - deleteButton = button; - return; - } const item = document.createElement("li"); item.className = "jsLegacyItem"; item.innerHTML = ''; @@ -108,13 +109,6 @@ define(["require", "exports", "tslib", "./Content/Remove/Handler", "../../../Cor items.forEach((item) => { dropdownMenu.insertAdjacentElement("afterbegin", item); }); - if (deleteButton !== null) { - const dispatchDeleteButton = dropdownMenu.querySelector(".jsDispatchDelete"); - dispatchDeleteButton.addEventListener("click", (event) => { - event.preventDefault(); - deleteButton.click(); - }); - } // check if there are visible items before each divider const listItems = Array.from(dropdownMenu.children); listItems.forEach((element) => Util_1.default.show(element));