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

index 731c508b5e751e7528adad6035e46e0c77402585..7932459c8705e53ceab47394ade3dd0ab362d8d2 100644 (file)
@@ -1,47 +1,22 @@
-/**
- * Data handler for a simple acl 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/SimpleAcl
- * @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 FormBuilderFieldSimpleAcl(fieldId) {
-        this.init(fieldId);
-    }
-    ;
-    Core.inherit(FormBuilderFieldSimpleAcl, FormBuilderField, {
-        /**
-         * @see        WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-         */
-        _getData: function () {
-            var groupIds = [];
-            elBySelAll('input[name="' + this._fieldId + '[group][]"]', undefined, function (input) {
-                groupIds.push(~~input.value);
-            });
-            var usersIds = [];
-            elBySelAll('input[name="' + this._fieldId + '[user][]"]', undefined, function (input) {
-                usersIds.push(~~input.value);
-            });
-            var data = {};
-            data[this._fieldId] = {
-                group: groupIds,
-                user: usersIds
+    Field_1 = tslib_1.__importDefault(Field_1);
+    Core = tslib_1.__importStar(Core);
+    class SimpleAcl extends Field_1.default {
+        _getData() {
+            const groupIds = Array.from(document.querySelectorAll('input[name="' + this._fieldId + '[group][]"]')).map((input) => input.value);
+            const usersIds = Array.from(document.querySelectorAll('input[name="' + this._fieldId + '[user][]"]')).map((input) => input.value);
+            return {
+                [this._fieldId]: {
+                    group: groupIds,
+                    user: usersIds,
+                },
             };
-            return data;
-        },
-        /**
-         * @see        WoltLabSuite/Core/Form/Builder/Field/Field#_readField
-         */
-        _readField: function () {
+        }
+        _readField() {
             // does nothing
         }
-    });
-    return FormBuilderFieldSimpleAcl;
+    }
+    Core.enableLegacyInheritance(SimpleAcl);
+    return SimpleAcl;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.js
deleted file mode 100644 (file)
index 2da8625..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Data handler for a simple acl 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/SimpleAcl
- * @since      5.2
- */
-define(['Core', './Field'], function(Core, FormBuilderField) {
-       "use strict";
-       
-       /**
-        * @constructor
-        */
-       function FormBuilderFieldSimpleAcl(fieldId) {
-               this.init(fieldId);
-       };
-       Core.inherit(FormBuilderFieldSimpleAcl, FormBuilderField, {
-               /**
-                * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData
-                */
-               _getData: function() {
-                       var groupIds = [];
-                       elBySelAll('input[name="' + this._fieldId + '[group][]"]', undefined, function(input) {
-                               groupIds.push(~~input.value);
-                       });
-                       
-                       var usersIds = [];
-                       elBySelAll('input[name="' + this._fieldId + '[user][]"]', undefined, function(input) {
-                               usersIds.push(~~input.value);
-                       });
-                       
-                       var data = {};
-                       
-                       data[this._fieldId] = {
-                               group: groupIds,
-                               user: usersIds
-                       };
-                       
-                       return data;
-               },
-               
-               /**
-                * @see WoltLabSuite/Core/Form/Builder/Field/Field#_readField
-                */
-               _readField: function() {
-                       // does nothing
-               }
-       });
-       
-       return FormBuilderFieldSimpleAcl;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.ts
new file mode 100644 (file)
index 0000000..0eb2226
--- /dev/null
@@ -0,0 +1,30 @@
+import Field from "./Field";
+import { FormBuilderData } from "../Data";
+import * as Core from "../../../Core";
+
+class SimpleAcl extends Field {
+  protected _getData(): FormBuilderData {
+    const groupIds = Array.from(document.querySelectorAll('input[name="' + this._fieldId + '[group][]"]')).map(
+      (input: HTMLInputElement) => input.value,
+    );
+
+    const usersIds = Array.from(document.querySelectorAll('input[name="' + this._fieldId + '[user][]"]')).map(
+      (input: HTMLInputElement) => input.value,
+    );
+
+    return {
+      [this._fieldId]: {
+        group: groupIds,
+        user: usersIds,
+      },
+    };
+  }
+
+  protected _readField(): void {
+    // does nothing
+  }
+}
+
+Core.enableLegacyInheritance(SimpleAcl);
+
+export = SimpleAcl;