Indention fixed

This commit is contained in:
Kai Lauterbach 2023-05-05 10:19:46 +02:00
parent 84dd924a1d
commit fe8b70a5b9

View file

@ -257,91 +257,91 @@ links.forEach(function(link) {
}); });
function createTable() { function createTable() {
var table = document.createElement("table"); var table = document.createElement("table");
// Headerzeile // Headerzeile
var headerRow = document.createElement("tr"); var headerRow = document.createElement("tr");
var headers = ["Stunde", "Minute", "ch1", "ch2", "ch3", "ch4"]; var headers = ["Stunde", "Minute", "ch1", "ch2", "ch3", "ch4"];
for (var i = 0; i < headers.length; i++) { for (var i = 0; i < headers.length; i++) {
var header = document.createElement("th"); var header = document.createElement("th");
header.innerHTML = headers[i]; header.innerHTML = headers[i];
headerRow.appendChild(header); headerRow.appendChild(header);
}
table.appendChild(headerRow);
// Inhaltszeilen
for (var row = 0; row < 10; row++) {
var contentRow = document.createElement("tr");
// Spalte "Stunde"
var hourCell = document.createElement("td");
var hourInput = document.createElement("input");
hourInput.type = "number";
hourInput.min = 0;
hourInput.max = 23;
hourCell.appendChild(hourInput);
contentRow.appendChild(hourCell);
// Spalte "Minute"
var minuteCell = document.createElement("td");
var minuteSelect = document.createElement("select");
for (var minute = 0; minute <= 50; minute += 10) {
var option = document.createElement("option");
option.value = minute;
option.text = minute.toString().padStart(2, "0");
minuteSelect.appendChild(option);
} }
minuteCell.appendChild(minuteSelect); table.appendChild(headerRow);
contentRow.appendChild(minuteCell);
// Spalten "ch1" bis "ch4" // Inhaltszeilen
for (var channel = 1; channel <= 4; channel++) { for (var row = 0; row < 10; row++) {
var channelCell = document.createElement("td"); var contentRow = document.createElement("tr");
var channelInput = document.createElement("input");
channelInput.type = "number"; // Spalte "Stunde"
channelInput.min = 0; var hourCell = document.createElement("td");
channelInput.max = 100; var hourInput = document.createElement("input");
channelCell.appendChild(channelInput); hourInput.type = "number";
contentRow.appendChild(channelCell); hourInput.min = 0;
hourInput.max = 23;
hourCell.appendChild(hourInput);
contentRow.appendChild(hourCell);
// Spalte "Minute"
var minuteCell = document.createElement("td");
var minuteSelect = document.createElement("select");
for (var minute = 0; minute <= 50; minute += 10) {
var option = document.createElement("option");
option.value = minute;
option.text = minute.toString().padStart(2, "0");
minuteSelect.appendChild(option);
}
minuteCell.appendChild(minuteSelect);
contentRow.appendChild(minuteCell);
// Spalten "ch1" bis "ch4"
for (var channel = 1; channel <= 4; channel++) {
var channelCell = document.createElement("td");
var channelInput = document.createElement("input");
channelInput.type = "number";
channelInput.min = 0;
channelInput.max = 100;
channelCell.appendChild(channelInput);
contentRow.appendChild(channelCell);
}
table.appendChild(contentRow);
} }
table.appendChild(contentRow); // Button
} var button = document.createElement("button");
button.innerHTML = "Save";
// Button button.classList.add("pure-button");
var button = document.createElement("button"); button.classList.add("pure-button-primary");
button.innerHTML = "Save"; button.onclick = function() {
button.classList.add("pure-button"); var data = [];
button.classList.add("pure-button-primary");
button.onclick = function() { var rows = table.getElementsByTagName("tr");
var data = []; for (var row = 1; row < rows.length; row++) {
var cells = rows[row].getElementsByTagName("td");
var rows = table.getElementsByTagName("tr");
for (var row = 1; row < rows.length; row++) { var hour = cells[0].querySelector("input").value;
var cells = rows[row].getElementsByTagName("td"); var minute = cells[1].querySelector("select").value;
var ch1 = cells[2].querySelector("input").value;
var hour = cells[0].querySelector("input").value; var ch2 = cells[3].querySelector("input").value;
var minute = cells[1].querySelector("select").value; var ch3 = cells[4].querySelector("input").value;
var ch1 = cells[2].querySelector("input").value; var ch4 = cells[5].querySelector("input").value;
var ch2 = cells[3].querySelector("input").value;
var ch3 = cells[4].querySelector("input").value; var rowObject = {"hour": hour, "min": minute, "ch1": ch1, "ch2": ch2, "ch3": ch3, "ch4": ch4};
var ch4 = cells[5].querySelector("input").value; data.push(rowObject);
}
var rowObject = {"hour": hour, "min": minute, "ch1": ch1, "ch2": ch2, "ch3": ch3, "ch4": ch4};
data.push(rowObject); var json = JSON.stringify(data);
} console.log(json);
var xhr = new XMLHttpRequest();
var json = JSON.stringify(data); xhr.open("POST", "http://{{IP_ADDRESS}}/tc_data_save?data=" + encodeURIComponent(json), true);
console.log(json); xhr.send();
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://{{IP_ADDRESS}}/tc_data_save?data=" + encodeURIComponent(json), true); };
xhr.send();
var container = document.getElementById("table-container");
}; container.innerHTML = "";
container.classList.add("pure-form");
var container = document.getElementById("table-container"); container.appendChild(table);
container.innerHTML = ""; container.appendChild(button);
container.classList.add("pure-form");
container.appendChild(table);
container.appendChild(button);
} }