diff --git a/workorder.php b/workorder.php index 81e6e6871..a764b7a69 100644 --- a/workorder.php +++ b/workorder.php @@ -82,6 +82,7 @@ $(document).ready(function(){ $('#clear').click(function(){ $.removeCookie('workOrder'); + alert(clearedMessage); location.href="index.php"; }); $('#unreserve').click(function(){ @@ -99,17 +100,68 @@ } }); $('#storage').click(function(){ - // Pretty much the same as the unreserve function + if (!confirm(confirmMoveMessage)) { + return; + } var workList = JSON.parse($.cookie("workOrder")); - for(var x in workList) { - if ( workList[x] != 0 ) { - $.ajax({ - type: "POST", - url: "/api/v1/device/"+workList[x]+"/store" - }); - } + let successCount = 0; + let errorCount = 0; + + let promises = workList.map(function(devID){ + if (devID != 0) { + return $.ajax({ + type: "POST", + url: "/api/v1/device/" + devID + "/store" + }).done(function(){ + successCount++; + }).fail(function(jqXHR){ + console.error("Error for device ID " + devID + ": " + jqXHR.responseText); + errorCount++; + }); + } + }); + + Promise.allSettled(promises).then(function(){ + let message = `${moveSuccessMessage}: ${successCount} ${moveSuccessCountMessage}, ${errorCount} ${moveErrorCountMessage}.`; + alert(message); + }); + }); + $('#audit').click(function(){ + let workList = JSON.parse($.cookie("workOrder")); + if (!workList || workList.length === 0) { + $('#auditResults').html('
'); + return; + } + + $('#auditResults').html(''); + + let auditPromises = workList + .filter(devID => devID != 0) + .map(function(devID){ + return $.ajax({ + type: "PUT", + url: `/api/v1/audit?DeviceID=${devID}` + }).then(function(response){ + return { id: devID, result: response }; + }).catch(function(){ + return { id: devID, error: true }; + }); + }); + + Promise.all(auditPromises).then(function(results){ + let html = '