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

index e60c22e5dc9e92eedd0b36925774b9eeb1b65d0a..aa4477d9149f93fb5a95618c44bb37d1c3175c01 100644 (file)
@@ -1,37 +1,32 @@
 /**
  * Data handler for a user 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/User
- * @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/User
+ * @since 5.2
  */
-define(['Core', './Field', 'WoltLabSuite/Core/Ui/ItemList'], function (Core, FormBuilderField, UiItemList) {
+define(["require", "exports", "tslib", "./Field", "../../../Core", "../../../Ui/ItemList/Static"], function (require, exports, tslib_1, Field_1, Core, UiItemList) {
     "use strict";
-    /**
-     * @constructor
-     */
-    function FormBuilderFieldUser(fieldId) {
-        this.init(fieldId);
-    }
-    ;
-    Core.inherit(FormBuilderFieldUser, FormBuilderField, {
-        /**
-         * @see        WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-         */
-        _getData: function () {
-            var values = UiItemList.getValues(this._fieldId);
-            var usernames = [];
-            for (var i = 0, length = values.length; i < length; i++) {
-                if (values[i].objectId) {
-                    usernames.push(values[i].value);
+    Field_1 = tslib_1.__importDefault(Field_1);
+    Core = tslib_1.__importStar(Core);
+    UiItemList = tslib_1.__importStar(UiItemList);
+    class User extends Field_1.default {
+        _getData() {
+            const usernames = UiItemList.getValues(this._fieldId)
+                .map((item) => {
+                if (item.objectId) {
+                    return item.value;
                 }
-            }
-            var data = {};
-            data[this._fieldId] = usernames.join(',');
-            return data;
+                return null;
+            })
+                .filter((v) => v !== null);
+            return {
+                [this._fieldId]: usernames.join(","),
+            };
         }
-    });
-    return FormBuilderFieldUser;
+    }
+    Core.enableLegacyInheritance(User);
+    return User;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/User.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/User.js
deleted file mode 100644 (file)
index 2cb81e1..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Data handler for a user 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/User
- * @since      5.2
- */
-define(['Core', './Field', 'WoltLabSuite/Core/Ui/ItemList'], function(Core, FormBuilderField, UiItemList) {
-       "use strict";
-       
-       /**
-        * @constructor
-        */
-       function FormBuilderFieldUser(fieldId) {
-               this.init(fieldId);
-       };
-       Core.inherit(FormBuilderFieldUser, FormBuilderField, {
-               /**
-                * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-                */
-               _getData: function() {
-                       var values = UiItemList.getValues(this._fieldId);
-                       var usernames = [];
-                       for (var i = 0, length = values.length; i < length; i++) {
-                               if (values[i].objectId) {
-                                       usernames.push(values[i].value);
-                               }
-                       }
-                       
-                       var data = {};
-                       data[this._fieldId] = usernames.join(',');
-                       
-                       return data;
-               }
-       });
-       
-       return FormBuilderFieldUser;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/User.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/User.ts
new file mode 100644 (file)
index 0000000..70f419a
--- /dev/null
@@ -0,0 +1,36 @@
+/**
+ * Data handler for a user 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/User
+ * @since 5.2
+ */
+
+import Field from "./Field";
+import { FormBuilderData } from "../Data";
+import * as Core from "../../../Core";
+import * as UiItemList from "../../../Ui/ItemList/Static";
+
+class User extends Field {
+  protected _getData(): FormBuilderData {
+    const usernames = UiItemList.getValues(this._fieldId)
+      .map((item) => {
+        if (item.objectId) {
+          return item.value;
+        }
+
+        return null;
+      })
+      .filter((v) => v !== null) as string[];
+
+    return {
+      [this._fieldId]: usernames.join(","),
+    };
+  }
+}
+
+Core.enableLegacyInheritance(User);
+
+export = User;