import { t } from "@lingui/macro"; import { customElement, html, property, TemplateResult } from "lit-element"; import { EVENT_REFRESH } from "../../constants"; import { ModalButton } from "../buttons/ModalButton"; import { Form } from "./Form"; import "../buttons/SpinnerButton"; import "../LoadingOverlay"; @customElement("ak-forms-modal") export class ModalForm extends ModalButton { @property({ type: Boolean }) closeAfterSuccessfulSubmit = true; @property({ type: Boolean }) showSubmitButton = true; @property({ type: Boolean }) loading = false; @property({ type: String }) cancelText = t`Cancel`; confirm(): Promise { const form = this.querySelector>("[slot=form]"); if (!form) { return Promise.reject(t`No form found`); } const formPromise = form.submit(new Event("submit")); if (!formPromise) { return Promise.reject(t`Form didn't return a promise for submitting`); } return formPromise .then(() => { if (this.closeAfterSuccessfulSubmit) { this.open = false; form?.resetForm(); } this.loading = false; this.locked = false; this.dispatchEvent( new CustomEvent(EVENT_REFRESH, { bubbles: true, composed: true, }), ); }) .catch((exc) => { this.loading = false; this.locked = false; throw exc; }); } renderModalInner(): TemplateResult { return html`${this.loading ? html`` : html``}

`; } }