From 35f423d4cabc57c83ff8ba3c815d6bdd02c066db Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Fri, 18 Jul 2025 21:08:11 +0200 Subject: [PATCH] frontend: Add addressbook editing form --- .../lib/edit-addressbook-form.ts | 97 ++++++++++++++++ crates/frontend/js-components/vite.config.ts | 1 + .../assets/js/edit-addressbook-form.mjs | 109 ++++++++++++++++++ .../sections/addressbooks_section.html | 6 + .../frontend/public/templates/pages/user.html | 1 + 5 files changed, 214 insertions(+) create mode 100644 crates/frontend/js-components/lib/edit-addressbook-form.ts create mode 100644 crates/frontend/public/assets/js/edit-addressbook-form.mjs diff --git a/crates/frontend/js-components/lib/edit-addressbook-form.ts b/crates/frontend/js-components/lib/edit-addressbook-form.ts new file mode 100644 index 0000000..d8b071d --- /dev/null +++ b/crates/frontend/js-components/lib/edit-addressbook-form.ts @@ -0,0 +1,97 @@ +import { html, LitElement } from "lit"; +import { customElement, property } from "lit/decorators.js"; +import { Ref, createRef, ref } from 'lit/directives/ref.js'; +import { escapeXml } from "."; + +@customElement("edit-addressbook-form") +export class EditAddressbookForm extends LitElement { + constructor() { + super() + + } + + protected override createRenderRoot() { + return this + } + + @property() + principal: string = '' + @property() + addr_id: string = '' + @property() + displayname: string = '' + @property() + description: string = '' + + dialog: Ref = createRef() + form: Ref = createRef() + + override render() { + return html` + + +

Create addressbook

+
+ +
+ +
+ + +
+
+ ` + } + + async submit(e: SubmitEvent) { + e.preventDefault() + if (!this.principal) { + alert("Empty principal") + return + } + if (!this.addr_id) { + alert("Empty id") + return + } + if (!this.displayname) { + alert("Empty displayname") + return + } + await fetch(`/carddav/principal/${this.principal}/${this.addr_id}`, { + method: 'PROPPATCH', + headers: { + 'Content-Type': 'application/xml' + }, + body: ` + + + + ${escapeXml(this.displayname)} + ${this.description ? `${escapeXml(this.description)}` : ''} + + + + + ${!this.description ? '' : ''} + + + + ` + + }) + window.location.reload() + return null + } +} + +declare global { + interface HTMLElementTagNameMap { + 'edit-addressbook-form': EditAddressbookForm + } +} diff --git a/crates/frontend/js-components/vite.config.ts b/crates/frontend/js-components/vite.config.ts index eee645e..3be6dbb 100644 --- a/crates/frontend/js-components/vite.config.ts +++ b/crates/frontend/js-components/vite.config.ts @@ -17,6 +17,7 @@ export default defineConfig({ "lib/create-calendar-form.ts", "lib/edit-calendar-form.ts", "lib/create-addressbook-form.ts", + "lib/edit-addressbook-form.ts", "lib/delete-button.ts", ], output: { diff --git a/crates/frontend/public/assets/js/edit-addressbook-form.mjs b/crates/frontend/public/assets/js/edit-addressbook-form.mjs new file mode 100644 index 0000000..10a5ae0 --- /dev/null +++ b/crates/frontend/public/assets/js/edit-addressbook-form.mjs @@ -0,0 +1,109 @@ +import { i, x } from "./lit-z6_uA4GX.mjs"; +import { n as n$1, t } from "./property-D0NJdseG.mjs"; +import { e, n, a as escapeXml } from "./index-b86iLJlP.mjs"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __decorateClass = (decorators, target, key, kind) => { + var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target; + for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--) + if (decorator = decorators[i2]) + result = (kind ? decorator(target, key, result) : decorator(result)) || result; + if (kind && result) __defProp(target, key, result); + return result; +}; +let EditAddressbookForm = class extends i { + constructor() { + super(); + this.principal = ""; + this.addr_id = ""; + this.displayname = ""; + this.description = ""; + this.dialog = e(); + this.form = e(); + } + createRenderRoot() { + return this; + } + render() { + return x` + + +

Create addressbook

+
+ +
+ +
+ + +
+
+ `; + } + async submit(e2) { + e2.preventDefault(); + if (!this.principal) { + alert("Empty principal"); + return; + } + if (!this.addr_id) { + alert("Empty id"); + return; + } + if (!this.displayname) { + alert("Empty displayname"); + return; + } + await fetch(`/carddav/principal/${this.principal}/${this.addr_id}`, { + method: "PROPPATCH", + headers: { + "Content-Type": "application/xml" + }, + body: ` + + + + ${escapeXml(this.displayname)} + ${this.description ? `${escapeXml(this.description)}` : ""} + + + + + ${!this.description ? "" : ""} + + + + ` + }); + window.location.reload(); + return null; + } +}; +__decorateClass([ + n$1() +], EditAddressbookForm.prototype, "principal", 2); +__decorateClass([ + n$1() +], EditAddressbookForm.prototype, "addr_id", 2); +__decorateClass([ + n$1() +], EditAddressbookForm.prototype, "displayname", 2); +__decorateClass([ + n$1() +], EditAddressbookForm.prototype, "description", 2); +EditAddressbookForm = __decorateClass([ + t("edit-addressbook-form") +], EditAddressbookForm); +export { + EditAddressbookForm +}; diff --git a/crates/frontend/public/templates/components/sections/addressbooks_section.html b/crates/frontend/public/templates/components/sections/addressbooks_section.html index 73c817c..bf0b9a8 100644 --- a/crates/frontend/public/templates/components/sections/addressbooks_section.html +++ b/crates/frontend/public/templates/components/sections/addressbooks_section.html @@ -16,6 +16,12 @@ method="GET"> + diff --git a/crates/frontend/public/templates/pages/user.html b/crates/frontend/public/templates/pages/user.html index f1a5c48..89d12cb 100644 --- a/crates/frontend/public/templates/pages/user.html +++ b/crates/frontend/public/templates/pages/user.html @@ -8,6 +8,7 @@ window.rusticalUser = JSON.parse(document.querySelector('#data-rustical-user').i + {% endblock %} {% block header_center %}