import {EditorForm, EditorFormDefinition} from "./forms";
-import {el} from "../../helpers";
import {EditorContainerUiElement} from "./core";
-
+import closeIcon from "@icons/close.svg";
+import {el} from "../../utils/dom";
export interface EditorModalDefinition {
title: string;
export class EditorFormModal extends EditorContainerUiElement {
protected definition: EditorFormModalDefinition;
+ protected key: string;
- constructor(definition: EditorFormModalDefinition) {
+ constructor(definition: EditorFormModalDefinition, key: string) {
super([new EditorForm(definition.form)]);
this.definition = definition;
+ this.key = key;
}
show(defaultValues: Record<string, string>) {
const form = this.getForm();
form.setValues(defaultValues);
form.setOnCancel(this.hide.bind(this));
+ form.setOnSuccessfulSubmit(this.hide.bind(this));
+
+ this.getContext().manager.setModalActive(this.key, this);
}
hide() {
this.getDOMElement().remove();
+ this.getContext().manager.setModalInactive(this.key);
}
- protected getForm(): EditorForm {
+ getForm(): EditorForm {
return this.children[0] as EditorForm;
}
protected buildDOM(): HTMLElement {
- const closeButton = el('button', {class: 'editor-modal-close', type: 'button', title: this.trans('Close')}, ['x']);
+ const closeButton = el('button', {
+ class: 'editor-modal-close',
+ type: 'button',
+ title: this.trans('Close'),
+ });
+ closeButton.innerHTML = closeIcon;
closeButton.addEventListener('click', this.hide.bind(this));
const modal = el('div', {class: 'editor-modal editor-form-modal'}, [