Projekt Litsimaja - Lapikute tagatoa seintele programmeeritavad ARGB ribad
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

119 lines
4.0 KiB

<html>
<head>
<title>Litsimaja</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="normalize.css">
<link rel="stylesheet" href="skeleton.css">
<link rel="stylesheet" href="custom.css">
<script type="text/javascript">
const hexToRgb = hex =>
hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i
,(m, r, g, b) => '#' + r + r + g + g + b + b)
.substring(1).match(/.{2}/g)
.map(x => parseInt(x, 16));
function show_loading(visible) {
document.getElementById('loading').style.visibility = visible ? 'visible' : 'hidden';
}
function send_get(url) {
show_loading(true);
var http = new XMLHttpRequest();
http.open('GET', url, true);
http.onreadystatechange = function() {
if (http.readyState == 4 && http.status == 200) {
show_loading(false);
}
};
http.send();
}
function send_post(url, data) {
show_loading(true);
var http = new XMLHttpRequest();
http.open('POST', url, true);
http.setRequestHeader('Content-Type', 'application/json');
http.onreadystatechange = function() {
if (http.readyState == 4 && http.status == 200) {
show_loading(false);
}
};
let json = JSON.stringify(data);
http.send(json);
}
function getProgramSelection() {
let select = document.getElementById('program');
return select.value;
}
function isLoop() {
let looping = document.getElementById('looping');
return looping.checked;
}
function isChanged(value) {
let rgb = hexToRgb(value);
let data = {color: [Number(rgb[0]), Number(rgb[1]), Number(rgb[2])], loop: isLoop()};
send_post('program/' + getProgramSelection(), data);
}
function doInit() {
send_post('/program/siinus.Wipes', {color: [100, 50, 0]})
}
function doBlind() {
send_post('/program/siinus.Static', {color: [0, 0, 0]})
}
function doCancel() {
send_get('/crash');
}
function switchRegion(region_id) {
send_get('/region/' + region_id);
}
</script>
</head>
<body>
<div class="spacer-row"></div>
<div class="container">
<div class="row">
<button onclick="doInit()">init</button>
<button onclick="doCancel()">end loop</button>
<button onclick="doBlind()">off</button>
<label><input type="checkbox" id="looping" /><b> loop</b></label>
</div>
<div class="row">
<p>Zone switch</p>
{% for region in regions %}
<button onclick="switchRegion({{ region }})">zone {{ region }}</button>
{% endfor %}
</div>
<div class="row" id='loading' style="visibility: hidden"><b>LOADING!</b></div>
<div class="section-rgb">
<div class="row">
<div class="one-third column">
<select id="program" size="10">
{% for group in programs %}
<optgroup label="{{ group.group }}">
{% for program in group.programs %}
<option value="{{ program.prg }}">{{ program.name }}</option>
{% endfor %}
</optgroup>
{% endfor %}
</select>
</div>
</div>
</div>
<div class="row">
<div class ="one-third column">
<input class="colorpicker" type="color" value="#ff0000" oninput="isChanged(this.value)">
</div>
</div>
</div>
</body>
</html>