From d5281d2023b3221b9149d7eef09e8945c150e9b4 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 29 Mar 2021 18:22:15 +0200 Subject: [PATCH] web: set name on ak-form-element-horizontal for error messages Signed-off-by: Jens Langhammer --- .../elements/forms/HorizontalFormElement.ts | 15 +++++++++ .../pages/crypto/CertificateGenerateForm.ts | 25 ++++++++++----- .../pages/crypto/CertificateKeyPairForm.ts | 22 +++++++++---- web/src/pages/groups/GroupForm.ts | 31 ++++++++++++------ web/src/pages/users/UserForm.ts | 32 +++++++++++++------ web/src/utils.ts | 4 +-- 6 files changed, 92 insertions(+), 37 deletions(-) diff --git a/web/src/elements/forms/HorizontalFormElement.ts b/web/src/elements/forms/HorizontalFormElement.ts index b51033469..5e7497e4c 100644 --- a/web/src/elements/forms/HorizontalFormElement.ts +++ b/web/src/elements/forms/HorizontalFormElement.ts @@ -30,10 +30,25 @@ export class HorizontalFormElement extends LitElement { @property({ type: Boolean }) invalid = false; + @property() + name = ""; + updated(): void { this.querySelectorAll("input[autofocus]").forEach(input => { input.focus(); }); + this.querySelectorAll("*").forEach((input) => { + switch (input.tagName.toLowerCase()) { + case "input": + case "textarea": + case "select": + case "ak-codemirror": + (input as HTMLInputElement).name = this.name; + break; + default: + break; + } + }); } render(): TemplateResult { diff --git a/web/src/pages/crypto/CertificateGenerateForm.ts b/web/src/pages/crypto/CertificateGenerateForm.ts index f435b434a..c6cb18174 100644 --- a/web/src/pages/crypto/CertificateGenerateForm.ts +++ b/web/src/pages/crypto/CertificateGenerateForm.ts @@ -1,6 +1,7 @@ import { CertificateGeneration, CryptoApi } from "authentik-api"; +import { CertificateKeyPair } from "authentik-api/src"; import { gettext } from "django"; -import { customElement, property } from "lit-element"; +import { customElement } from "lit-element"; import { html, TemplateResult } from "lit-html"; import { DEFAULT_CONFIG } from "../../api/Config"; import { Form } from "../../elements/forms/Form"; @@ -13,7 +14,7 @@ export class CertificateKeyPairForm extends Form { return gettext("Successfully generated certificate-key pair."); } - send = (data: CertificateGeneration): Promise => { + send = (data: CertificateGeneration): Promise => { return new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsGenerate({ data: data }); @@ -21,15 +22,23 @@ export class CertificateKeyPairForm extends Form { renderForm(): TemplateResult { return html`
- - + + - - + +

${gettext("Optional, comma-separated SubjectAlt Names.")}

- - + + `; } diff --git a/web/src/pages/crypto/CertificateKeyPairForm.ts b/web/src/pages/crypto/CertificateKeyPairForm.ts index 9ccb58e39..168cc5a04 100644 --- a/web/src/pages/crypto/CertificateKeyPairForm.ts +++ b/web/src/pages/crypto/CertificateKeyPairForm.ts @@ -1,4 +1,4 @@ -import { CertificateKeyPair, CoreApi, CryptoApi, Group } from "authentik-api"; +import { CertificateKeyPair, CryptoApi } from "authentik-api"; import { gettext } from "django"; import { customElement, property } from "lit-element"; import { html, TemplateResult } from "lit-html"; @@ -38,16 +38,24 @@ export class CertificateKeyPairForm extends Form { renderForm(): TemplateResult { return html`
- - + + ${this.keyPair ? html`${gettext("Only change the fields below if you want to overwrite their values.")}` : html``} - - + +

${gettext("PEM-encoded Certificate data.")}

- - + +

${gettext("Optional Private Key. If this is set, you can use this keypair for encryption.")}

`; diff --git a/web/src/pages/groups/GroupForm.ts b/web/src/pages/groups/GroupForm.ts index d173f9326..1c3aee9d1 100644 --- a/web/src/pages/groups/GroupForm.ts +++ b/web/src/pages/groups/GroupForm.ts @@ -39,20 +39,26 @@ export class GroupForm extends Form { renderForm(): TemplateResult { return html`
- - + + - +
- +

${gettext("Users added to this group will be superusers.")}

- - ${until(new CoreApi(DEFAULT_CONFIG).coreGroupsList({}).then(groups => { return groups.results.map(group => { @@ -61,8 +67,11 @@ export class GroupForm extends Form { }), html``)} - - ${until(new CoreApi(DEFAULT_CONFIG).coreUsersList({}).then(users => { return users.results.map(user => { const selected = Array.from(this.group?.users || []).some(su => { @@ -74,8 +83,10 @@ export class GroupForm extends Form {

${gettext("Hold control/command to select multiple items.")}

- - + + `; diff --git a/web/src/pages/users/UserForm.ts b/web/src/pages/users/UserForm.ts index 0cc8c565b..b1b342ec9 100644 --- a/web/src/pages/users/UserForm.ts +++ b/web/src/pages/users/UserForm.ts @@ -38,28 +38,40 @@ export class UserForm extends Form { renderForm(): TemplateResult { return html`
- - + +

${gettext("Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.")}

- - + +

${gettext("User's display name.")}

- - + + - +
- +

${gettext("Designates whether this user should be treated as active. Unselect this instead of deleting accounts.")}

- - + + `; diff --git a/web/src/utils.ts b/web/src/utils.ts index 89c3e0eea..a9531be2b 100644 --- a/web/src/utils.ts +++ b/web/src/utils.ts @@ -53,6 +53,6 @@ export function loading(v: T, actual: TemplateResult): TemplateResult { } export function camelToSnake(key: string): string { - var result = key.replace(/([A-Z])/g, " $1"); - return result.split(' ').join('_').toLowerCase(); + const result = key.replace(/([A-Z])/g, " $1"); + return result.split(" ").join("_").toLowerCase(); }