From 06787917de73ec32a626d0be6cad769a1fd36716 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Tue, 3 Dec 2024 10:16:36 +0100 Subject: [PATCH] Migrate `WCF.ACP.User.Group.Copy` to TypeScript --- .../Core/Acp/Ui/User/Group/Copy.ts | 28 ++++ wcfsetup/install/files/acp/js/WCF.ACP.js | 58 ------- .../files/acp/templates/userGroupAdd.tpl | 22 +-- .../Core/Acp/Ui/User/Group/Copy.js | 25 +++ .../acp/action/UserGroupCopyAction.class.php | 116 +++++++++++++ .../data/user/group/UserGroupAction.class.php | 154 +----------------- .../group/command/CopyUserGroup.class.php | 141 ++++++++++++++++ 7 files changed, 318 insertions(+), 226 deletions(-) create mode 100644 ts/WoltLabSuite/Core/Acp/Ui/User/Group/Copy.ts create mode 100644 wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Group/Copy.js create mode 100644 wcfsetup/install/files/lib/acp/action/UserGroupCopyAction.class.php create mode 100644 wcfsetup/install/files/lib/system/user/group/command/CopyUserGroup.class.php diff --git a/ts/WoltLabSuite/Core/Acp/Ui/User/Group/Copy.ts b/ts/WoltLabSuite/Core/Acp/Ui/User/Group/Copy.ts new file mode 100644 index 0000000000..45866e4ad7 --- /dev/null +++ b/ts/WoltLabSuite/Core/Acp/Ui/User/Group/Copy.ts @@ -0,0 +1,28 @@ +/** + * Handles the dialog to copy a user group. + * + * @author Olaf Braun + * @copyright 2001-2024 WoltLab GmbH + * @license GNU Lesser General Public License + */ + +import { dialogFactory } from "WoltLabSuite/Core/Component/Dialog"; + +interface CopyResponse { + groupID: number; + redirectURL: string; +} + +export function init() { + const button = document.querySelector(".jsButtonUserGroupCopy"); + button?.addEventListener("click", () => { + void dialogFactory() + .usingFormBuilder() + .fromEndpoint(button.dataset.endpoint!) + .then((result) => { + if (result.ok) { + window.location.href = result.result.redirectURL; + } + }); + }); +} diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index 4a45c87748..567ad9ef13 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -1283,64 +1283,6 @@ WCF.ACP.User.BanHandler = { } }; -/** - * Namespace for user group management. - */ -WCF.ACP.User.Group = { }; - -/** - * Handles copying user groups. - */ -WCF.ACP.User.Group.Copy = Class.extend({ - /** - * id of the copied group - * @var integer - */ - _groupID: 0, - - /** - * Initializes a new instance of WCF.ACP.User.Group.Copy. - * - * @param integer groupID - */ - init: function(groupID) { - this._groupID = groupID; - - $('.jsButtonUserGroupCopy').click($.proxy(this._click, this)); - }, - - /** - * Handles clicking on a 'copy user group' button. - */ - _click: function() { - var $template = $('
'); - $template.append($('
' + WCF.Language.get('wcf.acp.group.copy.copyMembers.description') + '
')); - $template.append($('
' + WCF.Language.get('wcf.acp.group.copy.copyUserGroupOptions.description') + '
')); - $template.append($('
' + WCF.Language.get('wcf.acp.group.copy.copyACLOptions.description') + '
')); - - WCF.System.Confirmation.show(WCF.Language.get('wcf.acp.group.copy.confirmMessage'), $.proxy(function(action) { - if (action === 'confirm') { - new WCF.Action.Proxy({ - autoSend: true, - data: { - actionName: 'copy', - className: 'wcf\\data\\user\\group\\UserGroupAction', - objectIDs: [ this._groupID ], - parameters: { - copyACLOptions: $('#copyACLOptions').is(':checked'), - copyMembers: $('#copyMembers').is(':checked'), - copyUserGroupOptions: $('#copyUserGroupOptions').is(':checked') - } - }, - success: function(data) { - window.location = data.returnValues.redirectURL; - } - }); - } - }, this), '', $template, true); - } -}); - /** * Generic implementation to enable users. */ diff --git a/wcfsetup/install/files/acp/templates/userGroupAdd.tpl b/wcfsetup/install/files/acp/templates/userGroupAdd.tpl index c7b0ece143..c4f27aa586 100644 --- a/wcfsetup/install/files/acp/templates/userGroupAdd.tpl +++ b/wcfsetup/install/files/acp/templates/userGroupAdd.tpl @@ -1,23 +1,15 @@ {include file='header' pageTitle='wcf.acp.group.'|concat:$action}