aboutsummaryrefslogtreecommitdiff
path: root/static/rrule.js
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-11-21 00:13:20 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2020-11-21 00:13:20 +0100
commit4a4c3e42151da7a83bd863d31d8ad5f8f4d07396 (patch)
tree84a91b007d75979c102bdbc35ac8c7a721f75cb3 /static/rrule.js
parentMerge branch 'edit-rrule' into js (diff)
downloadcalp-4a4c3e42151da7a83bd863d31d8ad5f8f4d07396.tar.gz
calp-4a4c3e42151da7a83bd863d31d8ad5f8f4d07396.tar.xz
Further work on breakout and rrule.
Diffstat (limited to 'static/rrule.js')
-rw-r--r--static/rrule.js57
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(';');
+ }
+ */
+};