RelayBoxWebApp/index.html

113 lines
4.0 KiB
HTML
Raw Permalink Normal View History

2015-06-01 00:51:45 -07:00
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
2015-06-01 14:10:15 +02:00
$("document").ready(function() {
2015-06-01 19:20:48 +02:00
$.ajaxSetup({
async: false
});
2015-06-01 22:26:00 +02:00
var switchMapping = $.getJSON('/switchMapping').responseJSON;
2015-06-10 17:21:59 +02:00
var sortedKeys = Object.keys(switchMapping).sort(function(a,b){return switchMapping[a]['index'] - switchMapping[b]['index']});
2015-06-01 17:03:23 +02:00
var firstListItem = $("li:first", "#switchlist");
2015-06-10 17:23:32 +02:00
for (var i = 0; i < sortedKeys.length; i++) {
var key = sortedKeys[i];
2015-06-01 17:03:23 +02:00
var newListItem = firstListItem.clone()
var href = newListItem.children('a')
2015-06-01 22:26:00 +02:00
href.attr('id', key);
2015-06-01 17:03:23 +02:00
href.attr('href', '#dialog?switch=' + switchMapping[key]['index'])
var span = newListItem.find("#statusEmpty0");
span.attr('id', 'state' + key);
span = newListItem.find("#labelEmpty0");
span.attr('id', 'label' + key);
span.text(switchMapping[key]['label']);
newListItem.appendTo("#switchlist");
}
firstListItem.hide();
2015-06-01 14:10:15 +02:00
$("#target").hide();
$("#button").click(function() {
2015-06-01 17:03:23 +02:00
var v = ($("#flip-checkbox-1").is(":checked")) ? 1 : 0;
var w = switchMapping[$("#target").text()]['index'];
2015-06-01 22:26:00 +02:00
console.debug('y:' + v + ', ' + w);
2015-06-01 14:10:15 +02:00
$.ajax({
2015-06-01 22:26:00 +02:00
url: '/switchCommand?target=' + w + '&state=' + v
2015-06-01 14:10:15 +02:00
});
});
$(".switchlink").click(function() {
2015-06-01 17:03:23 +02:00
var v = $(this).attr("id");
2015-06-01 21:58:05 +02:00
$("#target").text(v);
2015-06-01 17:03:23 +02:00
var w = $("span:first", this).text();
$("#dialogTitle").text(w);
2015-06-01 21:58:05 +02:00
var x = $("span:last", this).text();
console.debug(x);
2015-06-01 22:26:00 +02:00
if (x == 'an') {
2015-06-01 21:58:05 +02:00
console.debug('x:on');
$("#flip-checkbox-1").prop('checked', true);
} else {
console.debug('x:off');
$("#flip-checkbox-1").prop('checked', false);
}
$("#flip-checkbox-1").flipswitch( "refresh" );
2015-06-01 14:10:15 +02:00
});
2015-06-01 17:03:23 +02:00
function updateState() {
for (var key in switchMapping) {
$.ajax({
2015-06-01 22:26:00 +02:00
url: '/switchStatus?target=' + switchMapping[key]['index'],
2015-06-01 17:03:23 +02:00
success: function(data) {
$('#state' + key).text(data);
}
});
}
setTimeout(updateState, 1000);
}
updateState();
2015-06-01 14:10:15 +02:00
});
2015-06-01 00:51:45 -07:00
</script>
<style>
.red { background-color: red; }
.green { background-color: green; }
</style>
</head>
<body>
<div data-role="page" id="mainpage">
2016-07-05 15:25:15 +02:00
<div id="tabs" data-role="tabs">
<div data-role="navbar">
<ul>
<li><a class="ui-btn-active" href="#one" data-ajax="false">Relaybox</a></li>
<li><a href="#two" data-ajax="false">Measurements</a></li>
</ul>
</div>
<div class="ui-body-d ui-content" id="one">
<ul id="switchlist" data-role="listview" data-inset="true" data-count-theme="b">
<li><a class="switchlink" id="itemEmpty0" href="#dialog?switch=0"><span id="labelEmpty0">Vorlage</span> <span id="statusEmpty0" class="ui-li-count">on</span></a></li>
</ul>
</div>
<div class="ui-body-d ui-content" id="two">
bla
</div>
2015-06-01 00:51:45 -07:00
</div>
</div>
<div data-role="dialog" id="dialog">
<div data-role="header">
<h1 id="dialogTitle">Switching</h1>
</div>
<div data-role="main" class="ui-content">
<center>
<input name="flip-checkbox-1" id="flip-checkbox-1" type="checkbox" data-role="flipswitch">
<span id="target">x</span>
</center>
<a href="#mainpage" id="button" data-role="button" data-rel="back">Ok</a>
</div>
</div>
</body>
</html>