From 441560dc721cb71cc7f5540ecd10af57b75f9bb7 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 12 Dec 2017 15:50:18 +0000 Subject: [PATCH] Add a way to get the ical representation to events. --- src/ical.js.d.ts | 6 ++++++ src/pim-types.tsx | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ical.js.d.ts b/src/ical.js.d.ts index c392add..a87e499 100644 --- a/src/ical.js.d.ts +++ b/src/ical.js.d.ts @@ -11,6 +11,10 @@ declare module 'ical.js' { getFirstProperty(name?: string): Property; getAllProperties(name?: string): Array; + + updatePropertyWithValue(name: string, value: string | number | object): Property; + + addSubcomponent(component: Component): Component; } class Event { @@ -22,6 +26,8 @@ declare module 'ical.js' { location: string; attendees: Array; + component: Component; + constructor(component?: Component | null, options?: {strictExceptions: boolean, exepctions: Array}); } diff --git a/src/pim-types.tsx b/src/pim-types.tsx index 8a53777..c252469 100644 --- a/src/pim-types.tsx +++ b/src/pim-types.tsx @@ -3,6 +3,10 @@ import * as ICAL from 'ical.js'; export class EventType extends ICAL.Event { color: string; + static fromVCalendar(comp: ICAL.Component) { + return new EventType(comp.getFirstSubcomponent('vevent')); + } + get title() { return this.summary; } @@ -15,8 +19,12 @@ export class EventType extends ICAL.Event { return this.endDate.toJSDate(); } - static fromVCalendar(comp: ICAL.Component) { - return new EventType(comp.getFirstSubcomponent('vevent')); + toIcal() { + let comp = new ICAL.Component(['vcalendar', [], []]); + comp.updatePropertyWithValue('prodid', '-//iCal.js EteSync Web'); + + comp.addSubcomponent(this.component); + return comp.toString(); } }