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: [], mainImageResource: [],
}; };
let list = {}; this.fieldList = Object.freeze(fieldList);
for (let sectionName in fieldList) {
list = Object.assign(list, fieldList[sectionName]);
}
this.fieldList = Object.freeze(list);
console.log(this.fieldList);
const lines = csvRaw.trim().replace("\r\n", "\n").split("\n"); const lines = csvRaw.trim().replace("\r\n", "\n").split("\n");
@ -376,6 +371,7 @@ class CsvxmlDialogue {
class CsvxmlPage { class CsvxmlPage {
fieldList; fieldList;
fieldListFlat;
tls; tls;
domUploaderWrapper; domUploaderWrapper;
domMainWrapper; domMainWrapper;
@ -386,6 +382,13 @@ class CsvxmlPage {
constructor(fieldList) { constructor(fieldList) {
this.fieldList = Object.freeze(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"))); this.tls = Object.freeze(JSON.parse(document.body.getAttribute("data-tls")));
let domUploaderWrapper = document.createElement("div"); let domUploaderWrapper = document.createElement("div");
@ -405,27 +408,24 @@ class CsvxmlPage {
let line2 = []; let line2 = [];
let line3 = []; let line3 = [];
for (let sectionName in this.fieldList) { for (let fieldName in this.fieldListFlat) {
const sectionFields = this.fieldList[sectionName]; console.log(fieldName);
for (let fieldName in sectionFields) { console.log(selectedFields);
console.log(fieldName);
console.log(selectedFields);
if (selectedFields.length !== 0 && selectedFields.includes(fieldName) === false) continue; if (selectedFields.length !== 0 && selectedFields.includes(fieldName) === false) continue;
const field = sectionFields[fieldName]; const field = this.fieldListFlat[fieldName];
line1.push(fieldName); line1.push(fieldName);
line2.push(field.name_human_readable); 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("");
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('";"') + '"'; const csvLine1 = '"' + line1.join('";"') + '"';
@ -551,7 +551,7 @@ class CsvxmlPage {
// On loading success, check if the upload is valid JSON // On loading success, check if the upload is valid JSON
console.log("Read file"); console.log("Read file");
// Validate the file // Validate the file
let validator = new CsvxmlValidator(app.fieldList, reader.result); let validator = new CsvxmlValidator(app.fieldListFlat, reader.result);
if (validator.isValid() === true) { if (validator.isValid() === true) {
alert("Document is valid. Press ok to download."); alert("Document is valid. Press ok to download.");
app.zipUploadToXml(validator); app.zipUploadToXml(validator);
@ -630,13 +630,13 @@ class CsvxmlPage {
if (field.classList.contains("humanTLToggled") === false) return; 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) { 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++) { for (let i = 0, max = linkedFields.length; i < max; i++) {
let linkedField = document.getElementById(linkedFields[i]); let linkedField = document.getElementById(linkedFields[i]);
if (linkedField.classList.contains("humanTLToggled") === true) continue; if (linkedField.classList.contains("humanTLToggled") === true) continue;
app.toggleListFieldSelectionState(linkedField); this.toggleListFieldSelectionState(linkedField);
} }
} }