Convert `Form/Builder/Field/Checked` to TypeScript
authorMatthias Schmidt <gravatronics@live.com>
Wed, 9 Dec 2020 16:33:42 +0000 (17:33 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 15 Dec 2020 17:23:05 +0000 (18:23 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Checked.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Checked.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Checked.ts [new file with mode: 0644]

index 090e3975fb5eac557577c117c8a50264fe6ac31e..112a4c8a9838fc45b1f6c2be5c499b5c3911f627 100644 (file)
@@ -2,30 +2,23 @@
  * Data handler for a form builder field in an Ajax form that stores its value via a checkbox being
  * checked or not.
  *
- * @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/Checked
- * @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/Checked
+ * @since 5.2
  */
-define(['Core', './Field'], function (Core, FormBuilderField) {
+define(["require", "exports", "tslib", "./Field", "../../../Core"], function (require, exports, tslib_1, Field_1, Core) {
     "use strict";
-    /**
-     * @constructor
-     */
-    function FormBuilderFieldInput(fieldId) {
-        this.init(fieldId);
-    }
-    ;
-    Core.inherit(FormBuilderFieldInput, FormBuilderField, {
-        /**
-         * @see        WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-         */
-        _getData: function () {
-            var data = {};
-            data[this._fieldId] = ~~this._field.checked;
-            return data;
+    Field_1 = tslib_1.__importDefault(Field_1);
+    Core = tslib_1.__importStar(Core);
+    class Checked extends Field_1.default {
+        _getData() {
+            return {
+                [this._fieldId]: this._field.checked ? "1" : "0",
+            };
         }
-    });
-    return FormBuilderFieldInput;
+    }
+    Core.enableLegacyInheritance(Checked);
+    return Checked;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Checked.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Checked.js
deleted file mode 100644 (file)
index 7673985..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Data handler for a form builder field in an Ajax form that stores its value via a checkbox being
- * checked or not.
- * 
- * @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/Checked
- * @since      5.2
- */
-define(['Core', './Field'], function(Core, FormBuilderField) {
-       "use strict";
-       
-       /**
-        * @constructor
-        */
-       function FormBuilderFieldInput(fieldId) {
-               this.init(fieldId);
-       };
-       Core.inherit(FormBuilderFieldInput, FormBuilderField, {
-               /**
-                * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-                */
-               _getData: function() {
-                       var data = {};
-                       
-                       data[this._fieldId] = ~~this._field.checked;
-                       
-                       return data;
-               }
-       });
-       
-       return FormBuilderFieldInput;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Checked.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Checked.ts
new file mode 100644 (file)
index 0000000..5f5bced
--- /dev/null
@@ -0,0 +1,26 @@
+/**
+ * Data handler for a form builder field in an Ajax form that stores its value via a checkbox being
+ * checked or not.
+ *
+ * @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/Checked
+ * @since 5.2
+ */
+
+import Field from "./Field";
+import { FormBuilderData } from "../Data";
+import * as Core from "../../../Core";
+
+class Checked extends Field {
+  protected _getData(): FormBuilderData {
+    return {
+      [this._fieldId]: (this._field as HTMLInputElement).checked ? "1" : "0",
+    };
+  }
+}
+
+Core.enableLegacyInheritance(Checked);
+
+export = Checked;