From: Matthias Schmidt Date: Wed, 9 Dec 2020 16:35:22 +0000 (+0100) Subject: Convert `Form/Builder/Field/ValueI18n` to TypeScript X-Git-Tag: 5.4.0_Alpha_1~526^2~23 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=08e5aca0d00eda39ff870bdf2ad090ca9310fc05;p=GitHub%2FWoltLab%2FWCF.git Convert `Form/Builder/Field/ValueI18n` to TypeScript --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js index 47fd951abf..b11f778651 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js @@ -2,42 +2,35 @@ * Data handler for an i18n form builder field in an Ajax form that stores its value in an input's * value attribute. * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Form/Builder/Field/ValueI18n - * @since 5.2 + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Form/Builder/Field/ValueI18n + * @since 5.2 */ -define(['Core', './Field', 'WoltLabSuite/Core/Language/Input'], function (Core, FormBuilderField, LanguageInput) { +define(["require", "exports", "tslib", "./Field", "../../../Language/Input", "../../../Core"], function (require, exports, tslib_1, Field_1, LanguageInput, Core) { "use strict"; - /** - * @constructor - */ - function FormBuilderFieldValueI18n(fieldId) { - this.init(fieldId); - } - ; - Core.inherit(FormBuilderFieldValueI18n, FormBuilderField, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData - */ - _getData: function () { - var data = {}; - var values = LanguageInput.getValues(this._fieldId); + Field_1 = tslib_1.__importDefault(Field_1); + LanguageInput = tslib_1.__importStar(LanguageInput); + Core = tslib_1.__importStar(Core); + class ValueI18n extends Field_1.default { + _getData() { + const data = {}; + const values = LanguageInput.getValues(this._fieldId); if (values.size > 1) { - data[this._fieldId + '_i18n'] = values.toObject(); + values.forEach((value, key) => { + data[this._fieldId + "_i18n"][key] = value; + }); } else { data[this._fieldId] = values.get(0); } return data; - }, - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#destroy - */ - destroy: function () { + } + destroy() { LanguageInput.unregister(this._fieldId); } - }); - return FormBuilderFieldValueI18n; + } + Core.enableLegacyInheritance(ValueI18n); + return ValueI18n; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js deleted file mode 100644 index 7aceb81547..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Data handler for an i18n form builder field in an Ajax form that stores its value in an input's - * value attribute. - * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Form/Builder/Field/ValueI18n - * @since 5.2 - */ -define(['Core', './Field', 'WoltLabSuite/Core/Language/Input'], function(Core, FormBuilderField, LanguageInput) { - "use strict"; - - /** - * @constructor - */ - function FormBuilderFieldValueI18n(fieldId) { - this.init(fieldId); - }; - Core.inherit(FormBuilderFieldValueI18n, FormBuilderField, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData - */ - _getData: function() { - var data = {}; - - var values = LanguageInput.getValues(this._fieldId); - if (values.size > 1) { - data[this._fieldId + '_i18n'] = values.toObject(); - } - else { - data[this._fieldId] = values.get(0); - } - - return data; - }, - - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#destroy - */ - destroy: function() { - LanguageInput.unregister(this._fieldId); - } - }); - - return FormBuilderFieldValueI18n; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.ts new file mode 100644 index 0000000000..8cafa4b2ea --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.ts @@ -0,0 +1,40 @@ +/** + * Data handler for an i18n form builder field in an Ajax form that stores its value in an input's + * value attribute. + * + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Form/Builder/Field/ValueI18n + * @since 5.2 + */ + +import Field from "./Field"; +import { FormBuilderData } from "../Data"; +import * as LanguageInput from "../../../Language/Input"; +import * as Core from "../../../Core"; + +class ValueI18n extends Field { + protected _getData(): FormBuilderData { + const data = {}; + + const values = LanguageInput.getValues(this._fieldId); + if (values.size > 1) { + values.forEach((value, key) => { + data[this._fieldId + "_i18n"][key] = value; + }); + } else { + data[this._fieldId] = values.get(0); + } + + return data; + } + + destroy(): void { + LanguageInput.unregister(this._fieldId); + } +} + +Core.enableLegacyInheritance(ValueI18n); + +export = ValueI18n;