ui.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. function getAllData(){
  2. $.ajax({
  3. type: "GET",
  4. url: 'data.db',
  5. success: function(ret) {
  6. $.each(ret.data, function(i, item) {
  7. setSingleData(item);
  8. });
  9. }
  10. });
  11. }
  12. function setSingleData(singleData){
  13. //remove data
  14. $( "#" + singleData.seriennummer ).remove();
  15. container = document.getElementById(singleData.activity);
  16. entry = document.createElement("div");
  17. $(entry).attr("id",singleData.seriennummer);
  18. $(entry).html("<span>Code: " + singleData.produktcode + "</span><span> SN: " + singleData.seriennummer + "</span>");
  19. container.appendChild(entry);
  20. }
  21. function showDocument() {
  22. $.ajax({
  23. type: "GET",
  24. url: 'style.url',
  25. success: function(ret) {
  26. $('head link.custom').attr('href',ret);
  27. }
  28. });
  29. /*
  30. $.ajax({
  31. type: "GET",
  32. url: 'info.json',
  33. success: function(ret) {
  34. makeGrid(ret.x_amount, ret.y_amount);
  35. //set name
  36. document.title = ret.document_name;
  37. $.ajax({
  38. type: "GET",
  39. url: 'frames.json',
  40. success: function(ret2) {
  41. for (i of ret2.data) {
  42. makeFrame(i.lx,i.ly,i.rx,i.ry, i.url, i.callback, i.default, i.showbutton, i.style);
  43. }
  44. }
  45. });
  46. },
  47. error: function() {
  48. reason = '';
  49. clearDocument();
  50. }
  51. });*/
  52. }
  53. function clearDocument() {
  54. console.log('rrrr');
  55. $('#languages').addClass('hidden');
  56. $('#nope').removeClass('hidden');
  57. $('#control .added').remove();
  58. $('#content .added').remove();
  59. $('#reason').text(reason);
  60. }
  61. function init() {
  62. es = new EventSource('sse/');
  63. es.onopen = function() {
  64. getAllData();
  65. // load
  66. };
  67. es.onmessage = function(e) {
  68. console.log("Got SSE");
  69. if (e.data == 'new') {
  70. reason = '';
  71. showDocument();
  72. }
  73. if (e.data == 'reset') {
  74. reason = '';
  75. showDocument();
  76. }
  77. else{
  78. if(e.data == "update"){
  79. alert("update")
  80. }
  81. if(e.data != "keepalive" && e.data != "started"){
  82. try {
  83. var prdata = JSON.parse(e.data)
  84. //alert("LastIf" + prdata.seriennummer)
  85. setSingleData(prdata);
  86. }
  87. catch (e) {
  88. }
  89. }
  90. }
  91. };
  92. es.onerror = function() {
  93. reason = 'Server down.';
  94. clearDocument();
  95. setTimeout(init, 10000);
  96. };
  97. }
  98. $(document).ready(function() {
  99. init();
  100. });