1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- 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("<span>Code: " + singleData.produktcode + "</span><span> SN: " + singleData.seriennummer + "</span>");
- 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();
- });
|