Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function addToDeliveryList(id) {
  2.  
  3.     $.post("func/addToDeliveryList.php", {
  4.             id: id
  5.         })
  6.         .done(function(data) {
  7.             if (data == 'ok') {
  8.                 $('#confirmedOrdersActions_' + id).html('<button type="button" style="width: 150px; border-radius:0px; cursor:default;" class="btn btn-success"><i class="fas fa-check"></i> <b>Aggiunto!</b></button>')
  9.                 setTimeout(function() {
  10.                     $('#confirmedOrdersRow_' + id).slideUp()
  11.                 }, 2000);
  12.                 var el = $('.deliveryList').find(".nav-link")
  13.                 $(el).effect('shake').delay(150).effect('shake')
  14.                 $('#deliveryListLabelButton').effect('shake').delay(150).effect('shake')
  15.             }
  16.         });
  17.  
  18.  
  19. }
  20.  
  21. function removeFromDeliveryList(id) {
  22.  
  23.     $.post("func/removeFromDeliveryList.php", {
  24.             id: id
  25.         })
  26.         .done(function(data) {
  27.             if (data == 'ok') {
  28.                 $('#confirmedOrdersActions_' + id).html('<button type="button" style="width: 150px; border-radius:0px; cursor:default;" class="btn btn-danger"><i class="fas fa-check"></i> <b>Rimosso!</b></button>')
  29.                 setTimeout(function() {
  30.                     $('#confirmedOrdersRow_' + id).slideUp()
  31.                 }, 2000);
  32.  
  33.             }
  34.         });
  35.  
  36.  
  37. }
  38.  
  39. $(function() {
  40.     var tmpArray = [];
  41.     $('[id^="confirmedOrdersRow_"]').each(function(index) {
  42.         var thisId = $(this).attr("id")
  43.         var thisId = thisId.replace("confirmedOrdersRow_", "")
  44.         var thisId = parseInt(thisId)
  45.         tmpArray[thisId] = thisId
  46.     })
  47.     $('[id^="confirmedOrdersRow_"]').each(function(index, element) {
  48.         var tmp = $(this).attr("id")
  49.         var tmp = tmp.replace("confirmedOrdersRow_", "")
  50.         window['confirmedOrdersRow_' + tmp] = $(this).detach()
  51.     })
  52.     var tmpArray2 = []
  53.     var promises = [];
  54.     $(tmpArray).each(function(index, element) {
  55.         if (element) {
  56.             promises.push($.post("func/checkIfInDeliveryList.php", {
  57.                     id: index
  58.                 })
  59.                 .done(function(data) {
  60.                     if (data != '') {
  61.                         tmpArray2[data] = index
  62.                     }
  63.                 }))
  64.         }
  65.     })
  66.     $.when.apply($, promises).then(function() {
  67.         $(tmpArray2).each(function(index, element) {
  68.             $('#waitingOrdersContent').append(window['confirmedOrdersRow_' + element])
  69.         })
  70.         $(tmpArray).each(function(index, element) {
  71.             var tmpIndex = tmpArray2.indexOf(element)
  72.             if (tmpIndex > -1) tmpArray[element] = ''
  73.         })
  74.         $(tmpArray).each(function(index, element) {
  75.             if (element) $('#waitingOrdersContent').append(window['confirmedOrdersRow_' + element])
  76.         })
  77.         recreateDeliveryList()
  78.     })
  79. })
  80.  
  81. function recreateDeliveryList() {
  82.     deliveryListRecreated = []
  83.     $('[id^="confirmedOrdersRow_"]').each(function(index) {
  84.         var tmp = $(this).attr("id")
  85.         var tmp = tmp.replace("confirmedOrdersRow_", "")
  86.         deliveryListRecreated.push(tmp)
  87.     })
  88.     var deliveryListRecreatedJSON = JSON.stringify(deliveryListRecreated)
  89.     $.post("func/recreateDeliveryList.php", {
  90.             list: deliveryListRecreatedJSON
  91.         })
  92.         .done(function(data) {
  93.             console.log("Delivery List saved.")
  94.         })
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement