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

index 1a51f1f841456bdcc3dbafa23a001fcf1edf32bc..4871837882d73d11536d663cfc67067ebcb1e41a 100644 (file)
@@ -1,34 +1,27 @@
 /**
  * Data handler for a tag 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/Tag
- * @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/Tag
+ * @since 5.2
  */
-define(['Core', './Field', 'WoltLabSuite/Core/Ui/ItemList'], function (Core, FormBuilderField, UiItemList) {
+define(["require", "exports", "tslib", "./Field", "../../../Ui/ItemList", "../../../Core"], function (require, exports, tslib_1, Field_1, UiItemList, Core) {
     "use strict";
-    /**
-     * @constructor
-     */
-    function FormBuilderFieldTag(fieldId) {
-        this.init(fieldId);
-    }
-    ;
-    Core.inherit(FormBuilderFieldTag, FormBuilderField, {
-        /**
-         * @see        WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-         */
-        _getData: function () {
-            var data = {};
-            data[this._fieldId] = [];
-            var values = UiItemList.getValues(this._fieldId);
-            for (var i = 0, length = values.length; i < length; i++) {
-                data[this._fieldId].push(values[i].value);
-            }
-            return data;
+    Field_1 = tslib_1.__importDefault(Field_1);
+    UiItemList = tslib_1.__importStar(UiItemList);
+    Core = tslib_1.__importStar(Core);
+    class Tag extends Field_1.default {
+        _getData() {
+            const values = UiItemList.getValues(this._fieldId).map((item) => {
+                return item.value;
+            });
+            return {
+                [this._fieldId]: values,
+            };
         }
-    });
-    return FormBuilderFieldTag;
+    }
+    Core.enableLegacyInheritance(Tag);
+    return Tag;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.js
deleted file mode 100644 (file)
index a56bed9..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Data handler for a tag 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/Tag
- * @since      5.2
- */
-define(['Core', './Field', 'WoltLabSuite/Core/Ui/ItemList'], function(Core, FormBuilderField, UiItemList) {
-       "use strict";
-       
-       /**
-        * @constructor
-        */
-       function FormBuilderFieldTag(fieldId) {
-               this.init(fieldId);
-       };
-       Core.inherit(FormBuilderFieldTag, FormBuilderField, {
-               /**
-                * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-                */
-               _getData: function() {
-                       var data = {};
-                       data[this._fieldId] = [];
-                       
-                       var values = UiItemList.getValues(this._fieldId);
-                       for (var i = 0, length = values.length; i < length; i++) {
-                               data[this._fieldId].push(values[i].value);
-                       }
-                       
-                       return data;
-               }
-       });
-       
-       return FormBuilderFieldTag;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.ts
new file mode 100644 (file)
index 0000000..cee036e
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+ * Data handler for a tag 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/Tag
+ * @since 5.2
+ */
+
+import Field from "./Field";
+import * as UiItemList from "../../../Ui/ItemList";
+import { FormBuilderData } from "../Data";
+import * as Core from "../../../Core";
+
+class Tag extends Field {
+  protected _getData(): FormBuilderData {
+    const values: string[] = UiItemList.getValues(this._fieldId).map((item) => {
+      return item.value;
+    });
+
+    return {
+      [this._fieldId]: values,
+    };
+  }
+}
+
+Core.enableLegacyInheritance(Tag);
+
+export = Tag;