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

index 47fd951abfe7d719265f7b1f7205bb7fc02ed858..b11f77865181f96888eb02ed22c4161989e45f1e 100644 (file)
@@ -2,42 +2,35 @@
  * Data handler for an i18n form builder field in an Ajax form that stores its value in an input's
  * value attribute.
  *
- * @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/ValueI18n
- * @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/ValueI18n
+ * @since 5.2
  */
-define(['Core', './Field', 'WoltLabSuite/Core/Language/Input'], function (Core, FormBuilderField, LanguageInput) {
+define(["require", "exports", "tslib", "./Field", "../../../Language/Input", "../../../Core"], function (require, exports, tslib_1, Field_1, LanguageInput, Core) {
     "use strict";
-    /**
-     * @constructor
-     */
-    function FormBuilderFieldValueI18n(fieldId) {
-        this.init(fieldId);
-    }
-    ;
-    Core.inherit(FormBuilderFieldValueI18n, FormBuilderField, {
-        /**
-         * @see        WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-         */
-        _getData: function () {
-            var data = {};
-            var values = LanguageInput.getValues(this._fieldId);
+    Field_1 = tslib_1.__importDefault(Field_1);
+    LanguageInput = tslib_1.__importStar(LanguageInput);
+    Core = tslib_1.__importStar(Core);
+    class ValueI18n extends Field_1.default {
+        _getData() {
+            const data = {};
+            const values = LanguageInput.getValues(this._fieldId);
             if (values.size > 1) {
-                data[this._fieldId + '_i18n'] = values.toObject();
+                values.forEach((value, key) => {
+                    data[this._fieldId + "_i18n"][key] = value;
+                });
             }
             else {
                 data[this._fieldId] = values.get(0);
             }
             return data;
-        },
-        /**
-         * @see        WoltLabSuite/Core/Form/Builder/Field/Field#destroy
-         */
-        destroy: function () {
+        }
+        destroy() {
             LanguageInput.unregister(this._fieldId);
         }
-    });
-    return FormBuilderFieldValueI18n;
+    }
+    Core.enableLegacyInheritance(ValueI18n);
+    return ValueI18n;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js
deleted file mode 100644 (file)
index 7aceb81..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Data handler for an i18n form builder field in an Ajax form that stores its value in an input's
- * value attribute.
- * 
- * @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/ValueI18n
- * @since      5.2
- */
-define(['Core', './Field', 'WoltLabSuite/Core/Language/Input'], function(Core, FormBuilderField, LanguageInput) {
-       "use strict";
-       
-       /**
-        * @constructor
-        */
-       function FormBuilderFieldValueI18n(fieldId) {
-               this.init(fieldId);
-       };
-       Core.inherit(FormBuilderFieldValueI18n, FormBuilderField, {
-               /**
-                * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-                */
-               _getData: function() {
-                       var data = {};
-                       
-                       var values = LanguageInput.getValues(this._fieldId);
-                       if (values.size > 1) {
-                               data[this._fieldId + '_i18n'] = values.toObject();
-                       }
-                       else {
-                               data[this._fieldId] = values.get(0);
-                       }
-                       
-                       return data;
-               },
-               
-               /**
-                * @see WoltLabSuite/Core/Form/Builder/Field/Field#destroy
-                */
-               destroy: function() {
-                       LanguageInput.unregister(this._fieldId);
-               }
-       });
-       
-       return FormBuilderFieldValueI18n;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.ts
new file mode 100644 (file)
index 0000000..8cafa4b
--- /dev/null
@@ -0,0 +1,40 @@
+/**
+ * Data handler for an i18n form builder field in an Ajax form that stores its value in an input's
+ * value attribute.
+ *
+ * @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/ValueI18n
+ * @since 5.2
+ */
+
+import Field from "./Field";
+import { FormBuilderData } from "../Data";
+import * as LanguageInput from "../../../Language/Input";
+import * as Core from "../../../Core";
+
+class ValueI18n extends Field {
+  protected _getData(): FormBuilderData {
+    const data = {};
+
+    const values = LanguageInput.getValues(this._fieldId);
+    if (values.size > 1) {
+      values.forEach((value, key) => {
+        data[this._fieldId + "_i18n"][key] = value;
+      });
+    } else {
+      data[this._fieldId] = values.get(0);
+    }
+
+    return data;
+  }
+
+  destroy(): void {
+    LanguageInput.unregister(this._fieldId);
+  }
+}
+
+Core.enableLegacyInheritance(ValueI18n);
+
+export = ValueI18n;