diff --git a/firmware/data/bottom.js b/firmware/data/bottom.js index 3d0c2f0..3d4258f 100644 --- a/firmware/data/bottom.js +++ b/firmware/data/bottom.js @@ -30,6 +30,7 @@ amain.classList.remove("pure-button-primary"); acfg.classList.remove("pure-button-primary"); atde.classList.add("pure-button-primary"); createTable(); +fillTableFromJson(); }); } catch (error) { console.log("Error: load listener of the tab action listener management: " + error.message); @@ -292,4 +293,25 @@ container.innerHTML = ""; container.classList.add("pure-form"); container.appendChild(table); container.appendChild(button); -} \ No newline at end of file +} +function fillTableFromJson() { +var xhr = new XMLHttpRequest(); +xhr.onreadystatechange = function() { +if (this.readyState == 4 && this.status == 200) { +var json = JSON.parse(this.responseText); +var tableRows = document.querySelectorAll("table tr"); +for (var i = 1; i < tableRows.length; i++) { +var cells = tableRows[i].querySelectorAll("td"); +var hour = parseInt(cells[0].querySelector("select").value); +var minute = parseInt(cells[1].querySelector("select").value); +for (var j = 0; j < json.tcdata.length; j++) { +if (json.tcdata[j].hour == hour && json.tcdata[j].min == minute) { +cells[2 + j].querySelector("select").value = json.tcdata[j]["ch" + (j + 1)]; +} +} +} +} +}; +xhr.open("GET", "http://192.168.0.27/tc_data_blocks_read", true); +xhr.send(); +} diff --git a/firmware/html/bottom.js b/firmware/html/bottom.js index 8f7b39e..ed7644b 100644 --- a/firmware/html/bottom.js +++ b/firmware/html/bottom.js @@ -43,6 +43,7 @@ function addTabListener() { atde.classList.add("pure-button-primary"); createTable(); // recreate the table on timing data editor tab + fillTableFromJson(); }); } catch (error) { console.log("Error: load listener of the tab action listener management: " + error.message); @@ -354,4 +355,26 @@ function createTable() { container.classList.add("pure-form"); container.appendChild(table); container.appendChild(button); -} \ No newline at end of file +} + +function fillTableFromJson() { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + var json = JSON.parse(this.responseText); + var tableRows = document.querySelectorAll("table tr"); + for (var i = 1; i < tableRows.length; i++) { + var cells = tableRows[i].querySelectorAll("td"); + var hour = parseInt(cells[0].querySelector("select").value); + var minute = parseInt(cells[1].querySelector("select").value); + for (var j = 0; j < json.tcdata.length; j++) { + if (json.tcdata[j].hour == hour && json.tcdata[j].min == minute) { + cells[2 + j].querySelector("select").value = json.tcdata[j]["ch" + (j + 1)]; + } + } + } + } + }; + xhr.open("GET", "http://192.168.0.27/tc_data_blocks_read", true); + xhr.send(); +}