From 3a59150c36b0aa18c207f3c4f8d9e6180ea1d0eb Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 9 Dec 2020 17:35:02 +0100 Subject: [PATCH] Convert `Form/Builder/Field/User` to TypeScript --- .../Core/Form/Builder/Field/User.js | 53 +++++++++---------- .../Core/Form/Builder/Field/User.js | 40 -------------- .../Core/Form/Builder/Field/User.ts | 36 +++++++++++++ 3 files changed, 60 insertions(+), 69 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/User.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/User.ts diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/User.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/User.js index e60c22e5dc..aa4477d914 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/User.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/User.js @@ -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 - * @module WoltLabSuite/Core/Form/Builder/Field/User - * @since 5.2 + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @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 index 2cb81e1b8d..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/User.js +++ /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 - * @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 index 0000000000..70f419a978 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/User.ts @@ -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 + * @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; -- 2.20.1