From 08e5aca0d00eda39ff870bdf2ad090ca9310fc05 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 9 Dec 2020 17:35:22 +0100 Subject: [PATCH] Convert `Form/Builder/Field/ValueI18n` to TypeScript --- .../Core/Form/Builder/Field/ValueI18n.js | 49 ++++++++----------- .../Core/Form/Builder/Field/ValueI18n.js | 47 ------------------ .../Core/Form/Builder/Field/ValueI18n.ts | 40 +++++++++++++++ 3 files changed, 61 insertions(+), 75 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.ts 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; -- 2.20.1