From ed403e92f984cd16a70fea78b2920e7f04ca91aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Tue, 28 Jan 2020 11:41:06 +0100 Subject: [PATCH] Dynamic data loading for select depending on previous selects selection --- content/multipledataset.html | 132 ++++++++++++++++++++--------------- 1 file changed, 77 insertions(+), 55 deletions(-) diff --git a/content/multipledataset.html b/content/multipledataset.html index bc1bc51e..fcd881d3 100644 --- a/content/multipledataset.html +++ b/content/multipledataset.html @@ -85,54 +85,91 @@ draft: false window.defaultDats = window.defaultDats.concat(sub) } processingIndicator.isActive = false - await reloadSelect() + reloadCustomFiles() } async function reloadCustomFiles() { window.dats = window.defaultDats; - const kinds=new Map([["file_abs", VertExcitationKinds.Absorbtion], ["file_fluo", VertExcitationKinds.Fluorescence]]) + const kinds = new Map([["file_abs", VertExcitationKinds.Absorbtion], ["file_fluo", VertExcitationKinds.Fluorescence]]) for (const el of $('#form_dat > fieldset > div > input[type="file"')) { if (kinds.has(el.name)) { for (const f of el.files) { - const dat=await VertDataFile.loadAsync(f, kinds.get(this.name)) + const dat = await VertDataFile.loadAsync(f, kinds.get(this.name)) window.dats.push(dat) } } } + reloadSelect("DOI") } - async function clearSelect() { - $('#form_dat > fieldset > div > select,#sel_ref').each(function () { + async function clearSelect(BeforeName = null) { + var selects = ((BeforeName == null) ? getAllSelect() : getAllSelectAfter(BeforeName, true)) + selects.add($('#sel_ref')) + selects.each(function () { $(this).empty() }) } - async function reloadSelect() { - reloadCustomFiles() - clearSelect() - $('#form_dat > fieldset > div > select').each(async function () { - const vals = uniq(window.dats.map((d) => { - switch ($(this).attr("name")) { - case "method": - return d.method.name - break; - case "basis": - return d.method.basis - case "DOI": - return d.DOI.string - default: - return d[$(this).attr("name")] - break; - } - })) - var sets = await getSets() - for (const val of vals) { - if (val !== null) { - $("