diff options
Diffstat (limited to '')
-rw-r--r-- | static/rrule.js | 57 |
1 files changed, 57 insertions, 0 deletions
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 = "<recur>"; + for (let f of this.fields) { + let v = this.fields[f]; + if (! v) continue; + str += `<${f}>${v}</${f}>`; + } + str += "</recur>"; + return str; + } + + /* + asIcal() { + return this.fields + .map(f => [f, this.fields[f]]) + .filter([_, v] => v) + .map(([k, v]) => `${k}=${v}`) + .join(';'); + } + */ +}; |