From 4a4c3e42151da7a83bd863d31d8ad5f8f4d07396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 21 Nov 2020 00:13:20 +0100 Subject: Further work on breakout and rrule. --- static/rrule.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 static/rrule.js (limited to 'static/rrule.js') diff --git a/static/rrule.js b/static/rrule.js new file mode 100644 index 00000000..30bed919 --- /dev/null +++ b/static/rrule.js @@ -0,0 +1,57 @@ +class RRule { + + /* direct access to fields is fine */ + /* setting them however requires methods, since there might + be listeners */ + + const fields = ['freq', 'until', 'count', 'interval', + 'bysecond', 'byminute', 'byhour', + 'bymonthday', 'byyearday', 'byweekno', + 'bymonth', 'bysetpos', 'wkst'] + + constructor() { + + this.listeners = {} + + for (let f of this.fields) { + this[f] = false; + Object.defineProperty( + this, f, { + get: () => this['_' + f]; + set: (v) => { + this['_' + f] = v + for (let l of this.listeners[f]) { + l(v); + } + } + }); + this.listeners[f] = []; + } + } + + addListener(field, proc) { + this.listeners[field].append(proc); + } + + asXcal() { + /* TODO empty case */ + let str = ""; + for (let f of this.fields) { + let v = this.fields[f]; + if (! v) continue; + str += `<${f}>${v}`; + } + str += ""; + return str; + } + + /* + asIcal() { + return this.fields + .map(f => [f, this.fields[f]]) + .filter([_, v] => v) + .map(([k, v]) => `${k}=${v}`) + .join(';'); + } + */ +}; -- cgit v1.2.3