From da1a24a8f1f99789aa334ffaa9d9ccb893a882cd Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 9 Dec 2020 17:34:50 +0100 Subject: [PATCH] Convert `Form/Builder/Field/Tag` to TypeScript --- .../Core/Form/Builder/Field/Tag.js | 47 ++++++++----------- .../Core/Form/Builder/Field/Tag.js | 37 --------------- .../Core/Form/Builder/Field/Tag.ts | 30 ++++++++++++ 3 files changed, 50 insertions(+), 64 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.ts diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Tag.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Tag.js index 1a51f1f841..4871837882 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Tag.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Tag.js @@ -1,34 +1,27 @@ /** * Data handler for a tag 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/Tag - * @since 5.2 + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Form/Builder/Field/Tag + * @since 5.2 */ -define(['Core', './Field', 'WoltLabSuite/Core/Ui/ItemList'], function (Core, FormBuilderField, UiItemList) { +define(["require", "exports", "tslib", "./Field", "../../../Ui/ItemList", "../../../Core"], function (require, exports, tslib_1, Field_1, UiItemList, Core) { "use strict"; - /** - * @constructor - */ - function FormBuilderFieldTag(fieldId) { - this.init(fieldId); - } - ; - Core.inherit(FormBuilderFieldTag, FormBuilderField, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData - */ - _getData: function () { - var data = {}; - data[this._fieldId] = []; - var values = UiItemList.getValues(this._fieldId); - for (var i = 0, length = values.length; i < length; i++) { - data[this._fieldId].push(values[i].value); - } - return data; + Field_1 = tslib_1.__importDefault(Field_1); + UiItemList = tslib_1.__importStar(UiItemList); + Core = tslib_1.__importStar(Core); + class Tag extends Field_1.default { + _getData() { + const values = UiItemList.getValues(this._fieldId).map((item) => { + return item.value; + }); + return { + [this._fieldId]: values, + }; } - }); - return FormBuilderFieldTag; + } + Core.enableLegacyInheritance(Tag); + return Tag; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.js deleted file mode 100644 index a56bed994c..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Data handler for a tag 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/Tag - * @since 5.2 - */ -define(['Core', './Field', 'WoltLabSuite/Core/Ui/ItemList'], function(Core, FormBuilderField, UiItemList) { - "use strict"; - - /** - * @constructor - */ - function FormBuilderFieldTag(fieldId) { - this.init(fieldId); - }; - Core.inherit(FormBuilderFieldTag, FormBuilderField, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData - */ - _getData: function() { - var data = {}; - data[this._fieldId] = []; - - var values = UiItemList.getValues(this._fieldId); - for (var i = 0, length = values.length; i < length; i++) { - data[this._fieldId].push(values[i].value); - } - - return data; - } - }); - - return FormBuilderFieldTag; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.ts new file mode 100644 index 0000000000..cee036ec2b --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Tag.ts @@ -0,0 +1,30 @@ +/** + * Data handler for a tag 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/Tag + * @since 5.2 + */ + +import Field from "./Field"; +import * as UiItemList from "../../../Ui/ItemList"; +import { FormBuilderData } from "../Data"; +import * as Core from "../../../Core"; + +class Tag extends Field { + protected _getData(): FormBuilderData { + const values: string[] = UiItemList.getValues(this._fieldId).map((item) => { + return item.value; + }); + + return { + [this._fieldId]: values, + }; + } +} + +Core.enableLegacyInheritance(Tag); + +export = Tag; -- 2.20.1