From: Cyperghost Date: Thu, 14 Nov 2024 09:13:56 +0000 (+0100) Subject: Use FormBuilder to copy template groups X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0768f15dc09cbcf73ed6ead83156a6d4f721dd40;p=GitHub%2FWoltLab%2FWCF.git Use FormBuilder to copy template groups --- diff --git a/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.ts b/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.ts index 1650d84c09..ad6da2484c 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.ts @@ -1,143 +1,29 @@ /** * Provides a dialog to copy an existing template group. * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH + * @author Olaf Braun, Alexander Ebert + * @copyright 2001-2024 WoltLab GmbH * @license GNU Lesser General Public License */ -import * as Ajax from "../../../../Ajax"; -import { AjaxCallbackObject, AjaxCallbackSetup } from "../../../../Ajax/Data"; -import { DialogCallbackObject, DialogCallbackSetup } from "../../../../Ui/Dialog/Data"; -import * as Language from "../../../../Language"; -import UiDialog from "../../../../Ui/Dialog"; import * as UiNotification from "../../../../Ui/Notification"; -import DomUtil from "../../../../Dom/Util"; +import { dialogFactory } from "WoltLabSuite/Core/Component/Dialog"; -interface AjaxResponse { - returnValues: { - redirectURL: string; - }; +interface Response { + redirectURL: string; } -interface AjaxResponseError { - returnValues?: { - fieldName?: string; - errorType?: string; - }; +export function init(): void { + const button = document.querySelector(".jsButtonCopy") as HTMLAnchorElement; + button.addEventListener("click", () => void click(button)); } -class AcpUiTemplateGroupCopy implements AjaxCallbackObject, DialogCallbackObject { - private folderName?: HTMLInputElement = undefined; - private name?: HTMLInputElement = undefined; - private readonly templateGroupId: number; - - constructor(templateGroupId: number) { - this.templateGroupId = templateGroupId; - - const button = document.querySelector(".jsButtonCopy") as HTMLAnchorElement; - button.addEventListener("click", (ev) => this.click(ev)); - } - - private click(event: MouseEvent): void { - event.preventDefault(); - - UiDialog.open(this); - } - - _dialogSubmit(): void { - Ajax.api(this, { - parameters: { - templateGroupName: this.name!.value, - templateGroupFolderName: this.folderName!.value, - }, - }); - } - - _ajaxSuccess(data: AjaxResponse): void { - UiDialog.close(this); - +async function click(button: HTMLAnchorElement): Promise { + const result = await dialogFactory().usingFormBuilder().fromEndpoint(button.dataset.endpoint!); + if (result.ok) { UiNotification.show(undefined, () => { - window.location.href = data.returnValues.redirectURL; + window.location.href = result.result.redirectURL; }); } - - _dialogSetup(): ReturnType { - return { - id: "templateGroupCopy", - options: { - onSetup: () => { - ["Name", "FolderName"].forEach((type) => { - const input = document.getElementById("copyTemplateGroup" + type) as HTMLInputElement; - input.value = (document.getElementById("templateGroup" + type) as HTMLInputElement).value; - - if (type === "Name") { - this.name = input; - } else { - this.folderName = input; - } - }); - }, - title: Language.get("wcf.acp.template.group.copy"), - }, - source: `
-
- -
-
- -
-
-
-
- -
-
- -
-
-
- -
`, - }; - } - - _ajaxSetup(): ReturnType { - return { - data: { - actionName: "copy", - className: "wcf\\data\\template\\group\\TemplateGroupAction", - objectIDs: [this.templateGroupId], - }, - failure: (data: AjaxResponseError) => { - if (data && data.returnValues && data.returnValues.fieldName && data.returnValues.errorType) { - if (data.returnValues.fieldName === "templateGroupName") { - DomUtil.innerError( - this.name!, - Language.get(`wcf.acp.template.group.name.error.${data.returnValues.errorType}`), - ); - } else { - DomUtil.innerError( - this.folderName!, - Language.get(`wcf.acp.template.group.folderName.error.${data.returnValues.errorType}`), - ); - } - - return false; - } - - return true; - }, - }; - } } -let acpUiTemplateGroupCopy: AcpUiTemplateGroupCopy; - -export function init(templateGroupId: number): void { - if (!acpUiTemplateGroupCopy) { - acpUiTemplateGroupCopy = new AcpUiTemplateGroupCopy(templateGroupId); - } -} diff --git a/wcfsetup/install/files/acp/templates/templateGroupAdd.tpl b/wcfsetup/install/files/acp/templates/templateGroupAdd.tpl index 0b89149421..62fce1b22a 100644 --- a/wcfsetup/install/files/acp/templates/templateGroupAdd.tpl +++ b/wcfsetup/install/files/acp/templates/templateGroupAdd.tpl @@ -2,17 +2,8 @@ {if $action === 'edit'} {/if} @@ -24,7 +15,7 @@