Convert `Form/Builder/Field/RadioButton` to TypeScript
authorMatthias Schmidt <gravatronics@live.com>
Wed, 9 Dec 2020 16:34:32 +0000 (17:34 +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/RadioButton.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/RadioButton.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/RadioButton.ts [new file with mode: 0644]

index 86c47e1f021c546931f70a6564cd994b30a825db..d647b149be17a2255c48bf1835d453c1856665bd 100644 (file)
@@ -1,41 +1,31 @@
 /**
  * Data handler for a radio button form builder field in an Ajax form.
  *
- * @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/RadioButton
- * @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/RadioButton
+ * @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 FormBuilderFieldRadioButton(fieldId) {
-        this.init(fieldId);
-    }
-    ;
-    Core.inherit(FormBuilderFieldRadioButton, FormBuilderField, {
-        /**
-         * @see        WoltLabSuite/Core/Form/Builder/Field/Field#getData
-         */
-        _getData: function () {
-            var data = {};
-            for (var i = 0, length = this._fields.length; i < length; i++) {
-                if (this._fields[i].checked) {
-                    data[this._fieldId] = this._fields[i].value;
-                    break;
+    Field_1 = tslib_1.__importDefault(Field_1);
+    Core = tslib_1.__importStar(Core);
+    class RadioButton extends Field_1.default {
+        _getData() {
+            const data = {};
+            this._fields.some((input) => {
+                if (input.checked) {
+                    data[this._fieldId] = input.value;
+                    return true;
                 }
-            }
+            });
             return data;
-        },
-        /**
-         * @see        WoltLabSuite/Core/Form/Builder/Field/Field#_readField
-         */
-        _readField: function () {
-            this._fields = elBySelAll('input[name=' + this._fieldId + ']');
-        },
-    });
-    return FormBuilderFieldRadioButton;
+        }
+        _readField() {
+            this._fields = Array.from(document.querySelectorAll("input[name=" + this._fieldId + "]"));
+        }
+    }
+    Core.enableLegacyInheritance(RadioButton);
+    return RadioButton;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/RadioButton.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/RadioButton.js
deleted file mode 100644 (file)
index b08f6b6..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Data handler for a radio button form builder field in an Ajax form.
- * 
- * @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/RadioButton
- * @since      5.2
- */
-define(['Core', './Field'], function(Core, FormBuilderField) {
-       "use strict";
-
-       /**
-        * @constructor
-        */
-       function FormBuilderFieldRadioButton(fieldId) {
-               this.init(fieldId);
-       };
-       Core.inherit(FormBuilderFieldRadioButton, FormBuilderField, {
-               /**
-                * @see WoltLabSuite/Core/Form/Builder/Field/Field#getData
-                */
-               _getData: function() {
-                       var data = {};
-                       
-                       for (var i = 0, length = this._fields.length; i < length; i++) {
-                               if (this._fields[i].checked) {
-                                       data[this._fieldId] = this._fields[i].value;
-                                       break;
-                               }
-                       }
-                       
-                       return data;
-               },
-               
-               /**
-                * @see WoltLabSuite/Core/Form/Builder/Field/Field#_readField
-                */
-               _readField: function() {
-                       this._fields = elBySelAll('input[name=' + this._fieldId + ']');
-               },
-       });
-       
-       return FormBuilderFieldRadioButton;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/RadioButton.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/RadioButton.ts
new file mode 100644 (file)
index 0000000..be54ac8
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * Data handler for a radio button form builder field in an Ajax form.
+ *
+ * @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/RadioButton
+ * @since 5.2
+ */
+
+import Field from "./Field";
+import { FormBuilderData } from "../Data";
+import * as Core from "../../../Core";
+
+class RadioButton extends Field {
+  protected _fields: HTMLInputElement[];
+
+  protected _getData(): FormBuilderData {
+    const data = {};
+
+    this._fields.some((input) => {
+      if (input.checked) {
+        data[this._fieldId] = input.value;
+        return true;
+      }
+    });
+
+    return data;
+  }
+
+  protected _readField(): void {
+    this._fields = Array.from(document.querySelectorAll("input[name=" + this._fieldId + "]"));
+  }
+}
+
+Core.enableLegacyInheritance(RadioButton);
+
+export = RadioButton;