2021-03-18 00:43:12 +00:00
|
|
|
import { gettext } from "django";
|
|
|
|
import { customElement, html, property, TemplateResult } from "lit-element";
|
|
|
|
import { ModalButton } from "../buttons/ModalButton";
|
2021-03-18 10:16:13 +00:00
|
|
|
import { showMessage } from "../messages/MessageContainer";
|
2021-03-18 00:43:12 +00:00
|
|
|
|
|
|
|
@customElement("ak-forms-delete")
|
|
|
|
export class DeleteForm extends ModalButton {
|
|
|
|
|
2021-03-18 00:49:01 +00:00
|
|
|
@property({attribute: false})
|
|
|
|
obj?: Record<string, unknown>;
|
2021-03-18 00:43:12 +00:00
|
|
|
|
|
|
|
@property()
|
|
|
|
objectLabel?: string;
|
|
|
|
|
|
|
|
@property({attribute: false})
|
2021-03-18 00:49:01 +00:00
|
|
|
delete!: () => Promise<void>;
|
2021-03-18 00:43:12 +00:00
|
|
|
|
|
|
|
confirm(): void {
|
|
|
|
this.delete().then(() => {
|
|
|
|
this.open = false;
|
|
|
|
this.dispatchEvent(
|
|
|
|
new CustomEvent("ak-refresh", {
|
|
|
|
bubbles: true,
|
|
|
|
composed: true,
|
|
|
|
})
|
|
|
|
);
|
2021-03-18 10:16:13 +00:00
|
|
|
}).catch((e) => {
|
|
|
|
showMessage({
|
|
|
|
message: gettext(`Failed to delete ${this.objectLabel}: ${e.toString()}`),
|
|
|
|
level_tag: "error",
|
|
|
|
})
|
|
|
|
})
|
2021-03-18 00:43:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renderModalInner(): TemplateResult {
|
|
|
|
return html`<section class="pf-c-page__main-section pf-m-light">
|
|
|
|
<div class="pf-c-content">
|
|
|
|
<h1 class="pf-c-title pf-m-2xl">
|
2021-03-18 00:49:01 +00:00
|
|
|
${gettext(`Delete ${this.objectLabel}`)}
|
2021-03-18 00:43:12 +00:00
|
|
|
</h1>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<section class="pf-c-page__main-section">
|
|
|
|
<div class="pf-l-stack">
|
|
|
|
<div class="pf-l-stack__item">
|
|
|
|
<div class="pf-c-card">
|
|
|
|
<div class="pf-c-card__body">
|
|
|
|
<form class="pf-c-form pf-m-horizontal">
|
|
|
|
<p>
|
|
|
|
${gettext(
|
2021-03-18 00:49:01 +00:00
|
|
|
`Are you sure you want to delete ${this.objectLabel} '${this.obj?.name}'?`
|
2021-03-18 00:43:12 +00:00
|
|
|
)}
|
|
|
|
</p>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<footer class="pf-c-modal-box__footer">
|
|
|
|
<ak-spinner-button
|
|
|
|
.callAction=${() => {
|
|
|
|
this.confirm();
|
|
|
|
}}
|
|
|
|
class="pf-m-danger">
|
|
|
|
${gettext("Delete")}
|
|
|
|
</ak-spinner-button>
|
|
|
|
<ak-spinner-button
|
|
|
|
.callAction=${() => {
|
|
|
|
this.open = false;
|
|
|
|
}}
|
|
|
|
class="pf-m-secondary">
|
|
|
|
${gettext("Cancel")}
|
|
|
|
</ak-spinner-button>
|
|
|
|
</footer>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|