From: Matthias Schmidt Date: Wed, 9 Dec 2020 16:34:22 +0000 (+0100) Subject: Convert `Form/Builder/Field/ItemList` to TypeScript X-Git-Tag: 5.4.0_Alpha_1~526^2~29 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=856aa7fdd85e056955545405f23fbeaca07999da;p=GitHub%2FWoltLab%2FWCF.git Convert `Form/Builder/Field/ItemList` to TypeScript --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ItemList.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ItemList.js index 0ba161c10c..cda3db4aa3 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ItemList.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ItemList.js @@ -1,39 +1,33 @@ /** * Data handler for an item list 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/ItemList - * @since 5.2 + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Form/Builder/Field/ItemList + * @since 5.2 */ -define(['Core', './Field', 'WoltLabSuite/Core/Ui/ItemList/Static'], function (Core, FormBuilderField, UiItemListStatic) { +define(["require", "exports", "tslib", "./Field", "../../../Ui/ItemList/Static", "../../../Core"], function (require, exports, tslib_1, Field_1, UiItemListStatic, Core) { "use strict"; - /** - * @constructor - */ - function FormBuilderFieldItemList(fieldId) { - this.init(fieldId); - } - ; - Core.inherit(FormBuilderFieldItemList, FormBuilderField, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData - */ - _getData: function () { - var data = {}; - data[this._fieldId] = []; - var values = UiItemListStatic.getValues(this._fieldId); - for (var i = 0, length = values.length; i < length; i++) { - if (values[i].objectId) { - data[this._fieldId][values[i].objectId] = values[i].value; + Field_1 = tslib_1.__importDefault(Field_1); + UiItemListStatic = tslib_1.__importStar(UiItemListStatic); + Core = tslib_1.__importStar(Core); + class ItemList extends Field_1.default { + _getData() { + const values = []; + UiItemListStatic.getValues(this._fieldId).forEach((item) => { + if (item.objectId) { + values[item.objectId] = item.value; } else { - data[this._fieldId].push(values[i].value); + values.push(item.value); } - } - return data; + }); + return { + [this._fieldId]: values, + }; } - }); - return FormBuilderFieldItemList; + } + Core.enableLegacyInheritance(ItemList); + return ItemList; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ItemList.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ItemList.js deleted file mode 100644 index 3e16e6a3df..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ItemList.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Data handler for an item list 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/ItemList - * @since 5.2 - */ -define(['Core', './Field', 'WoltLabSuite/Core/Ui/ItemList/Static'], function(Core, FormBuilderField, UiItemListStatic) { - "use strict"; - - /** - * @constructor - */ - function FormBuilderFieldItemList(fieldId) { - this.init(fieldId); - }; - Core.inherit(FormBuilderFieldItemList, FormBuilderField, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData - */ - _getData: function() { - var data = {}; - data[this._fieldId] = []; - - var values = UiItemListStatic.getValues(this._fieldId); - for (var i = 0, length = values.length; i < length; i++) { - if (values[i].objectId) { - data[this._fieldId][values[i].objectId] = values[i].value; - } - else { - data[this._fieldId].push(values[i].value); - } - } - - return data; - } - }); - - return FormBuilderFieldItemList; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ItemList.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ItemList.ts new file mode 100644 index 0000000000..e83c501be0 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ItemList.ts @@ -0,0 +1,35 @@ +/** + * Data handler for an item list 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/ItemList + * @since 5.2 + */ + +import Field from "./Field"; +import * as UiItemListStatic from "../../../Ui/ItemList/Static"; +import { FormBuilderData } from "../Data"; +import * as Core from "../../../Core"; + +class ItemList extends Field { + protected _getData(): FormBuilderData { + const values: string[] = []; + UiItemListStatic.getValues(this._fieldId).forEach((item) => { + if (item.objectId) { + values[item.objectId] = item.value; + } else { + values.push(item.value); + } + }); + + return { + [this._fieldId]: values, + }; + } +} + +Core.enableLegacyInheritance(ItemList); + +export = ItemList;