mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Merge pull request #3006 from SchrodingersGat/bom-delete-fix
BOM delete fix
This commit is contained in:
commit
86c86bf446
@ -589,32 +589,15 @@
|
|||||||
// Get a list of the selected BOM items
|
// Get a list of the selected BOM items
|
||||||
var rows = $("#bom-table").bootstrapTable('getSelections');
|
var rows = $("#bom-table").bootstrapTable('getSelections');
|
||||||
|
|
||||||
// TODO - In the future, display (in the dialog) which items are going to be deleted
|
if (rows.length == 0) {
|
||||||
|
rows = $('#bom-table').bootstrapTable('getData');
|
||||||
showQuestionDialog(
|
|
||||||
'{% trans "Delete selected BOM items?" %}',
|
|
||||||
'{% trans "All selected BOM items will be deleted" %}',
|
|
||||||
{
|
|
||||||
accept: function() {
|
|
||||||
|
|
||||||
// Keep track of each DELETE request
|
|
||||||
var requests = [];
|
|
||||||
|
|
||||||
rows.forEach(function(row) {
|
|
||||||
requests.push(
|
|
||||||
inventreeDelete(
|
|
||||||
`/api/bom/${row.pk}/`,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Wait for *all* the requests to complete
|
|
||||||
$.when.apply($, requests).done(function() {
|
|
||||||
location.reload();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteBomItems(rows, {
|
||||||
|
success: function() {
|
||||||
|
$('#bom-table').bootstrapTable('refresh');
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#bom-upload').click(function() {
|
$('#bom-upload').click(function() {
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
/* exported
|
/* exported
|
||||||
constructBomUploadTable,
|
constructBomUploadTable,
|
||||||
|
deleteBomItems,
|
||||||
downloadBomTemplate,
|
downloadBomTemplate,
|
||||||
exportBom,
|
exportBom,
|
||||||
newPartFromBomWizard,
|
newPartFromBomWizard,
|
||||||
@ -647,7 +648,88 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
|
|||||||
reloadParentTable();
|
reloadParentTable();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function deleteBomItems(items, options={}) {
|
||||||
|
/* Delete the selected BOM items from the database
|
||||||
|
*/
|
||||||
|
|
||||||
|
function renderItem(item, opts={}) {
|
||||||
|
|
||||||
|
var sub_part = item.sub_part_detail;
|
||||||
|
var thumb = thumbnailImage(sub_part.thumbnail || sub_part.image);
|
||||||
|
|
||||||
|
var html = `
|
||||||
|
<tr>
|
||||||
|
<td>${thumb} ${sub_part.full_name}</td>
|
||||||
|
<td>${item.reference}</td>
|
||||||
|
<td>${item.quantity}
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows = '';
|
||||||
|
|
||||||
|
items.forEach(function(item) {
|
||||||
|
rows += renderItem(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
var html = `
|
||||||
|
<div class='alert alert-block alert-danger'>
|
||||||
|
{% trans "All selected BOM items will be deleted" %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class='table table-striped table-condensed'>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans "Part" %}</th>
|
||||||
|
<th>{% trans "Reference" %}</th>
|
||||||
|
<th>{% trans "Quantity" %}</th>
|
||||||
|
</tr>
|
||||||
|
${rows}
|
||||||
|
</table>
|
||||||
|
`;
|
||||||
|
|
||||||
|
constructFormBody({}, {
|
||||||
|
title: '{% trans "Delete selected BOM items?" %}',
|
||||||
|
fields: {},
|
||||||
|
preFormContent: html,
|
||||||
|
submitText: '{% trans "Delete" %}',
|
||||||
|
submitClass: 'danger',
|
||||||
|
confirm: true,
|
||||||
|
onSubmit: function(fields, opts) {
|
||||||
|
// Individually send DELETE requests for each BOM item
|
||||||
|
// We do *not* send these all at once, to prevent overloading the server
|
||||||
|
|
||||||
|
// Show the progress spinner
|
||||||
|
$(opts.modal).find('#modal-progress-spinner').show();
|
||||||
|
|
||||||
|
function deleteNextBomItem() {
|
||||||
|
|
||||||
|
if (items.length > 0) {
|
||||||
|
|
||||||
|
var item = items.shift();
|
||||||
|
|
||||||
|
inventreeDelete(`/api/bom/${item.pk}/`,
|
||||||
|
{
|
||||||
|
complete: deleteNextBomItem,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Destroy this modal once all items are deleted
|
||||||
|
$(opts.modal).modal('hide');
|
||||||
|
|
||||||
|
if (options.success) {
|
||||||
|
options.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteNextBomItem();
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1146,16 +1228,10 @@ function loadBomTable(table, options={}) {
|
|||||||
|
|
||||||
var pk = $(this).attr('pk');
|
var pk = $(this).attr('pk');
|
||||||
|
|
||||||
var html = `
|
var item = table.bootstrapTable('getRowByUniqueId', pk);
|
||||||
<div class='alert alert-block alert-danger'>
|
|
||||||
{% trans "Are you sure you want to delete this BOM item?" %}
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
constructForm(`/api/bom/${pk}/`, {
|
deleteBomItems([item], {
|
||||||
method: 'DELETE',
|
success: function() {
|
||||||
title: '{% trans "Delete BOM Item" %}',
|
|
||||||
preFormContent: html,
|
|
||||||
onSuccess: function() {
|
|
||||||
reloadBomTable(table);
|
reloadBomTable(table);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -288,6 +288,7 @@ function constructDeleteForm(fields, options) {
|
|||||||
* - method: The HTTP method e.g. 'PUT', 'POST', 'DELETE' (default='PATCH')
|
* - method: The HTTP method e.g. 'PUT', 'POST', 'DELETE' (default='PATCH')
|
||||||
* - title: The form title
|
* - title: The form title
|
||||||
* - submitText: Text for the "submit" button
|
* - submitText: Text for the "submit" button
|
||||||
|
* - submitClass: CSS class for the "submit" button (default = ')
|
||||||
* - closeText: Text for the "close" button
|
* - closeText: Text for the "close" button
|
||||||
* - fields: list of fields to display, with the following options
|
* - fields: list of fields to display, with the following options
|
||||||
* - filters: API query filters
|
* - filters: API query filters
|
||||||
|
@ -42,6 +42,8 @@ function createNewModal(options={}) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var submitClass = options.submitClass || 'primary';
|
||||||
|
|
||||||
var html = `
|
var html = `
|
||||||
<div class='modal fade modal-fixed-footer modal-primary inventree-modal' role='dialog' id='modal-form-${id}' tabindex='-1'>
|
<div class='modal fade modal-fixed-footer modal-primary inventree-modal' role='dialog' id='modal-form-${id}' tabindex='-1'>
|
||||||
<div class='modal-dialog'>
|
<div class='modal-dialog'>
|
||||||
@ -74,7 +76,7 @@ function createNewModal(options={}) {
|
|||||||
<span class='flex-item' style='flex-grow: 1;'></span>
|
<span class='flex-item' style='flex-grow: 1;'></span>
|
||||||
<h4><span id='modal-progress-spinner' class='fas fa-circle-notch fa-spin' style='display: none;'></span></h4>
|
<h4><span id='modal-progress-spinner' class='fas fa-circle-notch fa-spin' style='display: none;'></span></h4>
|
||||||
<button type='button' class='btn btn-secondary' id='modal-form-close' data-bs-dismiss='modal'>{% trans "Cancel" %}</button>
|
<button type='button' class='btn btn-secondary' id='modal-form-close' data-bs-dismiss='modal'>{% trans "Cancel" %}</button>
|
||||||
<button type='button' class='btn btn-primary' id='modal-form-submit'>{% trans "Submit" %}</button>
|
<button type='button' class='btn btn-${submitClass}' id='modal-form-submit'>{% trans "Submit" %}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user