/**
* 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;
});
+++ /dev/null
-/**
- * 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;
-});
--- /dev/null
+/**
+ * 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;