1 import {EditorForm, EditorFormDefinition} from "./forms";
2 import {el} from "../../helpers";
3 import {EditorContainerUiElement} from "./core";
6 export interface EditorModalDefinition {
10 export interface EditorFormModalDefinition extends EditorModalDefinition {
11 form: EditorFormDefinition;
14 export class EditorFormModal extends EditorContainerUiElement {
15 protected definition: EditorFormModalDefinition;
17 constructor(definition: EditorFormModalDefinition) {
18 super([new EditorForm(definition.form)]);
19 this.definition = definition;
22 show(defaultValues: Record<string, string>) {
23 const dom = this.getDOMElement();
24 document.body.append(dom);
26 const form = this.getForm();
27 form.setValues(defaultValues);
28 form.setOnCancel(this.hide.bind(this));
32 this.getDOMElement().remove();
35 protected getForm(): EditorForm {
36 return this.children[0] as EditorForm;
39 protected buildDOM(): HTMLElement {
40 const closeButton = el('button', {class: 'editor-modal-close', type: 'button', title: this.trans('Close')}, ['x']);
41 closeButton.addEventListener('click', this.hide.bind(this));
43 const modal = el('div', {class: 'editor-modal editor-form-modal'}, [
44 el('div', {class: 'editor-modal-header'}, [
45 el('div', {class: 'editor-modal-title'}, [this.trans(this.definition.title)]),
48 el('div', {class: 'editor-modal-body'}, [
49 this.getForm().getDOMElement(),
53 const wrapper = el('div', {class: 'editor-modal-wrapper'}, [modal]);
55 wrapper.addEventListener('click', event => {
56 if (event.target && !modal.contains(event.target as HTMLElement)) {