web/elements: add ModalForm
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
@ -17,14 +17,14 @@ export class Form extends LitElement {
|
||||
@property()
|
||||
send!: (data: Record<string, unknown>) => Promise<unknown>;
|
||||
|
||||
submit(ev: Event): void {
|
||||
submit(ev: Event): Promise<unknown> | undefined {
|
||||
ev.preventDefault();
|
||||
const ironForm = this.shadowRoot?.querySelector("iron-form");
|
||||
if (!ironForm) {
|
||||
return;
|
||||
}
|
||||
const data = ironForm.serializeForm();
|
||||
this.send(data).then(() => {
|
||||
return this.send(data).then(() => {
|
||||
showMessage({
|
||||
level_tag: "success",
|
||||
message: this.successMessage
|
||||
|
||||
58
web/src/elements/forms/ModalForm.ts
Normal file
58
web/src/elements/forms/ModalForm.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import { gettext } from "django";
|
||||
import { customElement, html, property, TemplateResult } from "lit-element";
|
||||
import { ModalButton } from "../buttons/ModalButton";
|
||||
import { Form } from "./Form";
|
||||
|
||||
@customElement("ak-forms-modal")
|
||||
export class DeleteForm extends ModalButton {
|
||||
|
||||
confirm(): void {
|
||||
this.querySelectorAll<Form>("ak-form").forEach(form => {
|
||||
const formPromise = form.submit(new Event("submit"));
|
||||
if (!formPromise) {
|
||||
return;
|
||||
}
|
||||
formPromise.then(() => {
|
||||
this.open = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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">
|
||||
<slot name="header"></slot>
|
||||
</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">
|
||||
<slot name="form"></slot>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<footer class="pf-c-modal-box__footer">
|
||||
<ak-spinner-button
|
||||
.callAction=${() => {
|
||||
this.confirm();
|
||||
}}
|
||||
class="pf-m-primary">
|
||||
<slot name="submit"></slot>
|
||||
</ak-spinner-button>
|
||||
<ak-spinner-button
|
||||
.callAction=${() => {
|
||||
this.open = false;
|
||||
}}
|
||||
class="pf-m-secondary">
|
||||
${gettext("Cancel")}
|
||||
</ak-spinner-button>
|
||||
</footer>`;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user