From: Matthias Schmidt Date: Sat, 12 Dec 2020 15:03:25 +0000 (+0100) Subject: Convert `Form/Builder/Field/Dependency/Container/Abstract` to TypeScript X-Git-Tag: 5.4.0_Alpha_1~526^2~14 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=68f339261e2198a1a2358a0a2f16f8b0b54c3504;p=GitHub%2FWoltLab%2FWCF.git Convert `Form/Builder/Field/Dependency/Container/Abstract` to TypeScript --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.js index a2ed5c508f..8bcbe8a5e0 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.js @@ -2,49 +2,40 @@ * Abstract implementation of a handler for the visibility of container due the dependencies * of its children. * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract - * @since 5.2 + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract + * @since 5.2 */ -define(['EventHandler', '../Manager'], function (EventHandler, DependencyManager) { +define(["require", "exports", "tslib", "../Manager", "../../../../../Core"], function (require, exports, tslib_1, Manager_1, Core) { "use strict"; - /** - * @constructor - */ - function Abstract(containerId) { - this.init(containerId); - } - ; - Abstract.prototype = { + Manager_1 = tslib_1.__importDefault(Manager_1); + Core = tslib_1.__importStar(Core); + class Abstract { + constructor(containerId) { + this.init(containerId); + } /** - * Checks if the container should be visible and shows or hides it accordingly. - * - * @abstract + * Returns `true` if the dependency is met and thus if the container should be shown. */ - checkContainer: function () { + checkContainer() { throw new Error("Missing implementation of WoltLabSuite/Core/Form/Builder/Field/Dependency/Container.checkContainer!"); - }, + } /** - * Initializes a new container dependency handler for the container with the given - * id. - * - * @param {string} containerId id of the handled container - * - * @throws {TypeError} if container id is no string - * @throws {Error} if container id is invalid + * Initializes a new container dependency handler for the container with the given id. */ - init: function (containerId) { - if (typeof containerId !== 'string') { + init(containerId) { + if (typeof containerId !== "string") { throw new TypeError("Container id has to be a string."); } - this._container = elById(containerId); + this._container = document.getElementById(containerId); if (this._container === null) { throw new Error("Unknown container with id '" + containerId + "'."); } - DependencyManager.addContainerCheckCallback(this.checkContainer.bind(this)); + Manager_1.default.addContainerCheckCallback(() => this.checkContainer()); } - }; + } + Core.enableLegacyInheritance(Abstract); return Abstract; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.js deleted file mode 100644 index 0f04ad90a1..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Abstract implementation of a handler for the visibility of container due the dependencies - * of its children. - * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract - * @since 5.2 - */ -define(['EventHandler', '../Manager'], function(EventHandler, DependencyManager) { - "use strict"; - - /** - * @constructor - */ - function Abstract(containerId) { - this.init(containerId); - }; - Abstract.prototype = { - /** - * Checks if the container should be visible and shows or hides it accordingly. - * - * @abstract - */ - checkContainer: function() { - throw new Error("Missing implementation of WoltLabSuite/Core/Form/Builder/Field/Dependency/Container.checkContainer!"); - }, - - /** - * Initializes a new container dependency handler for the container with the given - * id. - * - * @param {string} containerId id of the handled container - * - * @throws {TypeError} if container id is no string - * @throws {Error} if container id is invalid - */ - init: function(containerId) { - if (typeof containerId !== 'string') { - throw new TypeError("Container id has to be a string."); - } - - this._container = elById(containerId); - if (this._container === null) { - throw new Error("Unknown container with id '" + containerId + "'."); - } - - DependencyManager.addContainerCheckCallback(this.checkContainer.bind(this)); - } - }; - - return Abstract -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.ts new file mode 100644 index 0000000000..e706d363e6 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.ts @@ -0,0 +1,50 @@ +/** + * Abstract implementation of a handler for the visibility of container due the dependencies + * of its children. + * + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract + * @since 5.2 + */ + +import DependencyManager from "../Manager"; +import * as Core from "../../../../../Core"; + +class Abstract { + protected _container: HTMLElement; + + constructor(containerId: string) { + this.init(containerId); + } + + /** + * Returns `true` if the dependency is met and thus if the container should be shown. + */ + public checkContainer(): void { + throw new Error( + "Missing implementation of WoltLabSuite/Core/Form/Builder/Field/Dependency/Container.checkContainer!", + ); + } + + /** + * Initializes a new container dependency handler for the container with the given id. + */ + protected init(containerId: string): void { + if (typeof containerId !== "string") { + throw new TypeError("Container id has to be a string."); + } + + this._container = document.getElementById(containerId)!; + if (this._container === null) { + throw new Error("Unknown container with id '" + containerId + "'."); + } + + DependencyManager.addContainerCheckCallback(() => this.checkContainer()); + } +} + +Core.enableLegacyInheritance(Abstract); + +export = Abstract;