mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #973 from SchrodingersGat/multi-bom-item-delete
Multi bom item delete
This commit is contained in:
commit
65bc23a516
@ -108,6 +108,25 @@ function inventreePut(url, data={}, options={}) {
|
||||
if (options.error) {
|
||||
options.error(xhr, ajaxOptions, thrownError);
|
||||
}
|
||||
},
|
||||
complete: function(xhr, status) {
|
||||
if (options.complete) {
|
||||
options.complete(xhr, status);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function inventreeDelete(url, options={}) {
|
||||
/*
|
||||
* Delete a record
|
||||
*/
|
||||
|
||||
options = options || {};
|
||||
|
||||
options.method = 'DELETE';
|
||||
|
||||
inventreePut(url, {}, options);
|
||||
|
||||
}
|
@ -90,6 +90,48 @@
|
||||
location.href = "{% url 'part-bom' part.id %}";
|
||||
});
|
||||
|
||||
$('#bom-item-delete').click(function() {
|
||||
|
||||
// Get a list of the selected BOM items
|
||||
var rows = $("#bom-table").bootstrapTable('getSelections');
|
||||
|
||||
// TODO - In the future, display (in the dialog) which items are going to be deleted
|
||||
|
||||
showQuestionDialog(
|
||||
'{% trans "Delete selected BOM items?" %}',
|
||||
'{% trans "All selected BOM items will be deleted" %}',
|
||||
{
|
||||
accept: function() {
|
||||
|
||||
// Delete each row one at a time!
|
||||
function deleteRow(idx) {
|
||||
|
||||
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}/`;
|
||||
|
||||
inventreeDelete(
|
||||
url,
|
||||
{
|
||||
complete: function(xhr, status) {
|
||||
deleteRow(idx + 1);
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// Start the deletion!
|
||||
deleteRow(0);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$('#bom-upload').click(function() {
|
||||
location.href = "{% url 'upload-bom' part.id %}";
|
||||
});
|
||||
|
@ -39,7 +39,6 @@ function removeRowFromBomWizard(e) {
|
||||
if (colNum >= 3) {
|
||||
var cell = $(this).find('td:eq(1)');
|
||||
cell.text(rowNum++);
|
||||
console.log("Row: " + rowNum);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -106,26 +105,16 @@ function loadBomTable(table, options) {
|
||||
|
||||
// Construct the table columns
|
||||
|
||||
var cols = [
|
||||
{
|
||||
field: 'pk',
|
||||
title: 'ID',
|
||||
visible: false,
|
||||
switchable: false,
|
||||
},
|
||||
];
|
||||
var cols = [];
|
||||
|
||||
if (options.editable) {
|
||||
|
||||
/*
|
||||
// TODO - Enable multi-select functionality
|
||||
cols.push({
|
||||
field: 'ID',
|
||||
title: '',
|
||||
checkbox: true,
|
||||
title: 'Select',
|
||||
searchable: false,
|
||||
sortable: false,
|
||||
visible: true,
|
||||
switchable: false,
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
// Part column
|
||||
@ -234,16 +223,23 @@ function loadBomTable(table, options) {
|
||||
);
|
||||
|
||||
if (options.editable) {
|
||||
|
||||
cols.push({
|
||||
title: '{% trans "Actions" %}',
|
||||
switchable: false,
|
||||
field: 'pk',
|
||||
visible: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
|
||||
if (row.part == options.parent_id) {
|
||||
|
||||
var bValidate = "<button title='{% trans "Validate BOM Item" %}' class='bom-validate-button btn btn-default btn-glyph' type='button' pk='" + row.pk + "'><span class='fas fa-check-circle icon-blue'/></button>";
|
||||
var bValid = "<span title='{% trans "This line has been validated" %}' class='fas fa-check-double icon-green'/>";
|
||||
var bValidate = `<button title='{% trans "Validate BOM Item" %}' class='bom-validate-button btn btn-default btn-glyph' type='button' pk='${row.pk}'><span class='fas fa-check-circle icon-blue'/></button>`;
|
||||
|
||||
var bEdit = "<button title='{% trans "Edit BOM Item" %}' class='bom-edit-button btn btn-default btn-glyph' type='button' url='/part/bom/" + row.pk + "/edit'><span class='fas fa-edit'/></button>";
|
||||
var bDelt = "<button title='{% trans "Delete BOM Item" %}' class='bom-delete-button btn btn-default btn-glyph' type='button' url='/part/bom/" + row.pk + "/delete'><span class='fas fa-trash-alt icon-red'/></button>";
|
||||
var bValid = `<span title='{% trans "This line has been validated" %}' class='fas fa-check-double icon-green'/>`;
|
||||
|
||||
var bEdit = `<button title='{% trans "Edit BOM Item" %}' class='bom-edit-button btn btn-default btn-glyph' type='button' pk='${row.pk}'><span class='fas fa-edit'></span></button>`;
|
||||
|
||||
var bDelt = `<button title='{% trans "Delete BOM Item" %}' class='bom-delete-button btn btn-default btn-glyph' type='button' pk='${row.pk}'><span class='fas fa-trash-alt icon-red'></span></button>`;
|
||||
|
||||
var html = "<div class='btn-group' role='group'>";
|
||||
|
||||
@ -314,10 +310,10 @@ function loadBomTable(table, options) {
|
||||
}
|
||||
|
||||
table.inventreeTable({
|
||||
treeEnable: true,
|
||||
treeEnable: !options.editable,
|
||||
rootParentId: options.parent_id,
|
||||
idField: 'pk',
|
||||
uniqueId: 'pk',
|
||||
//uniqueId: 'pk',
|
||||
parentIdField: 'parentId',
|
||||
treeShowField: 'sub_part',
|
||||
showColumns: true,
|
||||
@ -333,20 +329,25 @@ function loadBomTable(table, options) {
|
||||
},
|
||||
formatNoMatches: function() { return "{% trans "No BOM items found" %}"; },
|
||||
clickToSelect: true,
|
||||
queryParams: function(p) {
|
||||
return params;
|
||||
},
|
||||
queryParams: params,
|
||||
columns: cols,
|
||||
url: options.bom_url,
|
||||
onPostBody: function() {
|
||||
|
||||
if (!options.editable) {
|
||||
table.treegrid({
|
||||
treeColumn: 0,
|
||||
onExpand: function() {
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
onLoadSuccess: function() {
|
||||
|
||||
if (options.editable) {
|
||||
table.bootstrapTable('uncheckAll');
|
||||
} else {
|
||||
|
||||
var data = table.bootstrapTable('getData');
|
||||
|
||||
for (var idx = 0; idx < data.length; idx++) {
|
||||
@ -366,6 +367,7 @@ function loadBomTable(table, options) {
|
||||
requestSubItems(row.pk, row.sub_part);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@ -373,29 +375,39 @@ function loadBomTable(table, options) {
|
||||
if (options.editable) {
|
||||
|
||||
table.on('click', '.bom-delete-button', function() {
|
||||
var button = $(this);
|
||||
|
||||
launchModalForm(button.attr('url'), {
|
||||
var pk = $(this).attr('pk');
|
||||
var url = `/part/bom/${pk}/delete/`;
|
||||
|
||||
launchModalForm(
|
||||
url,
|
||||
{
|
||||
success: function() {
|
||||
reloadBomTable(table);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
table.on('click', '.bom-edit-button', function() {
|
||||
var button = $(this);
|
||||
|
||||
launchModalForm(button.attr('url'), {
|
||||
var pk = $(this).attr('pk');
|
||||
var url = `/part/bom/${pk}/edit/`;
|
||||
|
||||
launchModalForm(
|
||||
url,
|
||||
{
|
||||
success: function() {
|
||||
reloadBomTable(table);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
table.on('click', '.bom-validate-button', function() {
|
||||
var button = $(this);
|
||||
|
||||
var url = '/api/bom/' + button.attr('pk') + '/validate/';
|
||||
var pk = $(this).attr('pk');
|
||||
var url = `/api/bom/${pk}/validate/`;
|
||||
|
||||
inventreePut(
|
||||
url,
|
||||
|
Loading…
Reference in New Issue
Block a user