RelayBoxWebApp/index.html
2015-06-01 19:20:48 +02:00

93 lines
3.2 KiB
HTML

<!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>
$("document").ready(function() {
var serverAddress = '127.0.0.1:8080';
$.ajaxSetup({
async: false
});
var switchMapping = $.getJSON('http://' + serverAddress + '/switchMapping').responseJSON;
var firstListItem = $("li:first", "#switchlist");
for (var key in switchMapping) {
var newListItem = firstListItem.clone()
var href = newListItem.children('a')
href.attr('id', 'switch' + key);
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();
$("#target").hide();
$("#button").click(function() {
var v = ($("#flip-checkbox-1").is(":checked")) ? 1 : 0;
var w = switchMapping[$("#target").text()]['index'];
$.ajax({
url: 'http://' + serverAddress + '/switchCommand?target=' + w + '&state=' + v
});
});
$(".switchlink").click(function() {
var v = $(this).attr("id");
var w = $("span:first", this).text();
$("#dialogTitle").text(w);
$("#target").text(v);
});
function updateState() {
for (var key in switchMapping) {
$.ajax({
url: 'http://' + serverAddress + '/switchStatus?target=' + switchMapping[key]['index'],
success: function(data) {
$('#state' + key).text(data);
}
});
}
setTimeout(updateState, 1000);
}
updateState();
});
</script>
<style>
.red { background-color: red; }
.green { background-color: green; }
</style>
</head>
<body>
<div data-role="page" id="mainpage">
<div data-role="header">
<h1>RelayBox</h1>
</div>
<div data-role="main" class="ui-content">
<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>
<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>