2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-03-23 14:07:45 +00:00
|
|
|
import { customElement, html, property, TemplateResult } from "lit-element";
|
2021-03-23 14:16:56 +00:00
|
|
|
import { EVENT_REFRESH } from "../../constants";
|
2021-03-23 14:07:45 +00:00
|
|
|
import { ModalButton } from "../buttons/ModalButton";
|
2021-04-03 12:47:34 +00:00
|
|
|
import "../buttons/SpinnerButton";
|
2021-03-27 22:11:44 +00:00
|
|
|
import { MessageLevel } from "../messages/Message";
|
2021-03-23 14:07:45 +00:00
|
|
|
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<unknown>;
|
|
|
|
|
|
|
|
confirm(): void {
|
|
|
|
this.onConfirm().then(() => {
|
|
|
|
this.onSuccess();
|
|
|
|
this.open = false;
|
|
|
|
this.dispatchEvent(
|
2021-03-23 14:16:56 +00:00
|
|
|
new CustomEvent(EVENT_REFRESH, {
|
2021-03-23 14:07:45 +00:00
|
|
|
bubbles: true,
|
|
|
|
composed: true,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}).catch((e) => {
|
|
|
|
this.onError(e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSuccess(): void {
|
|
|
|
showMessage({
|
2021-04-03 17:26:43 +00:00
|
|
|
message: this.successMessage,
|
2021-03-27 22:11:44 +00:00
|
|
|
level: MessageLevel.success,
|
2021-03-23 14:07:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onError(e: Error): void {
|
|
|
|
showMessage({
|
2021-04-03 17:26:43 +00:00
|
|
|
message: t`${this.errorMessage}: ${e.toString()}`,
|
2021-03-27 22:11:44 +00:00
|
|
|
level: MessageLevel.error,
|
2021-03-23 14:07:45 +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">
|
|
|
|
<slot name="header"></slot>
|
|
|
|
</h1>
|
|
|
|
</div>
|
|
|
|
</section>
|
2021-04-04 11:44:57 +00:00
|
|
|
<section class="pf-c-page__main-section pf-m-light">
|
|
|
|
<form class="pf-c-form pf-m-horizontal">
|
|
|
|
<slot name="body"></slot>
|
|
|
|
</form>
|
2021-03-23 14:07:45 +00:00
|
|
|
</section>
|
|
|
|
<footer class="pf-c-modal-box__footer">
|
|
|
|
<ak-spinner-button
|
|
|
|
.callAction=${() => {
|
|
|
|
this.confirm();
|
|
|
|
}}
|
|
|
|
class="pf-m-danger">
|
2021-04-03 17:26:43 +00:00
|
|
|
${this.action}
|
2021-03-23 14:07:45 +00:00
|
|
|
</ak-spinner-button>
|
|
|
|
<ak-spinner-button
|
|
|
|
.callAction=${() => {
|
|
|
|
this.open = false;
|
|
|
|
}}
|
|
|
|
class="pf-m-secondary">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Cancel`}
|
2021-03-23 14:07:45 +00:00
|
|
|
</ak-spinner-button>
|
|
|
|
</footer>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|