function getAllData(){
$.ajax({
type: "GET",
url: 'data.db',
success: function(ret) {
$.each(ret.data, function(i, item) {
setSingleData(item);
});
}
});
}
function setSingleData(singleData){
//remove data
$( "#" + singleData.seriennummer ).remove();
container = document.getElementById(singleData.activity);
entry = document.createElement("div");
$(entry).attr("id",singleData.seriennummer);
$(entry).html("Code: " + singleData.produktcode + " SN: " + singleData.seriennummer + "");
container.appendChild(entry);
}
function showDocument() {
$.ajax({
type: "GET",
url: 'style.url',
success: function(ret) {
$('head link.custom').attr('href',ret);
}
});
}
function clearDocument() {
$('#languages').addClass('hidden');
$('#nope').removeClass('hidden');
$('#control .added').remove();
$('#content .added').remove();
$('#reason').text(reason);
}
function init() {
es = new EventSource('sse/');
es.onopen = function() {
getAllData();
};
es.onmessage = function(e) {
console.log("Got SSE");
if (e.data == 'new') {
reason = '';
showDocument();
}
if (e.data == 'reset') {
reason = '';
showDocument();
}
else{
if(e.data == "update"){
alert("update")
}
if(e.data != "keepalive" && e.data != "started"){
try {
var prdata = JSON.parse(e.data)
//alert("LastIf" + prdata.seriennummer)
setSingleData(prdata);
}
catch (e) {
}
}
}
};
es.onerror = function() {
reason = 'Server down.';
clearDocument();
es.close();
setTimeout(init, 10000);
};
}
$(document).ready(function() {
init();
});