diff --git a/data/index.js b/data/index.js index b0b68de2..34a372d7 100644 --- a/data/index.js +++ b/data/index.js @@ -128,7 +128,8 @@ function generateHTML(json, parentNode = null, rowNr = -1) { for (var variable of json) //if isArray then variables of array generateHTML(variable, parentNode, rowNr); } - else { // json is object + else { // json is variable + let variable = json; //if root (type module) add the html to one of the screen columns if (parentNode == null) { parentNode = gId("screenColumn" + screenColumnNr); @@ -136,16 +137,16 @@ function generateHTML(json, parentNode = null, rowNr = -1) { } //if System, set the current view - if (json && json.id) { - if (json.id == "System") { + if (variable && variable.id) { + if (variable.id == "System") { //get the current view - console.log("view", json); - if (json.view) - savedView = json.view; + console.log("view", variable); + if (variable.view) + savedView = variable.view; } } else { - console.log("genHTML no json and id", json, parentNode); //tbd: caused by more data then columns in table... + console.log("genHTML no variable and id", variable, parentNode); //tbd: caused by more data then columns in table... return; } @@ -158,30 +159,30 @@ function generateHTML(json, parentNode = null, rowNr = -1) { let ndivNeeded = true; //for details ("n"), module and table do not need an extra div for details let labelNode = cE("label"); //set labelNode before if, will be used in if then else - labelNode.innerText = initCap(json.id); // the default when not overridden by uiFun + labelNode.innerText = initCap(variable.id); // the default when not overridden by uiFun let isPartOfTableRow = (rowNr != -1); if (!isPartOfTableRow) { newNode = cE("p"); - if (json.type != "button") newNode.appendChild(labelNode); //add label (tbd:must be done by childs n table cell) + if (variable.type != "button") newNode.appendChild(labelNode); //add label (tbd:must be done by childs n table cell) } - let parentNodeName = parentNode.nodeName.toLocaleLowerCase(); + let parentNodeType = parentNode.nodeName.toLocaleLowerCase(); - if (json.type == "module") { + if (variable.type == "module") { ndivNeeded = false; valueNode = cE("div"); // valueNode.draggable = true; valueNode.className = "screenBox"; let h2Node = cE("h2"); - h2Node.innerText = initCap(json.id); + h2Node.innerText = initCap(variable.id); valueNode.appendChild(h2Node); setupScreenBox(valueNode); } - else if (json.type == "table") { + else if (variable.type == "table") { ndivNeeded = false; //add label in an extra row @@ -199,24 +200,29 @@ function generateHTML(json, parentNode = null, rowNr = -1) { valueNode.appendChild(cE("tbody")); - //json.n will add the columns + //variable.n will add the columns } - else if (parentNodeName == "table") { - // console.log("tableChild", parentNode, parentNode.firstChild.firstChild, json); + else if (parentNodeType == "table") { + // console.log("tableChild", parentNode, parentNode.firstChild.firstChild, variable); //table header //no newNode created //table add the id in the header //rowNr = -1 for th so uiFun will be called and processed in changeHTML valueNode = cE("th"); - // valueNode.id = json.id; - valueNode.innerText = initCap(json.id); //label uiFun response can change it + // valueNode.id = variable.id; + valueNode.innerText = initCap(variable.id); //label uiFun response can change it parentNode.firstChild.firstChild.appendChild(valueNode); // (containing th) // newNode = valueNode; - } else if (json.type == "select") { + } else if (variable.type == "select") { - if (json.ro) { //e.g. for reset/restart reason: do not show a select but only show the selected option + if (variable.ro) { //e.g. for reset/restart reason: do not show a select but only show the selected option valueNode = cE("span"); - if (json.value) valueNode.innerText = json.value; + if (variable.value) valueNode.innerText = variable.value; + + if (savedData[variable.id]) { + // console.log("genHTML select table get savedData", valueNode, variable, savedData[variable.id]); + changeHTML(valueNode, {"data":savedData[variable.id]}); + } } else { //

with

// table or canvas

// 1) if exist then replace else add let parentNode; - if (nodeName == "canvas" || nodeName == "textarea" || nodeName == "table") + if (nodeType == "canvas" || nodeType == "textarea" || nodeType == "table") parentNode = node.previousSibling; //