From 74e5b2cd3fa0c6da8274cc5272a4f5b51f1b8882 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 12 Jul 2021 20:06:53 +1000 Subject: [PATCH] Handle delete differently --- InvenTree/templates/js/stock.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/InvenTree/templates/js/stock.js b/InvenTree/templates/js/stock.js index 35f7b6bb69..cf41c1a9cb 100644 --- a/InvenTree/templates/js/stock.js +++ b/InvenTree/templates/js/stock.js @@ -223,6 +223,32 @@ function adjustStock(items, options={}) { modal: modal, onSubmit: function(fields, opts) { + // "Delete" action gets handled differently + if (options.action == 'delete') { + + var requests = []; + + items.forEach(function(item) { + requests.push( + inventreeDelete( + `/api/stock/${item.pk}/`, + ) + ) + }); + + // Wait for *all* the requests to complete + $.when.apply($, requests).then(function() { + // Destroy the modal window + $(modal).modal('hide'); + + if (options.onSuccess) { + options.onSuccess(); + } + }); + + return; + } + // Data to transmit var data = { items: [], @@ -264,7 +290,7 @@ function adjustStock(items, options={}) { error: function(xhr) { switch (xhr.status) { case 400: - + // Handle errors for standard fields handleFormErrors( xhr.responseJSON,