/**
* 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 <http://opensource.org/licenses/lgpl-license.php>
- * @module WoltLabSuite/Core/Form/Builder/Field/Field
- * @since 5.2
+ * @author Matthias Schmidt
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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;
});
+++ /dev/null
-/**
- * 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 <http://opensource.org/licenses/lgpl-license.php>
- * @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;
-});
--- /dev/null
+/**
+ * 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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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<FormBuilderData> {
+ return Promise.resolve(this._getData());
+ }
+
+ /**
+ * Returns the id of the field.
+ */
+ public getId(): string {
+ return this._fieldId;
+ }
+}
+
+Core.enableLegacyInheritance(Field);
+
+export = Field;