* @module WoltLabSuite/Core/Form/Builder/Dialog
* @since 5.2
*/
-define(["require", "exports", "tslib", "../../Core", "../../Ui/Dialog", "../../Ajax", "./Manager"], function (require, exports, tslib_1, Core, Dialog_1, Ajax, Manager_1) {
+define(["require", "exports", "tslib", "../../Core", "../../Ui/Dialog", "../../Ajax", "./Manager"], function (require, exports, tslib_1, Core, Dialog_1, Ajax, FormBuilderManager) {
"use strict";
Core = tslib_1.__importStar(Core);
Dialog_1 = tslib_1.__importDefault(Dialog_1);
Ajax = tslib_1.__importStar(Ajax);
- Manager_1 = tslib_1.__importDefault(Manager_1);
+ FormBuilderManager = tslib_1.__importStar(FormBuilderManager);
class FormBuilderDialog {
constructor(dialogId, className, actionName, options) {
this.init(dialogId, className, actionName, options);
this._options = Core.extend({
actionParameters: {},
destroyOnClose: false,
- usesDboAction: new RegExp(/\w+\\data\\/).test(this._className),
+ usesDboAction: /\w+\\data\\/.test(this._className),
}, options);
this._options.dialog = Core.extend(this._options.dialog || {}, {
- onClose: this._dialogOnClose.bind(this),
+ onClose: () => this._dialogOnClose(),
});
this._formId = "";
this._dialogContent = "";
*/
destroy(ignoreDialog = false) {
if (this._formId !== "") {
- if (Manager_1.default.hasForm(this._formId)) {
- Manager_1.default.unregisterForm(this._formId);
+ if (FormBuilderManager.hasForm(this._formId)) {
+ FormBuilderManager.unregisterForm(this._formId);
}
if (ignoreDialog !== true) {
Dialog_1.default.destroy(this);
if (this._formId === "") {
throw new Error("Form has not been requested yet.");
}
- return Manager_1.default.getData(this._formId);
+ return FormBuilderManager.getData(this._formId);
}
/**
* Opens the dialog form.
*/
define(["require", "exports", "tslib", "../../Core", "../../Event/Handler", "./Field/Field", "./Field/Dependency/Manager"], function (require, exports, tslib_1, Core, EventHandler, Field_1, Manager_1) {
"use strict";
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.unregisterForm = exports.registerForm = exports.registerField = exports.hasForm = exports.hasField = exports.getForm = exports.getField = exports.getData = void 0;
Core = tslib_1.__importStar(Core);
EventHandler = tslib_1.__importStar(EventHandler);
Field_1 = tslib_1.__importDefault(Field_1);
Manager_1 = tslib_1.__importDefault(Manager_1);
const _fields = new Map();
const _forms = new Map();
- const FormBuilderManager = {
- /**
- * Returns a promise returning the data of the form with the given id.
- */
- getData(formId) {
- if (!this.hasForm(formId)) {
- throw new Error("Unknown form with id '" + formId + "'.");
+ /**
+ * Returns a promise returning the data of the form with the given id.
+ */
+ function getData(formId) {
+ if (!hasForm(formId)) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
+ const promises = [];
+ _fields.get(formId).forEach(function (field) {
+ const fieldData = field.getData();
+ if (!(fieldData instanceof Promise)) {
+ throw new TypeError("Data for field with id '" + field.getId() + "' is no promise.");
}
- const promises = [];
- _fields.get(formId).forEach(function (field) {
- const fieldData = field.getData();
- if (!(fieldData instanceof Promise)) {
- throw new TypeError("Data for field with id '" + field.getId() + "' is no promise.");
- }
- promises.push(fieldData);
- });
- return Promise.all(promises).then(function (promiseData) {
- let data = {};
- promiseData.forEach((_data) => {
- data = Core.extend(data, _data);
- });
- return data;
- });
- },
- /**
- * Returns the registered form field with given.
- *
- * @since 5.2.3
- */
- getField(formId, fieldId) {
- if (!this.hasField(formId, fieldId)) {
- throw new Error("Unknown field with id '" + formId + "' for form with id '" + fieldId + "'.");
- }
- return _fields.get(formId).get(fieldId);
- },
- /**
- * Returns the registered form with given id.
- */
- getForm(formId) {
- if (!this.hasForm(formId)) {
- throw new Error("Unknown form with id '" + formId + "'.");
- }
- return _forms.get(formId);
- },
- /**
- * Returns `true` if a field with the given id has been registered for the form with the given id
- * and `false` otherwise.
- */
- hasField(formId, fieldId) {
- if (!this.hasForm(formId)) {
- throw new Error("Unknown form with id '" + formId + "'.");
- }
- return _fields.get(formId).has(fieldId);
- },
- /**
- * Returns `true` if a form with the given id has been registered and `false` otherwise.
- */
- hasForm(formId) {
- return _forms.has(formId);
- },
- /**
- * Registers the given field for the form with the given id.
- */
- registerField(formId, field) {
- if (!this.hasForm(formId)) {
- throw new Error("Unknown form with id '" + formId + "'.");
- }
- if (!(field instanceof Field_1.default)) {
- throw new Error("Add field is no instance of 'WoltLabSuite/Core/Form/Builder/Field/Field'.");
- }
- const fieldId = field.getId();
- if (this.hasField(formId, fieldId)) {
- throw new Error("Form field with id '" + fieldId + "' has already been registered for form with id '" + formId + "'.");
- }
- _fields.get(formId).set(fieldId, field);
- EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "registerField", {
- field: field,
- formId: formId,
- });
- },
- /**
- * Registers the form with the given id.
- */
- registerForm(formId) {
- if (this.hasForm(formId)) {
- throw new Error("Form with id '" + formId + "' has already been registered.");
- }
- const form = document.getElementById(formId);
- if (form === null) {
- throw new Error("Unknown form with id '" + formId + "'.");
- }
- _forms.set(formId, form);
- _fields.set(formId, new Map());
- EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "registerForm", {
- formId: formId,
- });
- },
- /**
- * Unregisters the form with the given id.
- */
- unregisterForm: function (formId) {
- if (!this.hasForm(formId)) {
- throw new Error("Unknown form with id '" + formId + "'.");
- }
- EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "beforeUnregisterForm", {
- formId: formId,
- });
- _forms.delete(formId);
- _fields.get(formId).forEach(function (field) {
- field.destroy();
- });
- _fields.delete(formId);
- Manager_1.default.unregister(formId);
- EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "afterUnregisterForm", {
- formId: formId,
- });
- },
- };
- Core.enableLegacyInheritance(FormBuilderManager);
- return FormBuilderManager;
+ promises.push(fieldData);
+ });
+ return Promise.all(promises).then(function (promiseData) {
+ return promiseData.reduce((carry, current) => Core.extend(carry, current), {});
+ });
+ }
+ exports.getData = getData;
+ /**
+ * Returns the registered form field with given.
+ *
+ * @since 5.2.3
+ */
+ function getField(formId, fieldId) {
+ if (!hasField(formId, fieldId)) {
+ throw new Error("Unknown field with id '" + formId + "' for form with id '" + fieldId + "'.");
+ }
+ return _fields.get(formId).get(fieldId);
+ }
+ exports.getField = getField;
+ /**
+ * Returns the registered form with given id.
+ */
+ function getForm(formId) {
+ if (!hasForm(formId)) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
+ return _forms.get(formId);
+ }
+ exports.getForm = getForm;
+ /**
+ * Returns `true` if a field with the given id has been registered for the form with the given id
+ * and `false` otherwise.
+ */
+ function hasField(formId, fieldId) {
+ if (!hasForm(formId)) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
+ return _fields.get(formId).has(fieldId);
+ }
+ exports.hasField = hasField;
+ /**
+ * Returns `true` if a form with the given id has been registered and `false` otherwise.
+ */
+ function hasForm(formId) {
+ return _forms.has(formId);
+ }
+ exports.hasForm = hasForm;
+ /**
+ * Registers the given field for the form with the given id.
+ */
+ function registerField(formId, field) {
+ if (!hasForm(formId)) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
+ if (!(field instanceof Field_1.default)) {
+ throw new Error("Add field is no instance of 'WoltLabSuite/Core/Form/Builder/Field/Field'.");
+ }
+ const fieldId = field.getId();
+ if (hasField(formId, fieldId)) {
+ throw new Error("Form field with id '" + fieldId + "' has already been registered for form with id '" + formId + "'.");
+ }
+ _fields.get(formId).set(fieldId, field);
+ EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "registerField", {
+ field: field,
+ formId: formId,
+ });
+ }
+ exports.registerField = registerField;
+ /**
+ * Registers the form with the given id.
+ */
+ function registerForm(formId) {
+ if (hasForm(formId)) {
+ throw new Error("Form with id '" + formId + "' has already been registered.");
+ }
+ const form = document.getElementById(formId);
+ if (form === null) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
+ _forms.set(formId, form);
+ _fields.set(formId, new Map());
+ EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "registerForm", {
+ formId: formId,
+ });
+ }
+ exports.registerForm = registerForm;
+ /**
+ * Unregisters the form with the given id.
+ */
+ function unregisterForm(formId) {
+ if (!hasForm(formId)) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
+ EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "beforeUnregisterForm", {
+ formId: formId,
+ });
+ _forms.delete(formId);
+ _fields.get(formId).forEach(function (field) {
+ field.destroy();
+ });
+ _fields.delete(formId);
+ Manager_1.default.unregister(formId);
+ EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "afterUnregisterForm", {
+ formId: formId,
+ });
+ }
+ exports.unregisterForm = unregisterForm;
});
import { DialogCallbackObject, DialogCallbackSetup, DialogData } from "../../Ui/Dialog/Data";
import * as Ajax from "../../Ajax";
import { AjaxCallbackObject, AjaxCallbackSetup, DatabaseObjectActionResponse, RequestOptions } from "../../Ajax/Data";
-import FormBuilderManager from "./Manager";
+import * as FormBuilderManager from "./Manager";
import { FormBuilderData, FormBuilderDialogOptions } from "./Data";
interface AjaxResponseReturnValues {
{
actionParameters: {},
destroyOnClose: false,
- usesDboAction: new RegExp(/\w+\\data\\/).test(this._className),
+ usesDboAction: /\w+\\data\\/.test(this._className),
},
options,
) as FormBuilderDialogOptions;
this._options.dialog = Core.extend(this._options.dialog || {}, {
- onClose: this._dialogOnClose.bind(this),
+ onClose: () => this._dialogOnClose(),
});
this._formId = "";
import DependencyManager from "./Field/Dependency/Manager";
import { FormBuilderData } from "./Data";
-const _fields = new Map<string, Map<string, Field>>();
-const _forms = new Map<string, HTMLElement>();
-
-const FormBuilderManager = {
- /**
- * Returns a promise returning the data of the form with the given id.
- */
- getData(formId: string): Promise<FormBuilderData> {
- if (!this.hasForm(formId)) {
- throw new Error("Unknown form with id '" + formId + "'.");
- }
+type FormId = string;
+type FieldId = string;
- const promises: Promise<FormBuilderData>[] = [];
+const _fields = new Map<FormId, Map<FieldId, Field>>();
+const _forms = new Map<FormId, HTMLElement>();
- _fields.get(formId)!.forEach(function (field) {
- const fieldData = field.getData();
+/**
+ * Returns a promise returning the data of the form with the given id.
+ */
+export function getData(formId: FieldId): Promise<FormBuilderData> {
+ if (!hasForm(formId)) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
- if (!(fieldData instanceof Promise)) {
- throw new TypeError("Data for field with id '" + field.getId() + "' is no promise.");
- }
+ const promises: Promise<FormBuilderData>[] = [];
- promises.push(fieldData);
- });
+ _fields.get(formId)!.forEach(function (field) {
+ const fieldData = field.getData();
- return Promise.all(promises).then(function (promiseData: FormBuilderData[]) {
- let data = {};
+ if (!(fieldData instanceof Promise)) {
+ throw new TypeError("Data for field with id '" + field.getId() + "' is no promise.");
+ }
- promiseData.forEach((_data) => {
- data = Core.extend(data, _data);
- });
+ promises.push(fieldData);
+ });
- return data;
- });
- },
+ return Promise.all(promises).then(function (promiseData: FormBuilderData[]) {
+ return promiseData.reduce((carry, current) => Core.extend(carry, current), {});
+ });
+}
- /**
- * Returns the registered form field with given.
- *
- * @since 5.2.3
- */
- getField(formId: string, fieldId: string): Field {
- if (!this.hasField(formId, fieldId)) {
- throw new Error("Unknown field with id '" + formId + "' for form with id '" + fieldId + "'.");
- }
+/**
+ * Returns the registered form field with given.
+ *
+ * @since 5.2.3
+ */
+export function getField(formId: FieldId, fieldId: FieldId): Field {
+ if (!hasField(formId, fieldId)) {
+ throw new Error("Unknown field with id '" + formId + "' for form with id '" + fieldId + "'.");
+ }
- return _fields.get(formId)!.get(fieldId)!;
- },
+ return _fields.get(formId)!.get(fieldId)!;
+}
- /**
- * Returns the registered form with given id.
- */
- getForm(formId: string): HTMLElement {
- if (!this.hasForm(formId)) {
- throw new Error("Unknown form with id '" + formId + "'.");
- }
+/**
+ * Returns the registered form with given id.
+ */
+export function getForm(formId: FieldId): HTMLElement {
+ if (!hasForm(formId)) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
- return _forms.get(formId)!;
- },
+ return _forms.get(formId)!;
+}
- /**
- * Returns `true` if a field with the given id has been registered for the form with the given id
- * and `false` otherwise.
- */
- hasField(formId: string, fieldId: string): boolean {
- if (!this.hasForm(formId)) {
- throw new Error("Unknown form with id '" + formId + "'.");
- }
+/**
+ * Returns `true` if a field with the given id has been registered for the form with the given id
+ * and `false` otherwise.
+ */
+export function hasField(formId: FieldId, fieldId: FieldId): boolean {
+ if (!hasForm(formId)) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
- return _fields.get(formId)!.has(fieldId);
- },
-
- /**
- * Returns `true` if a form with the given id has been registered and `false` otherwise.
- */
- hasForm(formId): boolean {
- return _forms.has(formId);
- },
-
- /**
- * Registers the given field for the form with the given id.
- */
- registerField(formId: string, field: Field): void {
- if (!this.hasForm(formId)) {
- throw new Error("Unknown form with id '" + formId + "'.");
- }
+ return _fields.get(formId)!.has(fieldId);
+}
- if (!(field instanceof Field)) {
- throw new Error("Add field is no instance of 'WoltLabSuite/Core/Form/Builder/Field/Field'.");
- }
+/**
+ * Returns `true` if a form with the given id has been registered and `false` otherwise.
+ */
+export function hasForm(formId: FieldId): boolean {
+ return _forms.has(formId);
+}
- const fieldId = field.getId();
+/**
+ * Registers the given field for the form with the given id.
+ */
+export function registerField(formId: FieldId, field: Field): void {
+ if (!hasForm(formId)) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
- if (this.hasField(formId, fieldId)) {
- throw new Error(
- "Form field with id '" + fieldId + "' has already been registered for form with id '" + formId + "'.",
- );
- }
+ if (!(field instanceof Field)) {
+ throw new Error("Add field is no instance of 'WoltLabSuite/Core/Form/Builder/Field/Field'.");
+ }
- _fields.get(formId)!.set(fieldId, field);
+ const fieldId = field.getId();
- EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "registerField", {
- field: field,
- formId: formId,
- });
- },
+ if (hasField(formId, fieldId)) {
+ throw new Error(
+ "Form field with id '" + fieldId + "' has already been registered for form with id '" + formId + "'.",
+ );
+ }
- /**
- * Registers the form with the given id.
- */
- registerForm(formId: string): void {
- if (this.hasForm(formId)) {
- throw new Error("Form with id '" + formId + "' has already been registered.");
- }
+ _fields.get(formId)!.set(fieldId, field);
- const form = document.getElementById(formId);
- if (form === null) {
- throw new Error("Unknown form with id '" + formId + "'.");
- }
+ EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "registerField", {
+ field: field,
+ formId: formId,
+ });
+}
- _forms.set(formId, form);
- _fields.set(formId, new Map<string, Field>());
+/**
+ * Registers the form with the given id.
+ */
+export function registerForm(formId: FieldId): void {
+ if (hasForm(formId)) {
+ throw new Error("Form with id '" + formId + "' has already been registered.");
+ }
- EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "registerForm", {
- formId: formId,
- });
- },
+ const form = document.getElementById(formId);
+ if (form === null) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
- /**
- * Unregisters the form with the given id.
- */
- unregisterForm: function (formId: string): void {
- if (!this.hasForm(formId)) {
- throw new Error("Unknown form with id '" + formId + "'.");
- }
+ _forms.set(formId, form);
+ _fields.set(formId, new Map<FieldId, Field>());
- EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "beforeUnregisterForm", {
- formId: formId,
- });
+ EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "registerForm", {
+ formId: formId,
+ });
+}
- _forms.delete(formId);
+/**
+ * Unregisters the form with the given id.
+ */
+export function unregisterForm(formId: FieldId): void {
+ if (!hasForm(formId)) {
+ throw new Error("Unknown form with id '" + formId + "'.");
+ }
- _fields.get(formId)!.forEach(function (field) {
- field.destroy();
- });
+ EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "beforeUnregisterForm", {
+ formId: formId,
+ });
- _fields.delete(formId);
+ _forms.delete(formId);
- DependencyManager.unregister(formId);
+ _fields.get(formId)!.forEach(function (field) {
+ field.destroy();
+ });
- EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "afterUnregisterForm", {
- formId: formId,
- });
- },
-};
+ _fields.delete(formId);
-Core.enableLegacyInheritance(FormBuilderManager);
+ DependencyManager.unregister(formId);
-export = FormBuilderManager;
+ EventHandler.fire("WoltLabSuite/Core/Form/Builder/Manager", "afterUnregisterForm", {
+ formId: formId,
+ });
+}