Convert `Form/Builder/Field/Dependency/Container/Abstract` to TypeScript
authorMatthias Schmidt <gravatronics@live.com>
Sat, 12 Dec 2020 15:03:25 +0000 (16:03 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 15 Dec 2020 17:23:06 +0000 (18:23 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Abstract.ts [new file with mode: 0644]

index a2ed5c508f6706aa8876c8071e4be82c5b819ca7..8bcbe8a5e08c14a63c3d26737ecf38c63c8f3de9 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
- * @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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 0f04ad9..0000000
+++ /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 <http://opensource.org/licenses/lgpl-license.php>
- * @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 (file)
index 0000000..e706d36
--- /dev/null
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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;