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

index 0ba161c10c5c554d17f35168fc760ec7e1ff2023..cda3db4aa31a082b04797a55c55d781b10a461f8 100644 (file)
@@ -1,39 +1,33 @@
 /**
  * Data handler for an item list 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/ItemList
- * @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/ItemList
+ * @since 5.2
  */
-define(['Core', './Field', 'WoltLabSuite/Core/Ui/ItemList/Static'], function (Core, FormBuilderField, UiItemListStatic) {
+define(["require", "exports", "tslib", "./Field", "../../../Ui/ItemList/Static", "../../../Core"], function (require, exports, tslib_1, Field_1, UiItemListStatic, Core) {
     "use strict";
-    /**
-     * @constructor
-     */
-    function FormBuilderFieldItemList(fieldId) {
-        this.init(fieldId);
-    }
-    ;
-    Core.inherit(FormBuilderFieldItemList, FormBuilderField, {
-        /**
-         * @see        WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-         */
-        _getData: function () {
-            var data = {};
-            data[this._fieldId] = [];
-            var values = UiItemListStatic.getValues(this._fieldId);
-            for (var i = 0, length = values.length; i < length; i++) {
-                if (values[i].objectId) {
-                    data[this._fieldId][values[i].objectId] = values[i].value;
+    Field_1 = tslib_1.__importDefault(Field_1);
+    UiItemListStatic = tslib_1.__importStar(UiItemListStatic);
+    Core = tslib_1.__importStar(Core);
+    class ItemList extends Field_1.default {
+        _getData() {
+            const values = [];
+            UiItemListStatic.getValues(this._fieldId).forEach((item) => {
+                if (item.objectId) {
+                    values[item.objectId] = item.value;
                 }
                 else {
-                    data[this._fieldId].push(values[i].value);
+                    values.push(item.value);
                 }
-            }
-            return data;
+            });
+            return {
+                [this._fieldId]: values,
+            };
         }
-    });
-    return FormBuilderFieldItemList;
+    }
+    Core.enableLegacyInheritance(ItemList);
+    return ItemList;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ItemList.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ItemList.js
deleted file mode 100644 (file)
index 3e16e6a..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Data handler for an item list 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/ItemList
- * @since      5.2
- */
-define(['Core', './Field', 'WoltLabSuite/Core/Ui/ItemList/Static'], function(Core, FormBuilderField, UiItemListStatic) {
-       "use strict";
-       
-       /**
-        * @constructor
-        */
-       function FormBuilderFieldItemList(fieldId) {
-               this.init(fieldId);
-       };
-       Core.inherit(FormBuilderFieldItemList, FormBuilderField, {
-               /**
-                * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-                */
-               _getData: function() {
-                       var data = {};
-                       data[this._fieldId] = [];
-                       
-                       var values = UiItemListStatic.getValues(this._fieldId);
-                       for (var i = 0, length = values.length; i < length; i++) {
-                               if (values[i].objectId) {
-                                       data[this._fieldId][values[i].objectId] = values[i].value;
-                               }
-                               else {
-                                       data[this._fieldId].push(values[i].value);
-                               }
-                       }
-                       
-                       return data;
-               }
-       });
-       
-       return FormBuilderFieldItemList;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ItemList.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ItemList.ts
new file mode 100644 (file)
index 0000000..e83c501
--- /dev/null
@@ -0,0 +1,35 @@
+/**
+ * Data handler for an item list 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/ItemList
+ * @since 5.2
+ */
+
+import Field from "./Field";
+import * as UiItemListStatic from "../../../Ui/ItemList/Static";
+import { FormBuilderData } from "../Data";
+import * as Core from "../../../Core";
+
+class ItemList extends Field {
+  protected _getData(): FormBuilderData {
+    const values: string[] = [];
+    UiItemListStatic.getValues(this._fieldId).forEach((item) => {
+      if (item.objectId) {
+        values[item.objectId] = item.value;
+      } else {
+        values.push(item.value);
+      }
+    });
+
+    return {
+      [this._fieldId]: values,
+    };
+  }
+}
+
+Core.enableLegacyInheritance(ItemList);
+
+export = ItemList;