not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB

  1. // Network check component
  2. enyo.kind({
  3. name: "FoodChain.NetworkCheck",
  4. kind: enyo.Control,
  5. classes: "networkCheck",
  6. published: { connected: false },
  7. components: [
  8. {name: "box", components: []}
  9. ],
  10. // Constructor
  11. create: function() {
  12. this.inherited(arguments);
  13. this.then = null;
  14. },
  15. // Constructor
  16. rendered: function() {
  17. this.inherited(arguments);
  18. },
  19. // Check the connection
  20. check: function(then) {
  21. // Remove previous attempt
  22. var items = [];
  23. enyo.forEach(this.$.box.getControls(), function(item) {
  24. items.push(item);
  25. });
  26. for (var i = 0 ; i < items.length ; i++) {
  27. items[i].destroy();
  28. }
  29. // Ping network
  30. this.then = then;
  31. this.$.box.createComponent(
  32. {kind: "Image", showing: false, src: "images/cards/_ping.png?"+(new Date()).getTime(), onload: "networkOK", onerror: "networkKO"},
  33. {owner: this}
  34. ).render();
  35. },
  36. // Update icons depending of network response
  37. networkOK: function() {
  38. this.connected = true;
  39. if (this.then) this.then(this.connected);
  40. },
  41. networkKO: function() {
  42. this.connected = false;
  43. if (this.then) this.then(this.connected);
  44. }
  45. });