From: Matthias Schmidt Date: Wed, 9 Dec 2020 16:34:00 +0000 (+0100) Subject: Convert `Form/Builder/Field/Field` to TypeScript X-Git-Tag: 5.4.0_Alpha_1~526^2~30 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8fc2f54d60132f1ca6ee5552ada8c965a6674b85;p=GitHub%2FWoltLab%2FWCF.git Convert `Form/Builder/Field/Field` to TypeScript --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Field.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Field.js index 9e1e2019c1..bc75fb3485 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Field.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Field.js @@ -1,73 +1,65 @@ /** * Data handler for a 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/Field - * @since 5.2 + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Form/Builder/Field/Field + * @since 5.2 */ -define([], function () { +define(["require", "exports", "tslib", "../../../Core"], function (require, exports, tslib_1, Core) { "use strict"; - /** - * @constructor - */ - function FormBuilderField(fieldId) { - this.init(fieldId); - } - ; - FormBuilderField.prototype = { + Core = tslib_1.__importStar(Core); + class Field { + constructor(fieldId) { + this.init(fieldId); + } /** - * Initializes the form field. - * - * @param {string} fieldId id of the relevant form builder field + * Initializes the field. */ - init: function (fieldId) { + init(fieldId) { this._fieldId = fieldId; this._readField(); - }, + } /** * Returns the current data of the field or a promise returning the current data * of the field. * * @return {Promise|data} */ - _getData: function () { + _getData() { throw new Error("Missing implementation of WoltLabSuite/Core/Form/Builder/Field/Field._getData!"); - }, + } /** - * Reads the field HTML element. + * Reads the field's HTML element. */ - _readField: function () { - this._field = elById(this._fieldId); + _readField() { + this._field = document.getElementById(this._fieldId); if (this._field === null) { throw new Error("Unknown field with id '" + this._fieldId + "'."); } - }, + } /** * Destroys the field. * * This function is useful for remove registered elements from other APIs like dialogs. */ - destroy: function () { - // does nothing - }, + destroy() { + // does nothinbg + } /** - * Returns a promise returning the current data of the field. - * - * @return {Promise} + * Returns a promise providing the current data of the field. */ - getData: function () { + getData() { return Promise.resolve(this._getData()); - }, + } /** * Returns the id of the field. - * - * @return {string} */ - getId: function () { + getId() { return this._fieldId; } - }; - return FormBuilderField; + } + Core.enableLegacyInheritance(Field); + return Field; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Field.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Field.js deleted file mode 100644 index d4d6dee6a3..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Field.js +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Data handler for a 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/Field - * @since 5.2 - */ -define([], function() { - "use strict"; - - /** - * @constructor - */ - function FormBuilderField(fieldId) { - this.init(fieldId); - }; - FormBuilderField.prototype = { - /** - * Initializes the form field. - * - * @param {string} fieldId id of the relevant form builder field - */ - init: function(fieldId) { - this._fieldId = fieldId; - - this._readField(); - }, - - /** - * Returns the current data of the field or a promise returning the current data - * of the field. - * - * @return {Promise|data} - */ - _getData: function() { - throw new Error("Missing implementation of WoltLabSuite/Core/Form/Builder/Field/Field._getData!"); - }, - - /** - * Reads the field HTML element. - */ - _readField: function() { - this._field = elById(this._fieldId); - - if (this._field === null) { - throw new Error("Unknown field with id '" + this._fieldId + "'."); - } - }, - - /** - * Destroys the field. - * - * This function is useful for remove registered elements from other APIs like dialogs. - */ - destroy: function() { - // does nothing - }, - - /** - * Returns a promise returning the current data of the field. - * - * @return {Promise} - */ - getData: function() { - return Promise.resolve(this._getData()); - }, - - /** - * Returns the id of the field. - * - * @return {string} - */ - getId: function() { - return this._fieldId; - } - }; - - return FormBuilderField; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Field.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Field.ts new file mode 100644 index 0000000000..5ae819d8ec --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Field.ts @@ -0,0 +1,78 @@ +/** + * Data handler for a 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/Field + * @since 5.2 + */ + +import * as Core from "../../../Core"; +import { FormBuilderData } from "../Data"; + +class Field { + protected _fieldId: string; + protected _field: HTMLElement | null; + + constructor(fieldId: string) { + this.init(fieldId); + } + + /** + * Initializes the field. + */ + protected init(fieldId: string): void { + this._fieldId = fieldId; + + this._readField(); + } + + /** + * Returns the current data of the field or a promise returning the current data + * of the field. + * + * @return {Promise|data} + */ + protected _getData(): FormBuilderData { + throw new Error("Missing implementation of WoltLabSuite/Core/Form/Builder/Field/Field._getData!"); + } + + /** + * Reads the field's HTML element. + */ + protected _readField(): void { + this._field = document.getElementById(this._fieldId); + + if (this._field === null) { + throw new Error("Unknown field with id '" + this._fieldId + "'."); + } + } + + /** + * Destroys the field. + * + * This function is useful for remove registered elements from other APIs like dialogs. + */ + public destroy(): void { + // does nothinbg + } + + /** + * Returns a promise providing the current data of the field. + */ + public getData(): Promise { + return Promise.resolve(this._getData()); + } + + /** + * Returns the id of the field. + */ + public getId(): string { + return this._fieldId; + } +} + +Core.enableLegacyInheritance(Field); + +export = Field;