2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

Refactor multi-bom deletion

This commit is contained in:
Oliver Walters 2021-02-26 10:54:54 +11:00
parent 44f5e0907e
commit 12c2ea3b37

View File

@ -111,30 +111,21 @@
{ {
accept: function() { accept: function() {
// Delete each row one at a time! // Keep track of each DELETE request
function deleteRow(idx) { var requests = [];
if (idx >= rows.length) {
// All selected rows deleted - reload the table
$("#bom-table").bootstrapTable('refresh');
}
var row = rows[idx];
var url = `/api/bom/${row.pk}/`;
rows.forEach(function(row) {
requests.push(
inventreeDelete( inventreeDelete(
url, `/api/bom/${row.pk}/`,
{
complete: function(xhr, status) {
deleteRow(idx + 1);
}
}
) )
} );
});
// Start the deletion! // Wait for *all* the requests to complete
deleteRow(0); $.when.apply($, requests).then(function() {
$('#bom-table').bootstrapTable('refresh');
});
} }
} }
); );