diff --git a/crates/frontend/js-components/lib/edit-calendar-form.ts b/crates/frontend/js-components/lib/edit-calendar-form.ts new file mode 100644 index 0000000..b5e10b7 --- /dev/null +++ b/crates/frontend/js-components/lib/edit-calendar-form.ts @@ -0,0 +1,128 @@ +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-calendar-form") +export class EditCalendarForm extends LitElement { + constructor() { + super() + } + + protected override createRenderRoot() { + return this + } + + @property() + principal: string + @property() + cal_id: string + + @property() + displayname: string = '' + @property() + description: string = '' + @property() + color: string = '' + @property({ + converter: { + fromAttribute: (value, _type) => new Set(value ? JSON.parse(value) : []), + toAttribute: (value, _type) => JSON.stringify(value) + } + }) + components: Set<"VEVENT" | "VTODO" | "VJOURNAL"> = new Set() + + dialog: Ref = createRef() + form: Ref = createRef() + + + override render() { + return html` + + +

Create calendar

+
+ +
+ +
+ +
+ ${["VEVENT", "VTODO", "VJOURNAL"].map(comp => html` + +
+ `)} +
+ + +
+
+ ` + } + + async submit(e: SubmitEvent) { + e.preventDefault() + if (!this.principal) { + alert("Empty principal") + return + } + if (!this.cal_id) { + alert("Empty id") + return + } + if (!this.displayname) { + alert("Empty displayname") + return + } + if (!this.components.size) { + alert("No calendar components selected") + return + } + await fetch(`/caldav/principal/${this.principal}/${this.cal_id}`, { + method: 'PROPPATCH', + headers: { + 'Content-Type': 'application/xml' + }, + body: ` + + + + ${escapeXml(this.displayname)} + ${this.description ? `${escapeXml(this.description)}` : ''} + ${this.color ? `${escapeXml(this.color)}` : ''} + + ${Array.from(this.components.keys()).map(comp => ``).join('\n')} + + + + + + ${!this.description ? '' : ''} + ${!this.color ? '' : ''} + + + + ` + }) + window.location.reload() + return null + } +} + +declare global { + interface HTMLElementTagNameMap { + 'edit-calendar-form': EditCalendarForm + } +} diff --git a/crates/frontend/js-components/vite.config.ts b/crates/frontend/js-components/vite.config.ts index c25dcb9..eee645e 100644 --- a/crates/frontend/js-components/vite.config.ts +++ b/crates/frontend/js-components/vite.config.ts @@ -15,6 +15,7 @@ export default defineConfig({ rollupOptions: { input: [ "lib/create-calendar-form.ts", + "lib/edit-calendar-form.ts", "lib/create-addressbook-form.ts", "lib/delete-button.ts", ], diff --git a/crates/frontend/public/assets/js/edit-calendar-form.mjs b/crates/frontend/public/assets/js/edit-calendar-form.mjs new file mode 100644 index 0000000..7a29dd1 --- /dev/null +++ b/crates/frontend/public/assets/js/edit-calendar-form.mjs @@ -0,0 +1,142 @@ +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 EditCalendarForm = class extends i { + constructor() { + super(); + this.displayname = ""; + this.description = ""; + this.color = ""; + this.components = /* @__PURE__ */ new Set(); + this.dialog = e(); + this.form = e(); + } + createRenderRoot() { + return this; + } + render() { + return x` + + +

Create calendar

+
+ +
+ +
+ +
+ ${["VEVENT", "VTODO", "VJOURNAL"].map((comp) => x` + +
+ `)} +
+ + +
+
+ `; + } + async submit(e2) { + e2.preventDefault(); + if (!this.principal) { + alert("Empty principal"); + return; + } + if (!this.cal_id) { + alert("Empty id"); + return; + } + if (!this.displayname) { + alert("Empty displayname"); + return; + } + if (!this.components.size) { + alert("No calendar components selected"); + return; + } + await fetch(`/caldav/principal/${this.principal}/${this.cal_id}`, { + method: "PROPPATCH", + headers: { + "Content-Type": "application/xml" + }, + body: ` + + + + ${escapeXml(this.displayname)} + ${this.description ? `${escapeXml(this.description)}` : ""} + ${this.color ? `${escapeXml(this.color)}` : ""} + + ${Array.from(this.components.keys()).map((comp) => ``).join("\n")} + + + + + + ${!this.description ? "" : ""} + ${!this.color ? "" : ""} + + + + ` + }); + window.location.reload(); + return null; + } +}; +__decorateClass([ + n$1() +], EditCalendarForm.prototype, "principal", 2); +__decorateClass([ + n$1() +], EditCalendarForm.prototype, "cal_id", 2); +__decorateClass([ + n$1() +], EditCalendarForm.prototype, "displayname", 2); +__decorateClass([ + n$1() +], EditCalendarForm.prototype, "description", 2); +__decorateClass([ + n$1() +], EditCalendarForm.prototype, "color", 2); +__decorateClass([ + n$1({ + converter: { + fromAttribute: (value, _type) => new Set(value ? JSON.parse(value) : []), + toAttribute: (value, _type) => JSON.stringify(value) + } + }) +], EditCalendarForm.prototype, "components", 2); +EditCalendarForm = __decorateClass([ + t("edit-calendar-form") +], EditCalendarForm); +export { + EditCalendarForm +}; diff --git a/crates/frontend/public/templates/components/sections/calendars_section.html b/crates/frontend/public/templates/components/sections/calendars_section.html index e6b84b1..5820ccb 100644 --- a/crates/frontend/public/templates/components/sections/calendars_section.html +++ b/crates/frontend/public/templates/components/sections/calendars_section.html @@ -25,6 +25,14 @@ {% if !calendar.id.starts_with("_birthdays_") %} + {% endif %} diff --git a/crates/frontend/public/templates/pages/user.html b/crates/frontend/public/templates/pages/user.html index b5de34b..f1a5c48 100644 --- a/crates/frontend/public/templates/pages/user.html +++ b/crates/frontend/public/templates/pages/user.html @@ -6,6 +6,7 @@ window.rusticalUser = JSON.parse(document.querySelector('#data-rustical-user').innerHTML) + {% endblock %}