From 768d72ec24b702bdba0c1d7138fefb9b8225a8a9 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 28 Mar 2021 22:07:11 +0200 Subject: [PATCH] web/admin: implement groupform using webcomponents Signed-off-by: Jens Langhammer --- web/package-lock.json | 310 ---------------------------- web/package.json | 6 - web/src/elements/forms/Form.ts | 54 +++-- web/src/elements/forms/ModalForm.ts | 4 +- web/src/elements/forms/utils.ts | 16 ++ web/src/pages/groups/GroupForm.ts | 87 ++++---- 6 files changed, 91 insertions(+), 386 deletions(-) create mode 100644 web/src/elements/forms/utils.ts diff --git a/web/package-lock.json b/web/package-lock.json index f125fff3b..1026420cd 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -133,27 +133,6 @@ "resolved": "https://registry.npmjs.org/@patternfly/patternfly/-/patternfly-4.90.5.tgz", "integrity": "sha512-Fe0C8UkzSjtacQ+fHXlFB/LHzrv/c2K4z479C6dboOgkGQE1FyB0wt1NBfxij0D++rhOy04OOYdE+Tr0JSlZKw==" }, - "@polymer/font-roboto": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@polymer/font-roboto/-/font-roboto-3.0.2.tgz", - "integrity": "sha512-tx5TauYSmzsIvmSqepUPDYbs4/Ejz2XbZ1IkD7JEGqkdNUJlh+9KU85G56Tfdk/xjEZ8zorFfN09OSwiMrIQWA==" - }, - "@polymer/iron-a11y-announcer": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@polymer/iron-a11y-announcer/-/iron-a11y-announcer-3.1.0.tgz", - "integrity": "sha512-lc5i4NKB8kSQHH0Hwu8WS3ym93m+J69OHJWSSBxwd17FI+h2wmgxDzeG9LI4ojMMck17/uc2pLe7g/UHt5/K/A==", - "requires": { - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-a11y-keys-behavior": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-a11y-keys-behavior/-/iron-a11y-keys-behavior-3.0.1.tgz", - "integrity": "sha512-lnrjKq3ysbBPT/74l0Fj0U9H9C35Tpw2C/tpJ8a+5g8Y3YJs1WSZYnEl1yOkw6sEyaxOq/1DkzH0+60gGu5/PQ==", - "requires": { - "@polymer/polymer": "^3.0.0" - } - }, "@polymer/iron-ajax": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/@polymer/iron-ajax/-/iron-ajax-3.0.1.tgz", @@ -162,63 +141,6 @@ "@polymer/polymer": "^3.0.0" } }, - "@polymer/iron-autogrow-textarea": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@polymer/iron-autogrow-textarea/-/iron-autogrow-textarea-3.0.3.tgz", - "integrity": "sha512-5r0VkWrIlm0JIp5E5wlnvkw7slK72lFRZXncmrsLZF+6n1dg2rI8jt7xpFzSmUWrqpcyXwyKaGaDvUjl3j4JLA==", - "requires": { - "@polymer/iron-behaviors": "^3.0.0-pre.26", - "@polymer/iron-flex-layout": "^3.0.0-pre.26", - "@polymer/iron-validatable-behavior": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-behaviors": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-behaviors/-/iron-behaviors-3.0.1.tgz", - "integrity": "sha512-IMEwcv1lhf1HSQxuyWOUIL0lOBwmeaoSTpgCJeP9IBYnuB1SPQngmfRuHKgK6/m9LQ9F9miC7p3HeQQUdKAE0w==", - "requires": { - "@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-checked-element-behavior": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-checked-element-behavior/-/iron-checked-element-behavior-3.0.1.tgz", - "integrity": "sha512-aDr0cbCNVq49q+pOqa6CZutFh+wWpwPMLpEth9swx+GkAj+gCURhuQkaUYhIo5f2egDbEioR1aeHMnPlU9dQZA==", - "requires": { - "@polymer/iron-form-element-behavior": "^3.0.0-pre.26", - "@polymer/iron-validatable-behavior": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-dropdown": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-dropdown/-/iron-dropdown-3.0.1.tgz", - "integrity": "sha512-22yLhepfcKjuQMfFmRHi/9MPKTqkzgRrmWWW0P5uqK++xle53k2QBO5VYUAYiCN3ZcxIi9lEhZ9YWGeQj2JBig==", - "requires": { - "@polymer/iron-behaviors": "^3.0.0-pre.26", - "@polymer/iron-overlay-behavior": "^3.0.0-pre.27", - "@polymer/neon-animation": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-fit-behavior": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@polymer/iron-fit-behavior/-/iron-fit-behavior-3.1.0.tgz", - "integrity": "sha512-ABcgIYqrjhmUT8tiuolqeGttF/8pd3sEymUDrO1vXbZu4FWIvoLNndrMDFvs++AGd12Mjf5pYy84NJc6dB8Vig==", - "requires": { - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-flex-layout": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-flex-layout/-/iron-flex-layout-3.0.1.tgz", - "integrity": "sha512-7gB869czArF+HZcPTVSgvA7tXYFze9EKckvM95NB7SqYF+NnsQyhoXgKnpFwGyo95lUjUW9TFDLUwDXnCYFtkw==", - "requires": { - "@polymer/polymer": "^3.0.0" - } - }, "@polymer/iron-form": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/@polymer/iron-form/-/iron-form-3.0.1.tgz", @@ -228,238 +150,6 @@ "@polymer/polymer": "^3.0.0" } }, - "@polymer/iron-form-element-behavior": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-form-element-behavior/-/iron-form-element-behavior-3.0.1.tgz", - "integrity": "sha512-G/e2KXyL5AY7mMjmomHkGpgS0uAf4ovNpKhkuUTRnMuMJuf589bKqE85KN4ovE1Tzhv2hJoh/igyD6ekHiYU1A==", - "requires": { - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-icon": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-icon/-/iron-icon-3.0.1.tgz", - "integrity": "sha512-QLPwirk+UPZNaLnMew9VludXA4CWUCenRewgEcGYwdzVgDPCDbXxy6vRJjmweZobMQv/oVLppT2JZtJFnPxX6g==", - "requires": { - "@polymer/iron-flex-layout": "^3.0.0-pre.26", - "@polymer/iron-meta": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-iconset-svg": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-iconset-svg/-/iron-iconset-svg-3.0.1.tgz", - "integrity": "sha512-XNwURbNHRw6u2fJe05O5fMYye6GSgDlDqCO+q6K1zAnKIrpgZwf2vTkBd5uCcZwsN0FyCB3mvNZx4jkh85dRDw==", - "requires": { - "@polymer/iron-meta": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-input": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-input/-/iron-input-3.0.1.tgz", - "integrity": "sha512-WLx13kEcbH9GKbj9+pWR6pbJkA5kxn3796ynx6eQd2rueMyUfVTR3GzOvadBKsciUuIuzrxpBWZ2+3UcueVUQQ==", - "requires": { - "@polymer/iron-a11y-announcer": "^3.0.0-pre.26", - "@polymer/iron-validatable-behavior": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-list": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@polymer/iron-list/-/iron-list-3.1.0.tgz", - "integrity": "sha512-Eiv6xd3h3oPmn8SXFntXVfC3ZnegH+KHAxiKLKcOASFSRY3mHnr2AdcnExUJ9ItoCMA5UzKaM/0U22eWzGERtA==", - "requires": { - "@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.26", - "@polymer/iron-resizable-behavior": "^3.0.0-pre.26", - "@polymer/iron-scroll-target-behavior": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-menu-behavior": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@polymer/iron-menu-behavior/-/iron-menu-behavior-3.0.2.tgz", - "integrity": "sha512-8dpASkFNBIkxAJWsFLWIO1M7tKM0+wKs3PqdeF/dDdBciwoaaFgC2K1XCZFZnbe2t9/nJgemXxVugGZAWpYCGg==", - "requires": { - "@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.26", - "@polymer/iron-flex-layout": "^3.0.0-pre.26", - "@polymer/iron-selector": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-meta": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-meta/-/iron-meta-3.0.1.tgz", - "integrity": "sha512-pWguPugiLYmWFV9UWxLWzZ6gm4wBwQdDy4VULKwdHCqR7OP7u98h+XDdGZsSlDPv6qoryV/e3tGHlTIT0mbzJA==", - "requires": { - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-overlay-behavior": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@polymer/iron-overlay-behavior/-/iron-overlay-behavior-3.0.3.tgz", - "integrity": "sha512-Q/Fp0+uOQQ145ebZ7T8Cxl4m1tUKYjyymkjcL2rXUm+aDQGb1wA1M1LYxUF5YBqd+9lipE0PTIiYwA2ZL/sznA==", - "requires": { - "@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.26", - "@polymer/iron-fit-behavior": "^3.0.0-pre.26", - "@polymer/iron-resizable-behavior": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-resizable-behavior": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-resizable-behavior/-/iron-resizable-behavior-3.0.1.tgz", - "integrity": "sha512-FyHxRxFspVoRaeZSWpT3y0C9awomb4tXXolIJcZ7RvXhMP632V5lez+ch5G5SwK0LpnAPkg35eB0LPMFv+YMMQ==", - "requires": { - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-scroll-target-behavior": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-scroll-target-behavior/-/iron-scroll-target-behavior-3.0.1.tgz", - "integrity": "sha512-xg1WanG25BIkQE8rhuReqY9zx1K5M7F+YAIYpswEp5eyDIaZ1Y3vUmVeQ3KG+hiSugzI1M752azXN7kvyhOBcQ==", - "requires": { - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-selector": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-selector/-/iron-selector-3.0.1.tgz", - "integrity": "sha512-sBVk2uas6prW0glUe2xEJJYlvxmYzM40Au9OKbfDK2Qekou/fLKcBRyIYI39kuI8zWRaip8f3CI8qXcUHnKb1A==", - "requires": { - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/iron-validatable-behavior": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/iron-validatable-behavior/-/iron-validatable-behavior-3.0.1.tgz", - "integrity": "sha512-wwpYh6wOa4fNI+jH5EYKC7TVPYQ2OfgQqocWat7GsNWcsblKYhLYbwsvEY5nO0n2xKqNfZzDLrUom5INJN7msQ==", - "requires": { - "@polymer/iron-meta": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/neon-animation": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/neon-animation/-/neon-animation-3.0.1.tgz", - "integrity": "sha512-cDDc0llpVCe0ATbDS3clDthI54Bc8YwZIeTGGmBJleKOvbRTUC5+ssJmRL+VwVh+VM5FlnQlx760ppftY3uprg==", - "requires": { - "@polymer/iron-resizable-behavior": "^3.0.0-pre.26", - "@polymer/iron-selector": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/paper-behaviors": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/paper-behaviors/-/paper-behaviors-3.0.1.tgz", - "integrity": "sha512-6knhj69fPJejv8qR0kCSUY+Q0XjaUf0OSnkjRjmTJPAwSrRYtgqE+l6P1FfA+py1X/cUjgne9EF5rMZAKJIg1g==", - "requires": { - "@polymer/iron-behaviors": "^3.0.0-pre.26", - "@polymer/iron-checked-element-behavior": "^3.0.0-pre.26", - "@polymer/paper-ripple": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/paper-checkbox": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@polymer/paper-checkbox/-/paper-checkbox-3.1.0.tgz", - "integrity": "sha512-kXm6yDG1tT8if0XuJ2cc9NF+g8Ev4wG+rnf0a+Sx+O7J6fn1jcnBlYn72FlrfjVjDQZDBFmT6nynhD5PvFw8iQ==", - "requires": { - "@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.26", - "@polymer/iron-checked-element-behavior": "^3.0.0-pre.26", - "@polymer/paper-behaviors": "^3.0.0-pre.27", - "@polymer/paper-ripple": "^3.0.0-pre.26", - "@polymer/paper-styles": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/paper-dropdown-menu": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@polymer/paper-dropdown-menu/-/paper-dropdown-menu-3.2.0.tgz", - "integrity": "sha512-2ohwSHF+RLSK6kA0UkkMiMQF6EZcaEYWAA25kfisI6DWie7yozKrpQNsqvwfOEHU6DdDMIotrOtH1TM88YS8Zg==", - "requires": { - "@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.26", - "@polymer/iron-form-element-behavior": "^3.0.0-pre.26", - "@polymer/iron-icon": "^3.0.0-pre.26", - "@polymer/iron-iconset-svg": "^3.0.0-pre.26", - "@polymer/iron-validatable-behavior": "^3.0.0-pre.26", - "@polymer/paper-behaviors": "^3.0.0-pre.27", - "@polymer/paper-input": "^3.1.0", - "@polymer/paper-menu-button": "^3.1.0", - "@polymer/paper-ripple": "^3.0.0-pre.26", - "@polymer/paper-styles": "^3.0.0-pre.26", - "@polymer/polymer": "^3.3.1" - } - }, - "@polymer/paper-input": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/@polymer/paper-input/-/paper-input-3.2.1.tgz", - "integrity": "sha512-6ghgwQKM6mS0hAQxQqj+tkeEY1VUBqAsrasAm8V5RpNcfSWQC/hhRFxU0beGuKTAhndzezDzWYP6Zz4b8fExGg==", - "requires": { - "@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.26", - "@polymer/iron-autogrow-textarea": "^3.0.0-pre.26", - "@polymer/iron-behaviors": "^3.0.0-pre.26", - "@polymer/iron-form-element-behavior": "^3.0.0-pre.26", - "@polymer/iron-input": "^3.0.0-pre.26", - "@polymer/paper-styles": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/paper-item": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/paper-item/-/paper-item-3.0.1.tgz", - "integrity": "sha512-KTk2N+GsYiI/HuubL3sxebZ6tteQbBOAp4QVLAnbjSPmwl+mJSDWk+omuadesU0bpkCwaWVs3fHuQsmXxy4pkw==", - "requires": { - "@polymer/iron-behaviors": "^3.0.0-pre.26", - "@polymer/iron-flex-layout": "^3.0.0-pre.26", - "@polymer/paper-styles": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/paper-listbox": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/paper-listbox/-/paper-listbox-3.0.1.tgz", - "integrity": "sha512-vMLWFpYcggAPmEDBmK+96fFefacOG3GLB1EguTn8+ZkqI+328hNfw1MzHjH68rgCIIUtjmm+9qgB1Sy/MN0a/A==", - "requires": { - "@polymer/iron-behaviors": "^3.0.0-pre.26", - "@polymer/iron-menu-behavior": "^3.0.0-pre.26", - "@polymer/paper-styles": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/paper-menu-button": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@polymer/paper-menu-button/-/paper-menu-button-3.1.0.tgz", - "integrity": "sha512-q0G0/rvYD/FFmIBMGCQWjfXzRqwFw9+WHSYV4uOQzM1Ln8LMXSAd+2CENsbVwtMh6fmBePj15ZlU8SM2dt1WDQ==", - "requires": { - "@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.26", - "@polymer/iron-behaviors": "^3.0.0-pre.26", - "@polymer/iron-dropdown": "^3.0.0-pre.26", - "@polymer/iron-fit-behavior": "^3.1.0", - "@polymer/neon-animation": "^3.0.0-pre.26", - "@polymer/paper-styles": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/paper-ripple": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@polymer/paper-ripple/-/paper-ripple-3.0.2.tgz", - "integrity": "sha512-DnLNvYIMsiayeICroYxx6Q6Hg1cUU8HN2sbutXazlemAlGqdq80qz3TIaVdbpbt/pvjcFGX2HtntMlPstCge8Q==", - "requires": { - "@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, - "@polymer/paper-styles": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@polymer/paper-styles/-/paper-styles-3.0.1.tgz", - "integrity": "sha512-y6hmObLqlCx602TQiSBKHqjwkE7xmDiFkoxdYGaNjtv4xcysOTdVJsDR/R9UHwIaxJ7gHlthMSykir1nv78++g==", - "requires": { - "@polymer/font-roboto": "^3.0.1", - "@polymer/iron-flex-layout": "^3.0.0-pre.26", - "@polymer/polymer": "^3.0.0" - } - }, "@polymer/polymer": { "version": "3.4.1", "resolved": "https://registry.npmjs.org/@polymer/polymer/-/polymer-3.4.1.tgz", diff --git a/web/package.json b/web/package.json index 40d4c5203..c1c65e5c5 100644 --- a/web/package.json +++ b/web/package.json @@ -13,11 +13,6 @@ "@fortawesome/fontawesome-free": "^5.15.3", "@patternfly/patternfly": "^4.90.5", "@polymer/iron-form": "^3.0.1", - "@polymer/paper-checkbox": "^3.1.0", - "@polymer/paper-dropdown-menu": "^3.2.0", - "@polymer/paper-input": "^3.2.1", - "@polymer/paper-item": "^3.0.1", - "@polymer/paper-listbox": "^3.0.1", "@sentry/browser": "^6.2.3", "@sentry/tracing": "^6.2.3", "@types/chart.js": "^2.9.31", @@ -31,7 +26,6 @@ "flowchart.js": "^1.15.0", "lit-element": "^2.4.0", "lit-html": "^1.3.0", - "multiselect-combo-box": "^2.5.0-beta.3", "rapidoc": "^8.4.9", "rollup": "^2.42.4", "rollup-plugin-copy": "^3.4.0", diff --git a/web/src/elements/forms/Form.ts b/web/src/elements/forms/Form.ts index 6a7c84282..5028579f9 100644 --- a/web/src/elements/forms/Form.ts +++ b/web/src/elements/forms/Form.ts @@ -10,6 +10,7 @@ import AKGlobal from "../../authentik.css"; import PFForm from "@patternfly/patternfly/components/Form/form.css"; import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css"; import { MessageLevel } from "../messages/Message"; +import { IronFormElement } from "@polymer/iron-form/iron-form"; interface ErrorResponse { [key: string]: string[]; @@ -40,6 +41,23 @@ export class Form extends LitElement { `]; } + serializeForm(form: IronFormElement): T { + const elements = form._getSubmittableElements(); + const json: { [key: string]: unknown } = {}; + for (let i = 0; i < elements.length; i++) { + const element = elements[i] as HTMLInputElement; + const values = form._serializeElementValues(element); + if (element.tagName.toLowerCase() === "select" && "multiple" in element.attributes) { + json[element.name] = values; + } else { + for (let v = 0; v < values.length; v++) { + form._addSerializedElement(json, element.name, values[v]); + } + } + } + return json as unknown as T; + } + submit(ev: Event): Promise | undefined { ev.preventDefault(); const ironForm = this.shadowRoot?.querySelector("iron-form"); @@ -47,7 +65,7 @@ export class Form extends LitElement { console.warn("authentik/forms: failed to find iron-form"); return; } - const data = ironForm.serializeForm() as T; + const data = this.serializeForm(ironForm); return this.send(data).then((r) => { showMessage({ level: MessageLevel.success, @@ -56,24 +74,24 @@ export class Form extends LitElement { return r; }).catch((ex: Response) => { if (ex.status > 399 && ex.status < 500) { - return ex.json(); + return ex.json().then((errorMessage: ErrorResponse) => { + if (!errorMessage) return errorMessage; + if (errorMessage instanceof Error) { + throw errorMessage; + } + const elements: PaperInputElement[] = ironForm._getSubmittableElements(); + elements.forEach((element) => { + const elementName = element.name; + if (!elementName) return; + if (elementName in errorMessage) { + element.errorMessage = errorMessage[elementName].join(", "); + element.invalid = true; + } + }); + throw new APIError(errorMessage); + }); } - return ex; - }).then((errorMessage: ErrorResponse | Error) => { - if (!errorMessage) return errorMessage; - if (errorMessage instanceof Error) { - throw errorMessage; - } - const elements: PaperInputElement[] = ironForm._getSubmittableElements(); - elements.forEach((element) => { - const elementName = element.name; - if (!elementName) return; - if (elementName in errorMessage) { - element.errorMessage = errorMessage[elementName].join(", "); - element.invalid = true; - } - }); - throw new APIError(errorMessage); + throw ex; }); } diff --git a/web/src/elements/forms/ModalForm.ts b/web/src/elements/forms/ModalForm.ts index 194c7b21e..488e4ebcf 100644 --- a/web/src/elements/forms/ModalForm.ts +++ b/web/src/elements/forms/ModalForm.ts @@ -1,5 +1,5 @@ import { gettext } from "django"; -import { customElement, html, property, TemplateResult } from "lit-element"; +import { customElement, html, TemplateResult } from "lit-element"; import { ModalButton } from "../buttons/ModalButton"; import { Form } from "./Form"; @@ -12,7 +12,7 @@ export class ModalForm extends ModalButton { if (!formPromise) { return; } - formPromise.then((a) => { + formPromise.then(() => { this.open = false; }).catch((e) => { console.log(e); diff --git a/web/src/elements/forms/utils.ts b/web/src/elements/forms/utils.ts new file mode 100644 index 000000000..79ff0dc68 --- /dev/null +++ b/web/src/elements/forms/utils.ts @@ -0,0 +1,16 @@ +import { TemplateResult, html } from "lit-html"; + +export function formGroup(label: string, body: TemplateResult): TemplateResult { + return html`
+
+ +
+
+
+ ${body} +
+
+
`; +} diff --git a/web/src/pages/groups/GroupForm.ts b/web/src/pages/groups/GroupForm.ts index 6ad02c63f..996f016d4 100644 --- a/web/src/pages/groups/GroupForm.ts +++ b/web/src/pages/groups/GroupForm.ts @@ -4,14 +4,9 @@ import { customElement, property } from "lit-element"; import { html, TemplateResult } from "lit-html"; import { DEFAULT_CONFIG } from "../../api/Config"; import { Form } from "../../elements/forms/Form"; -import { ifDefined } from "lit-html/directives/if-defined"; -import "@polymer/paper-input/paper-input"; -import "@polymer/iron-form/iron-form"; -import '@polymer/paper-checkbox/paper-checkbox'; -import '@polymer/paper-dropdown-menu/paper-dropdown-menu'; -import '@polymer/paper-listbox/paper-listbox'; -import '@polymer/paper-item/paper-item'; import { until } from "lit-html/directives/until"; +import { formGroup } from "../../elements/forms/utils"; +import { ifDefined } from "lit-html/directives/if-defined"; @customElement("ak-group-form") export class GroupForm extends Form { @@ -19,6 +14,8 @@ export class GroupForm extends Form { @property({attribute: false}) group?: Group; + successMessage = gettext("Successfully updated group"); + send = (data: Group): Promise => { if (this.group) { return new CoreApi(DEFAULT_CONFIG).coreGroupsUpdate({ @@ -34,51 +31,41 @@ export class GroupForm extends Form { renderForm(): TemplateResult { return html`
- - - - ${gettext("Is superuser")} - -

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

- - - ${gettext("No parent")} - ${until(new CoreApi(DEFAULT_CONFIG).coreGroupsList({}).then(groups => { - return groups.results.map(group => { - return html`${group.name}`; - }) - }), html``)} - - -
-
-
+

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

+ `)} + ${formGroup(gettext("Parent"), html` + + `)} + ${formGroup(gettext("Members"), html` + +

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

+ `)} `; }