From 0fa822bead61f393dade30fd22cfe37b1f385a91 Mon Sep 17 00:00:00 2001 From: Luca Trupiano Date: Mon, 10 Oct 2022 18:52:06 +0200 Subject: [PATCH] Aggiunte condizioni annidate nella GUI da query salvate --- js/script_Luk_Q.js | 57 +++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/js/script_Luk_Q.js b/js/script_Luk_Q.js index 7ed6785..7e8833b 100644 --- a/js/script_Luk_Q.js +++ b/js/script_Luk_Q.js @@ -128,11 +128,11 @@ $(document).ready(function() { $('#cla' + tabID + '-tab').tab('show'); break; case "andCond": - addLogicCond("AND") + addLogicCond("AND","#sortable0") refreshConnectWith(); break; case "orCond": - addLogicCond("OR") + addLogicCond("OR","#sortable0") refreshConnectWith(); break; default: @@ -638,7 +638,7 @@ $(document).ready(function() { } // Funzione di creazione del LI delle condizioni logiche - function addLogicCond(condtype){ + function addLogicCond(condtype,sortableNum){ condListLen++; if (condtype == "AND") { var LItext = condLIpart1 + condListLen + condLIpart2and + condListLen + condLIpart3and + condListLen + condLIpart4; @@ -648,7 +648,7 @@ $(document).ready(function() { if ($("#H-cla0")[0]) { $("#H-cla0")[0].remove(); }; - $("#sortable0").append(LItext); + $(sortableNum).append(LItext); $("#sortable" + condListLen).sortable(); $("#sortable" + condListLen).sortable( "option", "appendTo", document.body ); $("#sortable" + condListLen).sortable({ @@ -931,6 +931,7 @@ $(document).ready(function() { }; function makeUpGui(queryJson) { + $("#risultatitesto").val(queryJson["LogicaGui"]); // 1. verifica json legit --> TO DO // 2. pulire interfaccia --> OK // 3. clausola0 --> OK @@ -961,32 +962,39 @@ $(document).ready(function() { }; // 4 e 5: guiLogicString = queryJson.LogicaGui; - var clauCount = 0; var clau2Make = ""; + var treeLevel = []; + var claParent = []; for (var i=0; i < guiLogicString.length; i++) { - //console.log("- " + logicExpr[i]); switch (guiLogicString[i]) { case "(": - //console.log("("); break; case ")": - //console.log(")"); + treeLevel.pop(); break; case "OR": - addLogicCond("OR"); + addLogicCond("OR",treeLevel[treeLevel.length - 1]); + treeLevel.push("#sortable" + condListLen); + guiLogicString[i] = "#sortable" + condListLen; refreshConnectWith(); break; case "AND": if (i > 1) { - addLogicCond("AND"); + addLogicCond("AND",treeLevel[treeLevel.length - 1]); + treeLevel.push("#sortable" + condListLen); refreshConnectWith(); + guiLogicString[i] = "#sortable" + condListLen; + } else { + guiLogicString[1] = "#sortable0"; + treeLevel.push("#sortable0"); }; break; default: - clauCount++ + claParent.push(treeLevel[treeLevel.length - 1]); }; }; - for (var i=1; i <= clauCount; i++) { + //console.log(claParent); + for (var i=1; i <= claParent.length; i++) { clau2Make = queryJson["Clausola" + i].TipoClausola; active = queryJson["Clausola" + i].Attiva switch (clau2Make) { @@ -997,19 +1005,6 @@ $(document).ready(function() { $("#cla" + tabID + " .catgram").val(selectedValue); addCatgramSubcla("cla" + tabID,selectedValue); var ks = Object.keys(queryJson["Clausola" + i]); -/* for (var j = 5; j < ks.length; j++) { - switch ($("#cla" + i + ks[j])[0].type) { - case "fieldset": - var sval = queryJson["Clausola" + i][ks[j]] - $("#cla" + tabID + sval.replace(/\s/g, '')).attr("checked",true); - console.log(sval); - break; - case "select-one": - $("#cla" + i + ks[j]).val([queryJson["Clausola" + i][ks[j]]]) - break; - default: - }; - }; */ for (var j = 5; j < ks.length; j++) { var test="cla" + i + ks[j]; var melement = document.getElementById(test); @@ -1044,17 +1039,13 @@ $(document).ready(function() { case "Struttura": addStruCla(active); break; -/* case "andCond": - addLogicCond("AND"); - refreshConnectWith(); - break; - case "orCond": - addLogicCond("OR"); - refreshConnectWith(); - break; */ default: }; + var ind = guiLogicString.indexOf("Clausola" + i); + guiLogicString[ind] = "#cla" + tabID; }; + // 6: + //console.log(guiLogicString); refreshTabList(); refreshClaList(); refreshSortables();