/**
* Abstract implementation of a form field dependency.
*
- * @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/Dependency/Abstract
- * @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/Dependency/Abstract
+ * @since 5.2
*/
-define(['./Manager'], function (DependencyManager) {
+define(["require", "exports", "tslib", "./Manager", "../../../../Core"], function (require, exports, tslib_1, Manager_1, Core) {
"use strict";
- /**
- * @constructor
- */
- function Abstract(dependentElementId, fieldId) {
- this.init(dependentElementId, fieldId);
- }
- ;
- Abstract.prototype = {
+ Manager_1 = tslib_1.__importDefault(Manager_1);
+ Core = tslib_1.__importStar(Core);
+ class FormBuilderFormFieldDependency {
+ constructor(dependentElementId, fieldId) {
+ this.init(dependentElementId, fieldId);
+ }
/**
- * Checks if the dependency is met.
- *
- * @abstract
+ * Returns `true` if the dependency is met.
*/
- checkDependency: function () {
+ checkDependency() {
throw new Error("Missing implementation of WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract.checkDependency!");
- },
+ }
/**
* Return the node whose availability depends on the value of a field.
- *
- * @return {HtmlElement} dependent node
*/
- getDependentNode: function () {
+ getDependentNode() {
return this._dependentElement;
- },
+ }
/**
* Returns the field the availability of the element dependents on.
- *
- * @return {HtmlElement} field controlling element availability
*/
- getField: function () {
+ getField() {
return this._field;
- },
+ }
/**
- * Returns all fields requiring `change` event listeners for this
- * dependency to be properly resolved.
- *
- * @return {HtmlElement[]} fields to register event listeners on
+ * Returns all fields requiring event listeners for this dependency to be properly resolved.
*/
- getFields: function () {
+ getFields() {
return this._fields;
- },
+ }
/**
* Initializes the new dependency object.
- *
- * @param {string} dependentElementId id of the (container of the) dependent element
- * @param {string} fieldId id of the field controlling element availability
- *
- * @throws {Error} if either depenent element id or field id are invalid
*/
- init: function (dependentElementId, fieldId) {
- this._dependentElement = elById(dependentElementId);
+ init(dependentElementId, fieldId) {
+ this._dependentElement = document.getElementById(dependentElementId);
if (this._dependentElement === null) {
throw new Error("Unknown dependent element with container id '" + dependentElementId + "Container'.");
}
- this._field = elById(fieldId);
+ this._field = document.getElementById(fieldId);
if (this._field === null) {
this._fields = [];
- elBySelAll('input[type=radio][name=' + fieldId + ']', undefined, function (field) {
+ document.querySelectorAll("input[type=radio][name=" + fieldId + "]").forEach((field) => {
this._fields.push(field);
- }.bind(this));
+ });
if (!this._fields.length) {
- elBySelAll('input[type=checkbox][name="' + fieldId + '[]"]', undefined, function (field) {
+ document
+ .querySelectorAll('input[type=checkbox][name="' + fieldId + '[]"]')
+ .forEach((field) => {
this._fields.push(field);
- }.bind(this));
+ });
if (!this._fields.length) {
throw new Error("Unknown field with id '" + fieldId + "'.");
}
}
else {
this._fields = [this._field];
- // handle special case of boolean form fields that have to form fields
- if (this._field.tagName === 'INPUT' && this._field.type === 'radio' && elData(this._field, 'no-input-id') !== '') {
- this._noField = elById(elData(this._field, 'no-input-id'));
+ // Handle special case of boolean form fields that have two form fields.
+ if (this._field.tagName === "INPUT" &&
+ this._field.type === "radio" &&
+ this._field.dataset.noInputId !== "") {
+ this._noField = document.getElementById(this._field.dataset.noInputId);
if (this._noField === null) {
throw new Error("Cannot find 'no' input field for input field '" + fieldId + "'");
}
this._fields.push(this._noField);
}
}
- DependencyManager.addDependency(this);
+ Manager_1.default.addDependency(this);
}
- };
- return Abstract;
+ }
+ Core.enableLegacyInheritance(FormBuilderFormFieldDependency);
+ return FormBuilderFormFieldDependency;
});
+++ /dev/null
-/**
- * Abstract implementation of a form field dependency.
- *
- * @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/Dependency/Abstract
- * @since 5.2
- */
-define(['./Manager'], function(DependencyManager) {
- "use strict";
-
- /**
- * @constructor
- */
- function Abstract(dependentElementId, fieldId) {
- this.init(dependentElementId, fieldId);
- };
- Abstract.prototype = {
- /**
- * Checks if the dependency is met.
- *
- * @abstract
- */
- checkDependency: function() {
- throw new Error("Missing implementation of WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract.checkDependency!");
- },
-
- /**
- * Return the node whose availability depends on the value of a field.
- *
- * @return {HtmlElement} dependent node
- */
- getDependentNode: function() {
- return this._dependentElement;
- },
-
- /**
- * Returns the field the availability of the element dependents on.
- *
- * @return {HtmlElement} field controlling element availability
- */
- getField: function() {
- return this._field;
- },
-
- /**
- * Returns all fields requiring `change` event listeners for this
- * dependency to be properly resolved.
- *
- * @return {HtmlElement[]} fields to register event listeners on
- */
- getFields: function() {
- return this._fields;
- },
-
- /**
- * Initializes the new dependency object.
- *
- * @param {string} dependentElementId id of the (container of the) dependent element
- * @param {string} fieldId id of the field controlling element availability
- *
- * @throws {Error} if either depenent element id or field id are invalid
- */
- init: function(dependentElementId, fieldId) {
- this._dependentElement = elById(dependentElementId);
- if (this._dependentElement === null) {
- throw new Error("Unknown dependent element with container id '" + dependentElementId + "Container'.");
- }
-
- this._field = elById(fieldId);
- if (this._field === null) {
- this._fields = [];
- elBySelAll('input[type=radio][name=' + fieldId + ']', undefined, function(field) {
- this._fields.push(field);
- }.bind(this));
-
- if (!this._fields.length) {
- elBySelAll('input[type=checkbox][name="' + fieldId + '[]"]', undefined, function(field) {
- this._fields.push(field);
- }.bind(this));
-
- if (!this._fields.length) {
- throw new Error("Unknown field with id '" + fieldId + "'.");
- }
- }
- }
- else {
- this._fields = [this._field];
-
- // handle special case of boolean form fields that have to form fields
- if (this._field.tagName === 'INPUT' && this._field.type === 'radio' && elData(this._field, 'no-input-id') !== '') {
- this._noField = elById(elData(this._field, 'no-input-id'));
- if (this._noField === null) {
- throw new Error("Cannot find 'no' input field for input field '" + fieldId + "'");
- }
-
- this._fields.push(this._noField);
- }
- }
-
- DependencyManager.addDependency(this);
- }
- };
-
- return Abstract;
-});
--- /dev/null
+/**
+ * Abstract implementation of a form field dependency.
+ *
+ * @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/Dependency/Abstract
+ * @since 5.2
+ */
+
+import Manager from "./Manager";
+import * as Core from "../../../../Core";
+
+abstract class FormBuilderFormFieldDependency {
+ protected _dependentElement: HTMLElement;
+ protected _field: HTMLElement;
+ protected _fields: HTMLElement[];
+ protected _noField?: HTMLInputElement;
+
+ constructor(dependentElementId: string, fieldId: string) {
+ this.init(dependentElementId, fieldId);
+ }
+
+ /**
+ * Returns `true` if the dependency is met.
+ */
+ public checkDependency(): boolean {
+ throw new Error(
+ "Missing implementation of WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract.checkDependency!",
+ );
+ }
+
+ /**
+ * Return the node whose availability depends on the value of a field.
+ */
+ public getDependentNode(): HTMLElement {
+ return this._dependentElement;
+ }
+
+ /**
+ * Returns the field the availability of the element dependents on.
+ */
+ public getField(): HTMLElement {
+ return this._field;
+ }
+
+ /**
+ * Returns all fields requiring event listeners for this dependency to be properly resolved.
+ */
+ public getFields(): HTMLElement[] {
+ return this._fields;
+ }
+
+ /**
+ * Initializes the new dependency object.
+ */
+ protected init(dependentElementId: string, fieldId: string): void {
+ this._dependentElement = document.getElementById(dependentElementId)!;
+ if (this._dependentElement === null) {
+ throw new Error("Unknown dependent element with container id '" + dependentElementId + "Container'.");
+ }
+
+ this._field = document.getElementById(fieldId)!;
+ if (this._field === null) {
+ this._fields = [];
+ document.querySelectorAll("input[type=radio][name=" + fieldId + "]").forEach((field: HTMLInputElement) => {
+ this._fields.push(field);
+ });
+
+ if (!this._fields.length) {
+ document
+ .querySelectorAll('input[type=checkbox][name="' + fieldId + '[]"]')
+ .forEach((field: HTMLInputElement) => {
+ this._fields.push(field);
+ });
+
+ if (!this._fields.length) {
+ throw new Error("Unknown field with id '" + fieldId + "'.");
+ }
+ }
+ } else {
+ this._fields = [this._field];
+
+ // Handle special case of boolean form fields that have two form fields.
+ if (
+ this._field.tagName === "INPUT" &&
+ (this._field as HTMLInputElement).type === "radio" &&
+ this._field.dataset.noInputId !== ""
+ ) {
+ this._noField = document.getElementById(this._field.dataset.noInputId!)! as HTMLInputElement;
+ if (this._noField === null) {
+ throw new Error("Cannot find 'no' input field for input field '" + fieldId + "'");
+ }
+
+ this._fields.push(this._noField);
+ }
+ }
+
+ Manager.addDependency(this);
+ }
+}
+
+Core.enableLegacyInheritance(FormBuilderFormFieldDependency);
+
+export = FormBuilderFormFieldDependency;