Change the function that adds a button so that it only returns a button and doesn...
authorCyperghost <olaf_schmitz_1@t-online.de>
Wed, 3 Jul 2024 07:53:05 +0000 (09:53 +0200)
committerCyperghost <olaf_schmitz_1@t-online.de>
Wed, 3 Jul 2024 07:53:05 +0000 (09:53 +0200)
ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js

index 6fb09a87372577ac34957bb7fabb8d09bd7042d6..85e9adc20efba8c4a33fef935afcc95f6b192ced 100644 (file)
@@ -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 {
index 7d93d1d07a94b3a999ac5eccc8c6fed17b2a60c5..722b6d83fd5e4db6c1ea6c8887b69465ee6f9bbf 100644 (file)
@@ -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) {