import { html, LitElement } from "lit"; import { customElement, property } from "lit/decorators.js"; import { Ref, createRef, ref } from 'lit/directives/ref.js'; import { createClient } from "webdav"; import { escapeXml } from "."; @customElement("create-calendar-form") export class CreateCalendarForm extends LitElement { constructor() { super() } protected override createRenderRoot() { return this } client = createClient("/caldav") @property() user: string = '' @property() principal: string = '' @property() cal_id: string = '' @property() displayname: string = '' @property() description: string = '' @property() color: string = '' @property() isSubscription: boolean = false @property() subscriptionUrl: string = '' @property() components: Set<"VEVENT" | "VTODO" | "VJOURNAL"> = new Set() dialog: Ref = createRef() form: Ref = createRef() override render() { return html`

Create calendar








${this.isSubscription ? html`
`: html``}
${["VEVENT", "VTODO", "VJOURNAL"].map(comp => html`
`)}
` } async submit(e: SubmitEvent) { console.log(this.displayname) e.preventDefault() 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 this.client.createDirectory(`/principal/${this.principal || this.user}/${this.cal_id}`, { data: ` ${escapeXml(this.displayname)} ${this.description ? `${escapeXml(this.description)}` : ''} ${this.color ? `${escapeXml(this.color)}` : ''} ${(this.isSubscription && this.subscriptionUrl) ? `${escapeXml(this.subscriptionUrl)}` : ''} ${Array.from(this.components.keys()).map(comp => ``).join('\n')} ` }) window.location.reload() return null } } declare global { interface HTMLElementTagNameMap { 'create-calendar-form': CreateCalendarForm } }