Fix automatic activation of dependent fields in csvxmlV2.js

This commit is contained in:
Joshua Ramon Enslin 2022-11-07 00:21:38 +01:00
parent a817b59b9b
commit 82f01a0961
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -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,14 +408,12 @@ class CsvxmlPage {
let line2 = [];
let line3 = [];
for (let sectionName in this.fieldList) {
const sectionFields = this.fieldList[sectionName];
for (let fieldName in sectionFields) {
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];
const field = this.fieldListFlat[fieldName];
line1.push(fieldName);
line2.push(field.name_human_readable);
@ -426,7 +427,6 @@ class CsvxmlPage {
else line3.push("");
}
}
const csvLine1 = '"' + line1.join('";"') + '"';
const csvLine2 = '"' + line2.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);
}
}