import { gettext } from "django"; import { customElement, html, property, TemplateResult } from "lit-element"; import { ModalButton } from "../buttons/ModalButton"; import { showMessage } from "../messages/MessageContainer"; @customElement("ak-forms-confirm") export class ConfirmationForm extends ModalButton { @property() successMessage!: string; @property() errorMessage!: string; @property() action!: string; @property({attribute: false}) onConfirm!: () => Promise; confirm(): void { this.onConfirm().then(() => { this.onSuccess(); this.open = false; this.dispatchEvent( new CustomEvent("ak-refresh", { bubbles: true, composed: true, }) ); }).catch((e) => { this.onError(e); }); } onSuccess(): void { showMessage({ message: gettext(this.successMessage), level_tag: "success", }); } onError(e: Error): void { showMessage({ message: gettext(`${this.errorMessage}: ${e.toString()}`), level_tag: "error", }); } renderModalInner(): TemplateResult { return html`

`; } }