From 0de19c72a24301fc64fe06bb8502e0bab24c532d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 28 Nov 2020 16:15:26 +0100 Subject: [PATCH] Introduce a helper interface for the FileUpload class This interface prevents a circular dependency of the modules `./Delete` and `./Upload`. --- .../files/js/WoltLabSuite/Core/Ui/File/Data.js | 6 ++++++ .../files/js/WoltLabSuite/Core/Ui/File/Delete.js | 1 - .../files/ts/WoltLabSuite/Core/Ui/File/Data.ts | 6 ++++++ .../files/ts/WoltLabSuite/Core/Ui/File/Delete.ts | 14 +++++++++----- .../files/ts/WoltLabSuite/Core/Ui/File/Upload.ts | 3 ++- 5 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Data.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Data.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 index 0000000000..e00a67fe65 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Data.js @@ -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 }); +}); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Delete.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Delete.js index 2fc93f647c..b1eeea363f 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Delete.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Delete.js @@ -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 index 0000000000..c13af33735 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Data.ts @@ -0,0 +1,6 @@ +// This helper interface exists to prevent a circular dependency +// between `./Delete` and `./Upload` + +export interface FileUploadHandler { + checkMaxFiles(): void; +} diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Delete.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Delete.ts index c1a96cd3eb..e973743f91 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Delete.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Delete.ts @@ -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; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Upload.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Upload.ts index dd814439fb..d8ab9f7d04 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Upload.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/File/Upload.ts @@ -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 { +class FileUpload extends Upload implements FileUploadHandler { protected readonly _deleteHandler: DeleteHandler; constructor(buttonContainerId: string, targetId: string, options: Partial) { -- 2.20.1