aboutsummaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-11-18 21:40:19 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2021-11-18 21:40:19 +0100
commite5d682702f6954ebab946ca0eb67ab22f465f6ea (patch)
tree34373f2f20154f6fcbfb4e534c69ff55fa23715c /static
parentRemove .interactive, fix date-time checkbox. (diff)
downloadcalp-e5d682702f6954ebab946ca0eb67ab22f465f6ea.tar.gz
calp-e5d682702f6954ebab946ca0eb67ab22f465f6ea.tar.xz
Add setProperties, add type info to setProperty.
Diffstat (limited to 'static')
-rw-r--r--static/event-creator.ts13
-rw-r--r--static/server_connect.ts15
-rw-r--r--static/vevent.ts30
3 files changed, 38 insertions, 20 deletions
diff --git a/static/event-creator.ts b/static/event-creator.ts
index 97ffbd62..6be94a9d 100644
--- a/static/event-creator.ts
+++ b/static/event-creator.ts
@@ -3,8 +3,8 @@ export { EventCreator }
import { VEvent } from './vevent'
import { v4 as uuid } from 'uuid'
import { ComponentBlock } from './components/vevent-block'
-import { round_time } from './lib'
-import { parseDate } from './lib'
+import { round_time, parseDate } from './lib'
+import { ical_type } from './types'
class EventCreator {
@@ -148,10 +148,11 @@ class EventCreator {
let d1 = new Date(container_start.getTime() + start_in_duration)
let d2 = new Date(container_start.getTime() + end_in_duration)
- /* TODO these writes should preferably be grouped,
- to save a redraw for all registered listeners */
- that.ev.setProperty('dtstart', d1);
- that.ev.setProperty('dtend', d2);
+ let type: ical_type = wide_element ? 'date' : 'date-time';
+ that.ev.setProperties([
+ ['dtstart', d1, type],
+ ['dtend', d2, type],
+ ]);
// console.log(that.event);
// console.log(d1.format("~L~H:~M"), d2.format("~L~H:~M"));
diff --git a/static/server_connect.ts b/static/server_connect.ts
index e02258ce..1d01e07e 100644
--- a/static/server_connect.ts
+++ b/static/server_connect.ts
@@ -1,15 +1,16 @@
-export { create_event }
+export { create_event, remove_event }
import { jcal_to_xcal } from './jcal'
import { VEvent } from './vevent'
+import { uid } from './types'
+import { vcal_objects } from './globals'
-/*
-async function remove_event(element: Element): void {
- let uidElement = element.querySelector("icalendar uid text")
- if (uidElement === null) {
- throw "Element lacks uid, giving up"
+async function remove_event(uid: uid) {
+ let element = vcal_objects.get(uid);
+ if (!element) {
+ console.error(`No VEvent with that uid = '${uid}', giving up`)
+ return;
}
- let uid: uid = uidElement.textContent!;
let data = new URLSearchParams();
data.append('uid', uid);
diff --git a/static/vevent.ts b/static/vevent.ts
index 307c572f..0c262208 100644
--- a/static/vevent.ts
+++ b/static/vevent.ts
@@ -106,11 +106,15 @@ class VEvent {
return this.properties.keys()
}
- setProperty(key: string, value: any) {
+ __setPropertyInternal(key: string, value: any, type?: ical_type) {
key = key.toUpperCase();
let e = this.properties.get(key);
- if (!e) {
- let type: ical_type
+ if (e) {
+ if (type) { e.type = type; }
+ e.value = value;
+ return;
+ }
+ if (!type) {
let type_ = valid_input_types.get(key)
if (type_ === undefined) {
type = 'unknown'
@@ -119,16 +123,28 @@ class VEvent {
} else {
type = type_
}
- e = new VEventValue(type, value)
- this.properties.set(key, e);
- } else {
- e.value = value;
+ }
+ e = new VEventValue(type, value)
+ this.properties.set(key, e);
+ }
+
+ setProperty(key: string, value: any, type?: ical_type) {
+ this.__setPropertyInternal(key, value, type);
+ for (let el of this.registered) {
+ el.redraw(this);
+ }
+ }
+
+ setProperties(pairs: [string, any, ical_type?][]) {
+ for (let pair of pairs) {
+ this.__setPropertyInternal(...pair);
}
for (let el of this.registered) {
el.redraw(this);
}
}
+
set calendar(calendar: string | null) {
this._calendar = calendar;
for (let el of this.registered) {