From: Cyperghost Date: Wed, 3 Jul 2024 07:53:05 +0000 (+0200) Subject: Change the function that adds a button so that it only returns a button and doesn... X-Git-Tag: 6.1.0_Alpha_1~41^2~6 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d6c7b089a09255026323721634f6e6220672972e;p=GitHub%2FWoltLab%2FWCF.git Change the function that adds a button so that it only returns a button and doesn't insert it --- diff --git a/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts b/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts index 6fb09a8737..85e9adc20e 100644 --- a/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts +++ b/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts @@ -76,10 +76,14 @@ export class FileProcessor { buttons.classList.add("buttonList"); buttons.classList.add(this.classPrefix + "item__buttons"); - this.addDeleteButton(element, buttons); + let listItem = document.createElement("li"); + listItem.append(this.getDeleteButton(element)); + buttons.append(listItem); if (this.#singleFileUpload) { - this.addReplaceButton(element, buttons); + listItem = document.createElement("li"); + listItem.append(this.getReplaceButton(element)); + buttons.append(listItem); } this.#extraButtons.forEach((button) => { @@ -116,7 +120,7 @@ export class FileProcessor { container.classList.add("innerError"); } - protected addDeleteButton(element: WoltlabCoreFileElement, buttons: HTMLUListElement): void { + protected getDeleteButton(element: WoltlabCoreFileElement): HTMLButtonElement { const deleteButton = document.createElement("button"); deleteButton.type = "button"; deleteButton.classList.add("button", "small"); @@ -127,12 +131,10 @@ export class FileProcessor { this.#unregisterFile(element); }); - const listItem = document.createElement("li"); - listItem.append(deleteButton); - buttons.append(listItem); + return deleteButton; } - protected addReplaceButton(element: WoltlabCoreFileElement, buttons: HTMLUListElement): void { + protected getReplaceButton(element: WoltlabCoreFileElement): HTMLButtonElement { const replaceButton = document.createElement("button"); replaceButton.type = "button"; replaceButton.classList.add("button", "small"); @@ -168,9 +170,7 @@ export class FileProcessor { this.#fileInput.click(); }); - const listItem = document.createElement("li"); - listItem.append(replaceButton); - buttons.append(listItem); + return replaceButton; } #unregisterFile(element: WoltlabCoreFileElement): void { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js index 7d93d1d07a..722b6d83fd 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js @@ -48,9 +48,13 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui const buttons = document.createElement("ul"); buttons.classList.add("buttonList"); buttons.classList.add(this.classPrefix + "item__buttons"); - this.addDeleteButton(element, buttons); + let listItem = document.createElement("li"); + listItem.append(this.getDeleteButton(element)); + buttons.append(listItem); if (this.#singleFileUpload) { - this.addReplaceButton(element, buttons); + listItem = document.createElement("li"); + listItem.append(this.getReplaceButton(element)); + buttons.append(listItem); } this.#extraButtons.forEach((button) => { const extraButton = document.createElement("button"); @@ -80,7 +84,7 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui (0, File_1.fileInitializationFailed)(container, element, reason); container.classList.add("innerError"); } - addDeleteButton(element, buttons) { + getDeleteButton(element) { const deleteButton = document.createElement("button"); deleteButton.type = "button"; deleteButton.classList.add("button", "small"); @@ -89,11 +93,9 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui await (0, DeleteFile_1.deleteFile)(element.fileId); this.#unregisterFile(element); }); - const listItem = document.createElement("li"); - listItem.append(deleteButton); - buttons.append(listItem); + return deleteButton; } - addReplaceButton(element, buttons) { + getReplaceButton(element) { const replaceButton = document.createElement("button"); replaceButton.type = "button"; replaceButton.classList.add("button", "small"); @@ -125,9 +127,7 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui this.#fileInput.addEventListener("change", changeEventListener, { once: true }); this.#fileInput.click(); }); - const listItem = document.createElement("li"); - listItem.append(replaceButton); - buttons.append(listItem); + return replaceButton; } #unregisterFile(element) { if (this.showBigPreview) {