BOM Display: Multiple fixes

- Previous multi-level BOM display changes had broken the table in editing mode
- Simplify code
- Re-implement edit / delete / validate buttons
- Re-enable checkboxes in edit mode
This commit is contained in:
Oliver Walters 2020-09-13 00:13:53 +10:00
parent 8c9491f3ca
commit 36ac268b96

View File

@ -39,7 +39,6 @@ function removeRowFromBomWizard(e) {
if (colNum >= 3) { if (colNum >= 3) {
var cell = $(this).find('td:eq(1)'); var cell = $(this).find('td:eq(1)');
cell.text(rowNum++); cell.text(rowNum++);
console.log("Row: " + rowNum);
} }
}); });
} }
@ -106,26 +105,16 @@ function loadBomTable(table, options) {
// Construct the table columns // Construct the table columns
var cols = [ var cols = [];
{
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
];
if (options.editable) { if (options.editable) {
/*
// TODO - Enable multi-select functionality
cols.push({ cols.push({
field: 'ID',
title: '',
checkbox: true, checkbox: true,
title: 'Select', visible: true,
searchable: false, switchable: false,
sortable: false,
}); });
*/
} }
// Part column // Part column
@ -234,16 +223,23 @@ function loadBomTable(table, options) {
); );
if (options.editable) { if (options.editable) {
cols.push({ cols.push({
title: '{% trans "Actions" %}',
switchable: false,
field: 'pk',
visible: true,
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
if (row.part == options.parent_id) { 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 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 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' url='/part/bom/" + row.pk + "/edit'><span class='fas fa-edit'/></button>"; 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' url='/part/bom/" + row.pk + "/delete'><span class='fas fa-trash-alt icon-red'/></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'>"; var html = "<div class='btn-group' role='group'>";
@ -314,10 +310,10 @@ function loadBomTable(table, options) {
} }
table.inventreeTable({ table.inventreeTable({
treeEnable: true, treeEnable: !options.editable,
rootParentId: options.parent_id, rootParentId: options.parent_id,
idField: 'pk', idField: 'pk',
uniqueId: 'pk', //uniqueId: 'pk',
parentIdField: 'parentId', parentIdField: 'parentId',
treeShowField: 'sub_part', treeShowField: 'sub_part',
showColumns: true, showColumns: true,
@ -333,37 +329,43 @@ function loadBomTable(table, options) {
}, },
formatNoMatches: function() { return "{% trans "No BOM items found" %}"; }, formatNoMatches: function() { return "{% trans "No BOM items found" %}"; },
clickToSelect: true, clickToSelect: true,
queryParams: function(p) { queryParams: params,
return params;
},
columns: cols, columns: cols,
url: options.bom_url, url: options.bom_url,
onPostBody: function() { onPostBody: function() {
table.treegrid({
treeColumn: 0, if (!options.editable) {
onExpand: function() { table.treegrid({
} treeColumn: 0,
}); onExpand: function() {
}
});
}
}, },
onLoadSuccess: function() { onLoadSuccess: function() {
var data = table.bootstrapTable('getData'); if (options.editable) {
table.bootstrapTable('uncheckAll');
} else {
for (var idx = 0; idx < data.length; idx++) { var data = table.bootstrapTable('getData');
var row = data[idx];
// If a row already has a parent ID set, it's already been updated! for (var idx = 0; idx < data.length; idx++) {
if (row.parentId) { var row = data[idx];
continue;
}
// Set the parent ID of the top-level rows // If a row already has a parent ID set, it's already been updated!
row.parentId = options.parent_id; if (row.parentId) {
continue;
}
table.bootstrapTable('updateRow', idx, row, true); // Set the parent ID of the top-level rows
row.parentId = options.parent_id;
if (row.sub_part_detail.assembly) { table.bootstrapTable('updateRow', idx, row, true);
requestSubItems(row.pk, row.sub_part);
if (row.sub_part_detail.assembly) {
requestSubItems(row.pk, row.sub_part);
}
} }
} }
}, },
@ -373,29 +375,39 @@ function loadBomTable(table, options) {
if (options.editable) { if (options.editable) {
table.on('click', '.bom-delete-button', function() { table.on('click', '.bom-delete-button', function() {
var button = $(this);
var pk = $(this).attr('pk');
var url = `/part/bom/${pk}/delete/`;
launchModalForm(button.attr('url'), { launchModalForm(
success: function() { url,
reloadBomTable(table); {
} success: function() {
}); reloadBomTable(table);
}
}
);
}); });
table.on('click', '.bom-edit-button', function() { table.on('click', '.bom-edit-button', function() {
var button = $(this);
var pk = $(this).attr('pk');
var url = `/part/bom/${pk}/edit/`;
launchModalForm(button.attr('url'), { launchModalForm(
success: function() { url,
reloadBomTable(table); {
} success: function() {
}); reloadBomTable(table);
}
}
);
}); });
table.on('click', '.bom-validate-button', function() { table.on('click', '.bom-validate-button', function() {
var button = $(this);
var pk = $(this).attr('pk');
var url = '/api/bom/' + button.attr('pk') + '/validate/'; var url = `/api/bom/${pk}/validate/`;
inventreePut( inventreePut(
url, url,