Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var myProducts = [];
  2. var i = 0;
  3. var sumdiff = 0;
  4.  
  5. function Product(id, name, location, timestamp, diff)
  6. {
  7.     this.id = id;
  8.     this.name = name;
  9.     this.location = location;
  10.     this.timestamp = timestamp;
  11.     this.diff = diff;
  12. }
  13.  
  14. function addProduct(produs)
  15. {
  16.     sumdiff += produs.diff;
  17.    
  18.     $("#products_holder li:nth-child(30)").remove();
  19.     $("#products_holder").prepend("<li id='prod" + produs.id + "'>" + produs.name + " - " + produs.location + " - " + produs.timestamp + "</li>");
  20.    
  21.     $("#prod" + produs.id).slideDown({queue: false, complete: function()
  22.     {
  23.         if (i < myProducts.length)
  24.             setTimeout(function()
  25.             {
  26.                 console.log(produs.diff);
  27.                 addProduct(myProducts[i++]);
  28.                
  29.             }, produs.diff);
  30.     }});
  31. }
  32.  
  33. var getData = function()
  34. {
  35.     if (i != myProducts.length)
  36.         console.log("n.am avut timp. sumdiff = " + sumdiff);
  37.        
  38.     myProducts = [];
  39.     i = 0;
  40.     sumdiff = 0;
  41.    
  42.     $.ajax({
  43.        
  44.         url: "http://localhost/salesmap/web/app_dev.php/salesmap/generate",
  45.         type: "POST",
  46.         dataType: 'json'
  47.     }).done(function(data)
  48.     {
  49.         for (var x = 0; x != data.length; ++x)
  50.         {
  51.             myProducts.push(new Product(data[x].id, data[x].product_name, data[x].location, data[x].timestamp, data[x].diff * 1000));
  52.         }
  53.        
  54.         if (myProducts.length > 0)
  55.             addProduct(myProducts[i++]);
  56.     });
  57. };
  58.  
  59. setInterval(function(){ getData(); }, 30000);
  60. getData();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement