aboutsummaryrefslogtreecommitdiff
path: root/static/script.js
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-11-23 21:37:03 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2020-11-23 21:37:03 +0100
commit0ff627bca9739fb3d0c8c4f820bc052fc6dd108e (patch)
treef4314589b48a62b0c55ea2f271cd70939cabd035 /static/script.js
parentNotes on input-list doc. (diff)
downloadcalp-0ff627bca9739fb3d0c8c4f820bc052fc6dd108e.tar.gz
calp-0ff627bca9739fb3d0c8c4f820bc052fc6dd108e.tar.xz
Bind large part of rrule.
Diffstat (limited to '')
-rw-r--r--static/script.js49
1 files changed, 43 insertions, 6 deletions
diff --git a/static/script.js b/static/script.js
index 133140d2..409359a7 100644
--- a/static/script.js
+++ b/static/script.js
@@ -436,10 +436,12 @@ function bind_properties (el, wide_event=false) {
/* primary display tab */
let p;
- for (let e of [...popup.querySelectorAll(".bind"),
- ...el.querySelectorAll('.bind')]) {
- if ((p = e.closest('[data-bindby=*]'))) {
- p.dataset.bindby(el, e);
+ let lst = [...popup.querySelectorAll(".bind"),
+ ...el.querySelectorAll('.bind')];
+ for (let e of lst) {
+ if ((p = e.closest('[data-bindby]'))) {
+ // console.log(p.dataset.bindby);
+ eval(p.dataset.bindby)(el, e);
} else {
let f = ((s, v) => s.innerHTML = v.format(s.dataset && s.dataset.fmt));
get_property(el, e.dataset.property).push([e, f]);
@@ -528,8 +530,10 @@ function bind_properties (el, wide_event=false) {
let field = child.tagName;
let lst = get_property(el, field);
+
/* Bind vcomponent fields for this event */
for (let s of el.querySelectorAll(`${field} > :not(parameters)`)) {
+
lst.push([s, (s, v) => {
if (v instanceof Date) {
if (v.isWholeDay) {
@@ -540,14 +544,23 @@ function bind_properties (el, wide_event=false) {
child.innerHTML = `<date-time>${str}</date-time>`;
}
} else if (v instanceof RRule) {
- /* TODO also recalculate whenever any field changes */
child.innerHTML = v.asXcal();
} else {
/* assume that type already is correct */
s.innerHTML = v;
}
}]);
- el.properties["_value_" + field] = s.innerHTML;
+
+ /* Binds value from XML-tree to javascript object
+ [parsedate]
+ */
+ switch (field) {
+ case 'rrule':
+ el.properties['_value_rrule'] = recur_xml_to_rrule(s);
+ break;
+ default:
+ el.properties["_value_" + field] = s.innerHTML;
+ }
}
}
@@ -584,6 +597,7 @@ function bind_properties (el, wide_event=false) {
let end = parseDate(container.dataset.end);
if (el.properties.dtstart) {
+ /* [parsedate] */
el.properties.dtstart = parseDate(el.properties.dtstart);
get_property(el, 'dtstart').push(
[el.style, (s, v) =>
@@ -601,6 +615,29 @@ function bind_properties (el, wide_event=false) {
(s, v) => s[wide_event?'right':'bottom'] = 100 * (1 - (to_local(v)-start)/(end-start)) + "%"]);
}
+
+ /* Update XML on rrule field change */
+ if (el.properties.rrule) {
+ for (let f of el.properties.rrule.fields) {
+ el.properties.rrule.addListener(
+ f, v => {
+ console.log(v);
+ let recur = el.querySelector('rrule recur');
+ let field = recur.querySelector(f);
+ if (field) {
+ if (! v) {
+ field.remove();
+ } else {
+ field.innerHTML = v;
+ }
+ } else {
+ if (v) recur.innerHTML += `<${f}>${v}</${f}>`;
+ }
+ });
+ }
+ }
+
+
/* ---------- Calendar ------------------------------ */
if (! el.dataset.calendar) {