2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Refactor deletion of multiple manufacturer part objects

- issues multiple DELETE requests via the API
This commit is contained in:
Oliver
2021-07-01 17:01:30 +10:00
parent 206d7bd96a
commit 9bd71c1184
6 changed files with 74 additions and 61 deletions

View File

@ -170,6 +170,61 @@ function loadCompanyTable(table, url, options={}) {
}
function deleteManufacturerParts(selections, options={}) {
if (selections.length == 0) {
return;
}
var parts = [];
var text = `
<div class='alert alert-block alert-danger'>
<p>{% trans "The following manufacturer parts will be deleted" %}:</p>
<ul>`;
selections.forEach(function(item) {
parts.push(item.pk);
text += `
<li>
<p>${item.MPN} - ${item.part_detail.full_name}</p>
</li>`;
});
text += `
</ul>
</div>`;
showQuestionDialog(
'{% trans "Delete Manufacturer Parts" %}',
text,
{
accept_text: '{% trans "Delete" %}',
accept: function() {
// Delete each manufacturer part
var requests = [];
parts.forEach(function(pk) {
var url = `/api/company/part/manufacturer/${pk}`;
requests.push(inventreeDelete(url));
});
// Wait for all the requests to complete
$.when(requests).then(function() {
if (options.onSuccess) {
options.onSuccess();
}
})
}
}
);
}
function loadManufacturerPartTable(table, url, options) {
/*
* Load manufacturer part table

View File

@ -906,7 +906,7 @@ function loadStockTable(table, options) {
);
});
$.when.apply($, requests).then(function() {
$.when(requests).then(function() {
$("#stock-table").bootstrapTable('refresh');
});
})