From 82f01a0961835eabb09e6440e9a558278f89a8e1 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Mon, 7 Nov 2022 00:21:38 +0100 Subject: [PATCH] Fix automatic activation of dependent fields in csvxmlV2.js --- public/assets/js/csvxmlV2.js | 54 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/public/assets/js/csvxmlV2.js b/public/assets/js/csvxmlV2.js index 9a2aec4..4c9333a 100644 --- a/public/assets/js/csvxmlV2.js +++ b/public/assets/js/csvxmlV2.js @@ -17,12 +17,7 @@ class CsvxmlValidator { mainImageResource: [], }; - let list = {}; - for (let sectionName in fieldList) { - list = Object.assign(list, fieldList[sectionName]); - } - this.fieldList = Object.freeze(list); - console.log(this.fieldList); + this.fieldList = Object.freeze(fieldList); const lines = csvRaw.trim().replace("\r\n", "\n").split("\n"); @@ -376,6 +371,7 @@ class CsvxmlDialogue { class CsvxmlPage { fieldList; + fieldListFlat; tls; domUploaderWrapper; domMainWrapper; @@ -386,6 +382,13 @@ class CsvxmlPage { constructor(fieldList) { this.fieldList = Object.freeze(fieldList); + + let list = {}; + for (let sectionName in fieldList) { + list = Object.assign(list, fieldList[sectionName]); + } + this.fieldListFlat = Object.freeze(list); + this.tls = Object.freeze(JSON.parse(document.body.getAttribute("data-tls"))); let domUploaderWrapper = document.createElement("div"); @@ -405,27 +408,24 @@ class CsvxmlPage { let line2 = []; let line3 = []; - for (let sectionName in this.fieldList) { - const sectionFields = this.fieldList[sectionName]; - for (let fieldName in sectionFields) { - console.log(fieldName); - console.log(selectedFields); + for (let fieldName in this.fieldListFlat) { + console.log(fieldName); + console.log(selectedFields); - if (selectedFields.length !== 0 && selectedFields.includes(fieldName) === false) continue; - const field = sectionFields[fieldName]; + if (selectedFields.length !== 0 && selectedFields.includes(fieldName) === false) continue; + const field = this.fieldListFlat[fieldName]; - line1.push(fieldName); - line2.push(field.name_human_readable); - - if (field.allowedValues !== undefined) { - // Join for object - let values = []; - for (let key in field.allowedValues) values.push(field.allowedValues[key]); - line3.push(values.join(",")); - } - else line3.push(""); + line1.push(fieldName); + line2.push(field.name_human_readable); + if (field.allowedValues !== undefined) { + // Join for object + let values = []; + for (let key in field.allowedValues) values.push(field.allowedValues[key]); + line3.push(values.join(",")); } + else line3.push(""); + } const csvLine1 = '"' + line1.join('";"') + '"'; @@ -551,7 +551,7 @@ class CsvxmlPage { // On loading success, check if the upload is valid JSON console.log("Read file"); // Validate the file - let validator = new CsvxmlValidator(app.fieldList, reader.result); + let validator = new CsvxmlValidator(app.fieldListFlat, reader.result); if (validator.isValid() === true) { alert("Document is valid. Press ok to download."); app.zipUploadToXml(validator); @@ -630,13 +630,13 @@ class CsvxmlPage { if (field.classList.contains("humanTLToggled") === false) return; - let dependencies = field.getAttribute("data-dependencies"); + let dependencies = this.fieldListFlat[field.id].dependsOn; if (dependencies !== undefined && dependencies !== null) { - let linkedFields = dependencies.split(";"); + let linkedFields = this.fieldListFlat[field.id].dependsOn; for (let i = 0, max = linkedFields.length; i < max; i++) { let linkedField = document.getElementById(linkedFields[i]); if (linkedField.classList.contains("humanTLToggled") === true) continue; - app.toggleListFieldSelectionState(linkedField); + this.toggleListFieldSelectionState(linkedField); } }