Convert `Ui/User/Search/Input` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Tue, 27 Oct 2020 11:00:23 +0000 (12:00 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 28 Oct 2020 11:57:21 +0000 (12:57 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Search/Input.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Search/Input.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Search/Input.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Search/Input.ts [new file with mode: 0644]

index 7926bd0f7f64119f8e066f1cfdf4f4aa0e148bf3..45fe279454cb2c2b80e365f4d7f2db3fc36ded02 100644 (file)
@@ -1,45 +1,63 @@
 /**
  * Provides suggestions for users, optionally supporting groups.
  *
- * @author     Alexander Ebert
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Ui/User/Search/Input
- * @see         module:WoltLabSuite/Core/Ui/Search/Input
+ * @author  Alexander Ebert
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Ui/User/Search/Input
+ * @see  module:WoltLabSuite/Core/Ui/Search/Input
  */
-define(['Core', 'WoltLabSuite/Core/Ui/Search/Input'], function (Core, UiSearchInput) {
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
+}) : (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    o[k2] = m[k];
+}));
+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
+    Object.defineProperty(o, "default", { enumerable: true, value: v });
+}) : function(o, v) {
+    o["default"] = v;
+});
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
+    __setModuleDefault(result, mod);
+    return result;
+};
+var __importDefault = (this && this.__importDefault) || function (mod) {
+    return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+define(["require", "exports", "../../../Core", "../../Search/Input"], function (require, exports, Core, Input_1) {
     "use strict";
-    /**
-     * @param       {Element}       element         input element
-     * @param       {Object=}       options         search options and settings
-     * @constructor
-     */
-    function UiUserSearchInput(element, options) { this.init(element, options); }
-    Core.inherit(UiUserSearchInput, UiSearchInput, {
-        init: function (element, options) {
-            var includeUserGroups = (Core.isPlainObject(options) && options.includeUserGroups === true);
+    Core = __importStar(Core);
+    Input_1 = __importDefault(Input_1);
+    class UiUserSearchInput extends Input_1.default {
+        constructor(element, options) {
+            const includeUserGroups = (Core.isPlainObject(options) && options.includeUserGroups === true);
             options = Core.extend({
                 ajax: {
                     className: 'wcf\\data\\user\\UserAction',
                     parameters: {
                         data: {
-                            includeUserGroups: (includeUserGroups ? 1 : 0)
-                        }
-                    }
-                }
+                            includeUserGroups: (includeUserGroups ? 1 : 0),
+                        },
+                    },
+                },
             }, options);
-            UiUserSearchInput._super.prototype.init.call(this, element, options);
-        },
-        _createListItem: function (item) {
-            var listItem = UiUserSearchInput._super.prototype._createListItem.call(this, item);
-            elData(listItem, 'type', item.type);
-            var box = elCreate('div');
+            super(element, options);
+        }
+        createListItem(item) {
+            const listItem = super.createListItem(item);
+            listItem.dataset.type = item.type;
+            const box = document.createElement('div');
             box.className = 'box16';
             box.innerHTML = (item.type === 'group') ? '<span class="icon icon16 fa-users"></span>' : item.icon;
             box.appendChild(listItem.children[0]);
             listItem.appendChild(box);
             return listItem;
         }
-    });
+    }
     return UiUserSearchInput;
 });
index c6833afbfd36bbe5ccac2652a536607173fa2891..94cde1b080a3e5ea507d75e66dccff678d748eca 100644 (file)
@@ -343,7 +343,7 @@ class UiSearchInput {
   /**
    * Creates an list item from response data.
    */
-  private createListItem(item: ListItemData): HTMLLIElement {
+  protected createListItem(item: ListItemData): HTMLLIElement {
     const listItem = document.createElement('li');
     listItem.dataset.objectId = item.objectID.toString();
     listItem.dataset.label = item.label;
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Search/Input.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Search/Input.js
deleted file mode 100644 (file)
index 2bea665..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Provides suggestions for users, optionally supporting groups.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Ui/User/Search/Input
- * @see         module:WoltLabSuite/Core/Ui/Search/Input
- */
-define(['Core', 'WoltLabSuite/Core/Ui/Search/Input'], function(Core, UiSearchInput) {
-       "use strict";
-       
-       /**
-        * @param       {Element}       element         input element
-        * @param       {Object=}       options         search options and settings
-        * @constructor
-        */
-       function UiUserSearchInput(element, options) { this.init(element, options); }
-       Core.inherit(UiUserSearchInput, UiSearchInput, {
-               init: function(element, options) {
-                       var includeUserGroups = (Core.isPlainObject(options) && options.includeUserGroups === true);
-                       
-                       options = Core.extend({
-                               ajax: {
-                                       className: 'wcf\\data\\user\\UserAction',
-                                       parameters: {
-                                               data: {
-                                                       includeUserGroups: (includeUserGroups ? 1 : 0)
-                                               }
-                                       }
-                               }
-                       }, options);
-                       
-                       UiUserSearchInput._super.prototype.init.call(this, element, options);
-               },
-               
-               _createListItem: function(item) {
-                       var listItem = UiUserSearchInput._super.prototype._createListItem.call(this, item);
-                       elData(listItem, 'type', item.type);
-                       
-                       var box = elCreate('div');
-                       box.className = 'box16';
-                       box.innerHTML = (item.type === 'group') ? '<span class="icon icon16 fa-users"></span>' : item.icon;
-                       box.appendChild(listItem.children[0]);
-                       listItem.appendChild(box);
-                       
-                       return listItem;
-               }
-       });
-       
-       return UiUserSearchInput;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Search/Input.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Search/Input.ts
new file mode 100644 (file)
index 0000000..28e0180
--- /dev/null
@@ -0,0 +1,46 @@
+/**
+ * Provides suggestions for users, optionally supporting groups.
+ *
+ * @author  Alexander Ebert
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Ui/User/Search/Input
+ * @see  module:WoltLabSuite/Core/Ui/Search/Input
+ */
+
+import * as Core from '../../../Core';
+import UiSearchInput from '../../Search/Input';
+
+class UiUserSearchInput extends UiSearchInput {
+  constructor(element, options) {
+    const includeUserGroups = (Core.isPlainObject(options) && options.includeUserGroups === true);
+
+    options = Core.extend({
+      ajax: {
+        className: 'wcf\\data\\user\\UserAction',
+        parameters: {
+          data: {
+            includeUserGroups: (includeUserGroups ? 1 : 0),
+          },
+        },
+      },
+    }, options);
+
+    super(element, options);
+  }
+
+  protected createListItem(item): HTMLLIElement {
+    const listItem = super.createListItem(item);
+    listItem.dataset.type = item.type;
+
+    const box = document.createElement('div');
+    box.className = 'box16';
+    box.innerHTML = (item.type === 'group') ? '<span class="icon icon16 fa-users"></span>' : item.icon;
+    box.appendChild(listItem.children[0]);
+    listItem.appendChild(box);
+
+    return listItem;
+  }
+}
+
+export = UiUserSearchInput