homeservice/webui/index.html
Thomas Klaehn 6a9a42adc6 Water web service
Signed-off-by: Thomas Klaehn <thomas.klaehn@perinet.io>
2025-04-17 12:44:35 +02:00

211 lines
7.0 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<style>
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
/* Hide default HTML checkbox */
.switch input {
opacity: 0;
width: 0;
height: 0;
}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
<title id="title">Wasser</title>
<script type="text/javaScript">
function init() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/water/devices");
xhr.send();
xhr.responseType = "json";
xhr.onload = () => {
if (xhr.readyState == 4 && xhr.status == 200) {
let devices = xhr.response['devices'];
// remove old lines in switch table
// let table = document.getElementById("switch_tbl");
// let rows = table.getElementsByTagName("tr");
// for(let i = 0; i < rows.length; i++) {
// table.removeChild(rows[i]);
// }
// add rows recursively
// for(let i = 0; i < devices.length; i++) {
// console.log(devices[i]);
// let new_row = table.insertRow();
// let new_cell = new_row.insertCell();
// new_cell.innerHTML = devices[i].name;
// let btn = document.createElement("checkbox");
// btn.setAttribute
// let button_cell = new_row.insertCell();
// button_cell.appendChild(btn);
// }
// } else {
// console.log(`Error: ${xhr.status}`);
}
};
}
function check(checkbox, name) {
var obj;
if(checkbox.checked) {
obj = '{"name":"' + name + '","state":true}'
} else {
obj = '{"name":"' + name + '","state":false}'
}
console.log(obj);
const xhr = new XMLHttpRequest();
xhr.open("PATCH", "/water/switch");
xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
xhr.onload = () => {
var data = JSON.parse(xhr.responseText);
if (xhr.readyState == 4 && xhr.status == "202") {
console.log(data);
} else {
console.log(`Error: ${xhr.status}`);
}
};
xhr.send(obj);
}
</script>
</head>
<body onload=init()>
<div class="headercontainer">
<div class="meta">
<div class="left" style="line-height: 24px;font-weight: bold;" id="headline">Wasser</div>
<div class="middle"></div>
<div class="right"><span></span></div>
</div>
<!-- <div class="header" id="header_cnt">
<div class="headerlogo"><img src="images/logo_perinet.png" width="258" height="94" alt="" /></div>
</div> -->
</div>
<!--Content-->
<div id="content">
<table id="switch_tbl">
<tr>
<td>Huehner</td>
<td>
<label class="switch">
<input type="checkbox" onchange="check(this, 'chicken')">
<span class="slider round"></span>
</label>
</td>
</tr>
<tr>
<td>Hochbeet</td>
<td>
<label class="switch">
<input type="checkbox" onchange="check(this, 'bed')">
<span class="slider round"></span>
</label>
</td>
</tr>
<tr>
<td>Sauna</td>
<td>
<label class="switch">
<input type="checkbox" onchange="check(this, 'sauna')">
<span class="slider round"></span>
</label>
</td>
</tr>
<tr>
<td>Haselnuss</td>
<td>
<label class="switch">
<input type="checkbox" onchange="check(this, 'nut')">
<span class="slider round"></span>
</label>
</td>
</tr>
<tr>
<td>Holzlager</td>
<td>
<label class="switch">
<input type="checkbox" onchange="check(this, 'wood')">
<span class="slider round"></span>
</label>
</td>
</tr>
<tr>
<td>Tomaten</td>
<td>
<label class="switch">
<input type="checkbox" onchange="check(this, 'tomato')">
<span class="slider round"></span>
</label>
</td>
</tr>
<tr>
<td>Scheune</td>
<td>
<label class="switch">
<input type="checkbox" onchange="check(this, 'barn')">
<span class="slider round"></span>
</label>
</td>
</tr>
</table>
</div>
</body>
</html>