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 %}
parent: null,
{% endif %}
}
},
allowTreeView: true,
}
);

View File

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

View File

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