workflow.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var GRID_PUBLIC_ID
  2. ,KNOWN_VERSION = 0
  3. ,GRID;
  4. function doGet(url, callback) {
  5. var xhr = new XMLHttpRequest();
  6. xhr.onreadystatechange = function(e) {
  7. if (xhr.readyState === 4) {
  8. var resp = null;
  9. if (xhr.status === 200) {
  10. resp = xhr.response;
  11. try {
  12. resp = JSON.parse(/** @type {string} */ (resp));
  13. } catch (e) {
  14. resp = null;
  15. }
  16. }
  17. callback(resp);
  18. }
  19. };
  20. xhr.open('GET', url, true);
  21. xhr.send(null);
  22. }
  23. function initPolling() {
  24. doGet("/api/poll?grid=" +GRID_PUBLIC_ID +"&v=" +KNOWN_VERSION, function(resp) {
  25. GRID = new Grid(resp);
  26. if (resp["grid"]) {
  27. KNOWN_VERSION = Math.max(GRID.update(resp["grid"]) || 0, KNOWN_VERSION);
  28. uiCreateGrid();
  29. }
  30. });
  31. }
  32. document.addEventListener('DOMContentLoaded', function() {
  33. GRID_PUBLIC_ID = (document.location.hash.substr(1));
  34. if (GRID_PUBLIC_ID == "") {
  35. document.location.href = "/";
  36. return;
  37. }
  38. initPolling();
  39. });