Fixes for part category table

(cherry picked from commit f7ef309995f8a52c213748f4a9226724e288c936)
This commit is contained in:
Oliver 2021-11-03 13:33:38 +11:00
parent c4ea3ecf6f
commit 08ffa102c6
3 changed files with 32 additions and 26 deletions

View File

@ -210,7 +210,8 @@
{% else %} {% else %}
parent: null, parent: null,
{% endif %} {% endif %}
} },
allowTreeView: true,
} }
); );

View File

@ -1133,8 +1133,10 @@ function loadPartTable(table, url, options={}) {
} }
/*
* Display a table of part categories
*/
function loadPartCategoryTable(table, options) { function loadPartCategoryTable(table, options) {
/* Display a table of part categories */
var params = options.params || {}; var params = options.params || {};
@ -1157,15 +1159,15 @@ function loadPartCategoryTable(table, options) {
setupFilterList(filterKey, table, filterListElement); setupFilterList(filterKey, table, filterListElement);
var tree_view = inventreeLoad('category-tree-view') == 1; var tree_view = options.allowTreeView && inventreeLoad('category-tree-view') == 1;
table.inventreeTable({ table.inventreeTable({
treeEnable: tree_view, treeEnable: tree_view,
rootParentId: options.params.parent, rootParentId: tree_view ? options.params.parent : null,
uniqueId: 'pk', uniqueId: 'pk',
idField: 'pk', idField: 'pk',
treeShowField: 'name', treeShowField: 'name',
parentIdField: 'parent', parentIdField: tree_view ? 'parent' : null,
method: 'get', method: 'get',
url: options.url || '{% url "api-part-category-list" %}', url: options.url || '{% url "api-part-category-list" %}',
queryParams: filters, queryParams: filters,
@ -1176,7 +1178,7 @@ function loadPartCategoryTable(table, options) {
name: 'category', name: 'category',
original: original, original: original,
showColumns: true, showColumns: true,
buttons: [ buttons: options.allowTreeView ? [
{ {
icon: 'fas fa-bars', icon: 'fas fa-bars',
attributes: { attributes: {
@ -1215,9 +1217,11 @@ function loadPartCategoryTable(table, options) {
); );
} }
} }
], ] : [],
onPostBody: function() { onPostBody: function() {
if (options.allowTreeView) {
tree_view = inventreeLoad('category-tree-view') == 1; tree_view = inventreeLoad('category-tree-view') == 1;
if (tree_view) { if (tree_view) {
@ -1238,6 +1242,7 @@ function loadPartCategoryTable(table, options) {
$('#view-category-tree').removeClass('btn-secondary').addClass('btn-outline-secondary'); $('#view-category-tree').removeClass('btn-secondary').addClass('btn-outline-secondary');
$('#view-category-list').removeClass('btn-outline-secondary').addClass('btn-secondary'); $('#view-category-list').removeClass('btn-outline-secondary').addClass('btn-secondary');
} }
}
}, },
columns: [ columns: [
{ {

View File

@ -1449,8 +1449,8 @@ function loadStockLocationTable(table, options) {
var tree_view = options.allowTreeView && inventreeLoad('location-tree-view') == 1; var tree_view = options.allowTreeView && inventreeLoad('location-tree-view') == 1;
table.inventreeTable({ table.inventreeTable({
treeEnable: options.allowTreeView && tree_view, treeEnable: tree_view,
rootParentId: options.params.parent, rootParentId: tree_view ? options.params.parent : null,
uniqueId: 'pk', uniqueId: 'pk',
idField: 'pk', idField: 'pk',
treeShowField: 'name', treeShowField: 'name',