From cf5a85a73a188cf2608e61bee4a442e975b1a672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 26 Oct 2020 18:10:01 +0100 Subject: Fields for extra properties update correctly! --- static/lib.js | 9 +++++++ static/script.js | 71 +++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/static/lib.js b/static/lib.js index 79e48f1e..46236411 100644 --- a/static/lib.js +++ b/static/lib.js @@ -3,6 +3,15 @@ General procedures which in theory could be used anywhere. */ +HTMLElement.prototype._addEventListener = HTMLElement.prototype.addEventListener; +HTMLElement.prototype.addEventListener = function (name, proc) { + if (! this.listeners) this.listeners = {}; + if (! this.listeners[name]) this.listeners[name] = []; + this.listeners[name].push(proc); + return this._addEventListener(name, proc); +}; + + /* ----- Date Extensions ---------------------------- */ /* diff --git a/static/script.js b/static/script.js index 42f61da7..5af632fd 100644 --- a/static/script.js +++ b/static/script.js @@ -338,6 +338,15 @@ async function create_event (event) { } +/* list of lists -> list of tuples */ +function zip(...args) { + // console.log(args); + if (args === []) return []; + return [...Array(Math.min(...args.map(x => x.length))).keys()] + .map((_, i) => args.map(lst => lst[i])); +} + + /* This incarnation of this function only adds the calendar switcher dropdown. All events are already editable by switching to that tab. @@ -490,14 +499,6 @@ window.onload = function () { serializer.serializeToString(xml); */ - for (let lst of document.getElementsByClassName('input-list')) { - let unit = lst.querySelector('.final.unit').cloneNode(true); - lst.unit = unit; - for (let el of lst.getElementsByTagName('input')) { - el.addEventListener('input', update_inline_list); - } - } - /* for (let el of document.querySelectorAll(".input-list input")) { el.oninput = update_inline_list; @@ -628,8 +629,11 @@ window.onload = function () { } } - name.addEventListener('input', function () { + name.addEventListener('input', function setOptionDropdown () { let types = valid_input_types[this.value.toUpperCase()]; + let el = this.parentElement; + let [_, type_selector, value_field] = el.children; + type_selector.disabled = false; if (types) { type_selector.innerHTML = ''; @@ -650,9 +654,28 @@ window.onload = function () { update_value_field(el); }); - type_selector.onchange = function () { - update_value_field(el); + + type_selector.addEventListener('change', function () { + update_value_field(this.parentElement); + }); + } + + + + /** Set up input-list **/ + + for (let lst of document.getElementsByClassName('input-list')) { + let oldUnit = lst.querySelector('.final.unit') + + for (let el of lst.getElementsByTagName('input')) { + el.addEventListener('input', update_inline_list); } + + let unit = oldUnit.cloneNode(true); + + transferListeners(oldUnit, unit); + + lst.unit = unit; } } @@ -983,16 +1006,24 @@ function bind_properties (el, wide_event=false) { */ -function advance_final(input_list) { - let new_unit = input_list.unit.cloneNode(true); - new_unit.classList.add('final'); - - for (let i of new_unit.getElementsByTagName('input')) { - /* TODO eventual other listeners? */ - /* TODO