diff --git a/web/src/elements/forms/Form.ts b/web/src/elements/forms/Form.ts index 57297f1f5..786c4cf03 100644 --- a/web/src/elements/forms/Form.ts +++ b/web/src/elements/forms/Form.ts @@ -15,6 +15,7 @@ import { MessageLevel } from "../messages/Message"; import { IronFormElement } from "@polymer/iron-form/iron-form"; import { camelToSnake, convertToSlug } from "../../utils"; import { ValidationError } from "authentik-api/src"; +import { EVENT_REFRESH } from "../../constants"; export class APIError extends Error { @@ -140,6 +141,12 @@ export class Form extends LitElement { level: MessageLevel.success, message: this.getSuccessMessage() }); + this.dispatchEvent( + new CustomEvent(EVENT_REFRESH, { + bubbles: true, + composed: true, + }) + ); return r; }).catch((ex: Response) => { if (ex.status > 399 && ex.status < 500) { diff --git a/web/src/elements/forms/ModelForm.ts b/web/src/elements/forms/ModelForm.ts new file mode 100644 index 000000000..612fcab48 --- /dev/null +++ b/web/src/elements/forms/ModelForm.ts @@ -0,0 +1,32 @@ +import { property } from "lit-element"; +import { EVENT_REFRESH } from "../../constants"; +import { Form } from "./Form"; + +export abstract class ModelForm extends Form { + + abstract loadInstance(pk: PKT): Promise; + + @property() + set instancePk(value: PKT) { + this._instancePk = value; + this.loadInstance(value).then(instance => { + this.instance = instance; + }); + } + + private _instancePk?: PKT; + + @property({ attribute: false }) + instance?: T; + + constructor() { + super(); + this.addEventListener(EVENT_REFRESH, () => { + if (!this._instancePk) return; + this.loadInstance(this._instancePk).then(instance => { + this.instance = instance; + }); + }); + } + +}