Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var myProducts = [];
- var i = 0;
- var sumdiff = 0;
- function Product(id, name, location, timestamp, diff)
- {
- this.id = id;
- this.name = name;
- this.location = location;
- this.timestamp = timestamp;
- this.diff = diff;
- }
- function addProduct(produs)
- {
- sumdiff += produs.diff;
- $("#products_holder li:nth-child(30)").remove();
- $("#products_holder").prepend("<li id='prod" + produs.id + "'>" + produs.name + " - " + produs.location + " - " + produs.timestamp + "</li>");
- $("#prod" + produs.id).slideDown({queue: false, complete: function()
- {
- if (i < myProducts.length)
- setTimeout(function()
- {
- console.log(produs.diff);
- addProduct(myProducts[i++]);
- }, produs.diff);
- }});
- }
- var getData = function()
- {
- if (i != myProducts.length)
- console.log("n.am avut timp. sumdiff = " + sumdiff);
- myProducts = [];
- i = 0;
- sumdiff = 0;
- $.ajax({
- url: "http://localhost/salesmap/web/app_dev.php/salesmap/generate",
- type: "POST",
- dataType: 'json'
- }).done(function(data)
- {
- for (var x = 0; x != data.length; ++x)
- {
- myProducts.push(new Product(data[x].id, data[x].product_name, data[x].location, data[x].timestamp, data[x].diff * 1000));
- }
- if (myProducts.length > 0)
- addProduct(myProducts[i++]);
- });
- };
- setInterval(function(){ getData(); }, 30000);
- getData();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement