web: simplify DeleteForm

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-03-18 01:49:01 +01:00
parent a95b6e0e61
commit bc37480f0d
1 changed files with 5 additions and 10 deletions

View File

@ -1,23 +1,18 @@
import { gettext } from "django"; import { gettext } from "django";
import { customElement, html, property, TemplateResult } from "lit-element"; import { customElement, html, property, TemplateResult } from "lit-element";
import { BaseInheritanceModel } from "../../api/Client";
import { ModalButton } from "../buttons/ModalButton"; import { ModalButton } from "../buttons/ModalButton";
export interface DeletableObject extends BaseInheritanceModel {
name: string | number;
}
@customElement("ak-forms-delete") @customElement("ak-forms-delete")
export class DeleteForm extends ModalButton { export class DeleteForm extends ModalButton {
@property() @property({attribute: false})
obj?: DeletableObject; obj?: Record<string, unknown>;
@property() @property()
objectLabel?: string; objectLabel?: string;
@property({attribute: false}) @property({attribute: false})
delete!: () => Promise<DeletableObject>; delete!: () => Promise<void>;
confirm(): void { confirm(): void {
this.delete().then(() => { this.delete().then(() => {
@ -35,7 +30,7 @@ export class DeleteForm extends ModalButton {
return html`<section class="pf-c-page__main-section pf-m-light"> return html`<section class="pf-c-page__main-section pf-m-light">
<div class="pf-c-content"> <div class="pf-c-content">
<h1 class="pf-c-title pf-m-2xl"> <h1 class="pf-c-title pf-m-2xl">
${gettext(`Delete ${(this.obj?.verboseName) || this.objectLabel}`)} ${gettext(`Delete ${this.objectLabel}`)}
</h1> </h1>
</div> </div>
</section> </section>
@ -47,7 +42,7 @@ export class DeleteForm extends ModalButton {
<form class="pf-c-form pf-m-horizontal"> <form class="pf-c-form pf-m-horizontal">
<p> <p>
${gettext( ${gettext(
`Are you sure you want to delete ${(this.obj?.verboseName) || this.objectLabel} '${this.obj?.name}'?` `Are you sure you want to delete ${this.objectLabel} '${this.obj?.name}'?`
)} )}
</p> </p>
</form> </form>