From 15e50471776e702333920b188932f03ee1f8573b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 9 Dec 2021 19:17:46 +0100 Subject: Propagate recurring events to frontend. This handles each instance of a recurring event as its own unique event, which allows us to properly send it to the frontend. It's currently not possible to submit the repeating events back, but that is probably a underlying problem. --- static/components/edit-rrule.ts | 18 ++++++++++++++++++ static/components/vevent-edit.ts | 6 ++++++ static/jcal.ts | 14 +++++++++++--- static/vevent.ts | 2 +- 4 files changed, 36 insertions(+), 4 deletions(-) (limited to 'static') diff --git a/static/components/edit-rrule.ts b/static/components/edit-rrule.ts index 6be01b76..cac19e80 100644 --- a/static/components/edit-rrule.ts +++ b/static/components/edit-rrule.ts @@ -17,6 +17,24 @@ class EditRRule extends ComponentVEvent { let frag = this.template.content.cloneNode(true) as DocumentFragment let body = frag.firstElementChild! this.replaceChildren(body); + + for (let el of this.querySelectorAll('[name]')) { + el.addEventListener('input', () => { + // console.log(this); + let data = vcal_objects.get(this.uid)!; + let rrule = data.getProperty('rrule') + if (!rrule) { + console.warn('RRUle missing from object'); + return; + } + rrule = rrule as RecurrenceRule + + console.log(el.getAttribute('name'), (el as any).value); + rrule[el.getAttribute('name')!] = (el as any).value; + data.setProperty('rrule', rrule); + + }); + } } connectedCallback() { diff --git a/static/components/vevent-edit.ts b/static/components/vevent-edit.ts index d48c7967..5c482882 100644 --- a/static/components/vevent-edit.ts +++ b/static/components/vevent-edit.ts @@ -7,6 +7,7 @@ import { DateTimeInput } from './date-time-input' import { vcal_objects } from '../globals' import { VEvent, RecurrenceRule } from '../vevent' import { create_event } from '../server_connect' +import { to_boolean } from '../lib' /* Edit form for a given VEvent. Used as the edit tab of popups. @@ -148,6 +149,11 @@ class ComponentEdit extends ComponentVEvent { } } + let el = this.querySelector('[name="has_repeats"]') + if (el) { + (el as HTMLInputElement).checked = to_boolean(data.getProperty('rrule')) + } + if (data.calendar) { for (let el of this.getElementsByClassName('calendar-selection')) { (el as HTMLSelectElement).value = data.calendar; diff --git a/static/jcal.ts b/static/jcal.ts index 605f41e7..41f33db4 100644 --- a/static/jcal.ts +++ b/static/jcal.ts @@ -33,9 +33,17 @@ function jcal_type_to_xcal(doc: Document, type: ical_type, value: any): Element case 'recur': for (var key in value) { if (!value.hasOwnProperty(key)) continue; - let e = doc.createElementNS(xcal, key); - e.textContent = value[key]; - el.appendChild(e); + if (key === 'byday') { + for (let v of value[key]) { + let e = doc.createElementNS(xcal, key); + e.textContent = v; + el.appendChild(e); + } + } else { + let e = doc.createElementNS(xcal, key); + e.textContent = value[key]; + el.appendChild(e); + } } break; diff --git a/static/vevent.ts b/static/vevent.ts index c7dcd406..994c9425 100644 --- a/static/vevent.ts +++ b/static/vevent.ts @@ -60,7 +60,7 @@ class VEventValue { value = 'UTC-OFFSET GOES HERE'; break; case 'recur': - value = v.asJcal(); + value = v.to_jcal(); break; case 'float': -- cgit v1.2.3