Introduce a helper interface for the FileUpload class
authorAlexander Ebert <ebert@woltlab.com>
Sat, 28 Nov 2020 15:15:26 +0000 (16:15 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 28 Nov 2020 15:15:26 +0000 (16:15 +0100)
This interface prevents a circular dependency of the modules `./Delete` and `./Upload`.

wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Data.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Delete.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Data.ts [new file with mode: 0644]
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Delete.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Upload.ts

diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Data.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Data.js
new file mode 100644 (file)
index 0000000..e00a67f
--- /dev/null
@@ -0,0 +1,6 @@
+// This helper interface exists to prevent a circular dependency
+// between `./Delete` and `./Upload`
+define(["require", "exports"], function (require, exports) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+});
index 2fc93f647c20277e8b8736714370f113e75946aa..b1eeea363f2ca375d690cd1f61288b9a8d50d0e6 100644 (file)
@@ -14,7 +14,6 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ch
     Listener_1 = tslib_1.__importDefault(Listener_1);
     Language = tslib_1.__importStar(Language);
     class UiFileDelete {
-        // TODO: uploadHandler should not be `any`
         constructor(buttonContainerId, targetId, isSingleImagePreview, uploadHandler) {
             this.containers = new Map();
             this.deleteButton = undefined;
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Data.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Data.ts
new file mode 100644 (file)
index 0000000..c13af33
--- /dev/null
@@ -0,0 +1,6 @@
+// This helper interface exists to prevent a circular dependency
+// between `./Delete` and `./Upload`
+
+export interface FileUploadHandler {
+  checkMaxFiles(): void;
+}
index c1a96cd3eb64de347fb857dc774511afe73bc8d7..e973743f917b6369f522abbaf9ae2554650c3f3e 100644 (file)
@@ -13,6 +13,7 @@ import { AjaxCallbackObject, AjaxCallbackSetup, DatabaseObjectActionResponse } f
 import * as Core from "../../Core";
 import DomChangeListener from "../../Dom/Change/Listener";
 import * as Language from "../../Language";
+import { FileUploadHandler } from "./Data";
 
 interface AjaxResponse extends DatabaseObjectActionResponse {
   uniqueFileId: string;
@@ -30,11 +31,14 @@ class UiFileDelete implements AjaxCallbackObject {
   private readonly internalId: string;
   private readonly isSingleImagePreview: boolean;
   private readonly target: HTMLElement;
-  // TODO: uploadHandler should not be `any`
-  private readonly uploadHandler: any;
-
-  // TODO: uploadHandler should not be `any`
-  constructor(buttonContainerId: string, targetId: string, isSingleImagePreview: boolean, uploadHandler: any) {
+  private readonly uploadHandler: FileUploadHandler;
+
+  constructor(
+    buttonContainerId: string,
+    targetId: string,
+    isSingleImagePreview: boolean,
+    uploadHandler: FileUploadHandler,
+  ) {
     this.isSingleImagePreview = isSingleImagePreview;
     this.uploadHandler = uploadHandler;
 
index dd814439fba4038dd3e3a15bab8781dbbeb4c12c..d8ab9f7d045931213fec585300ef86403f0b6801 100644 (file)
@@ -15,6 +15,7 @@ import { default as DeleteHandler } from "./Delete";
 import DomUtil from "../../Dom/Util";
 import * as Language from "../../Language";
 import Upload from "../../Upload";
+import { FileUploadHandler } from "./Data";
 
 interface FileUploadOptions extends UploadOptions {
   // image preview
@@ -41,7 +42,7 @@ interface AjaxResponse {
   files: FileData[];
 }
 
-class FileUpload extends Upload<FileUploadOptions> {
+class FileUpload extends Upload<FileUploadOptions> implements FileUploadHandler {
   protected readonly _deleteHandler: DeleteHandler;
 
   constructor(buttonContainerId: string, targetId: string, options: Partial<FileUploadOptions>) {