import { gettext } from "django"; import { customElement, html, property, TemplateResult } from "lit-element"; import { EVENT_REFRESH } from "../../constants"; import { ModalButton } from "../buttons/ModalButton"; import { showMessage } from "../messages/MessageContainer"; @customElement("ak-forms-delete") export class DeleteForm extends ModalButton { @property({attribute: false}) obj?: Record; @property() objectLabel?: string; @property({attribute: false}) delete!: () => Promise; confirm(): void { this.delete().then(() => { this.onSuccess(); this.open = false; this.dispatchEvent( new CustomEvent(EVENT_REFRESH, { bubbles: true, composed: true, }) ); }).catch((e) => { this.onError(e); }); } onSuccess(): void { showMessage({ message: gettext(`Successfully deleted ${this.objectLabel} ${ this.obj?.name }`), level_tag: "success", }); } onError(e: Error): void { showMessage({ message: gettext(`Failed to delete ${this.objectLabel}: ${e.toString()}`), level_tag: "error", }); } renderModalInner(): TemplateResult { return html`

${gettext(`Delete ${this.objectLabel}`)}

${gettext( `Are you sure you want to delete ${this.objectLabel} '${this.obj?.name}'?` )}

`; } }