Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make checkbox field non-switchable for stock table #939

Merged
merged 5 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 55 additions & 1 deletion InvenTree/InvenTree/static/script/inventree/tables.js
Expand Up @@ -80,11 +80,28 @@ function reloadTable(table, filters) {
}


function visibleColumnString(columns) {
/* Generate a list of "visible" columns to save to file. */

var fields = [];

columns.forEach(function(column) {
if (column.switchable && column.visible) {
fields.push(column.field);
}
});

return fields.join(',');
}


/* Wrapper function for bootstrapTable.
* Sets some useful defaults, and manage persistent settings.
*/
$.fn.inventreeTable = function(options) {

var table = this;

var tableName = options.name || 'table';

var varName = tableName + '-pagesize';
Expand All @@ -95,14 +112,51 @@ $.fn.inventreeTable = function(options) {
options.rememberOrder = true;
options.sortable = true;
options.search = true;
options.showColumns = true;

// Callback to save pagination data
options.onPageChange = function(number, size) {
inventreeSave(varName, size);
};

// Callback when a column is changed
options.onColumnSwitch = function(field, checked) {
console.log(`${field} -> ${checked}`);

var columns = table.bootstrapTable('getVisibleColumns');

var text = visibleColumnString(columns);

// Save visible columns
inventreeSave(`table_columns_${tableName}`, text);
};

// Standard options for all tables
this.bootstrapTable(options);
table.bootstrapTable(options);

// Load visible column list from memory
// Load visible column list
var visibleColumns = inventreeLoad(`table_columns_${tableName}`, null);

// If a set of visible columns has been saved, load!
if (visibleColumns) {
var columns = visibleColumns.split(",");

// Which columns are currently visible?
var visible = table.bootstrapTable('getVisibleColumns');

if (visible) {
visible.forEach(function(column) {

// Visible field should *not* be visible! (hide it!)
if (column.switchable && !columns.includes(column.field)) {
table.bootstrapTable('hideColumn', column.field);
}
});
} else {
console.log('Could not get list of visible columns!');
}
}
}

function customGroupSorter(sortName, sortOrder, sortData) {
Expand Down
2 changes: 2 additions & 0 deletions InvenTree/order/templates/order/purchase_order_detail.html
Expand Up @@ -127,6 +127,7 @@ <h4>{% trans "Purchase Order Items" %}</h4>

$("#po-table").inventreeTable({
onPostBody: setupCallbacks,
name: 'purchaseorder',
formatNoMatches: function() { return "{% trans 'No line items found' %}"; },
queryParams: {
order: {{ order.id }},
Expand All @@ -138,6 +139,7 @@ <h4>{% trans "Purchase Order Items" %}</h4>
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
{
field: 'part',
Expand Down
1 change: 1 addition & 0 deletions InvenTree/order/templates/order/sales_order_detail.html
Expand Up @@ -190,6 +190,7 @@ <h4>{% trans "Sales Order Items" %}</h4>
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
{
sortable: true,
Expand Down
1 change: 1 addition & 0 deletions InvenTree/part/templates/part/used_in.html
Expand Up @@ -29,6 +29,7 @@ <h4>{% trans "Assemblies" %}</h4>
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
{
field: 'part_detail',
Expand Down
1 change: 1 addition & 0 deletions InvenTree/templates/InvenTree/settings/currency.html
Expand Up @@ -37,6 +37,7 @@ <h4>Currencies</h4>
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
{
field: 'symbol',
Expand Down
1 change: 1 addition & 0 deletions InvenTree/templates/InvenTree/settings/part.html
Expand Up @@ -31,6 +31,7 @@ <h4>{% trans "Part Parameter Templates" %}</h4>
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
{
field: 'name',
Expand Down
2 changes: 2 additions & 0 deletions InvenTree/templates/js/bom.html
Expand Up @@ -111,6 +111,7 @@
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
];

Expand Down Expand Up @@ -320,6 +321,7 @@
parentIdField: 'parentId',
treeShowField: 'sub_part',
showColumns: true,
name: 'bom',
sortable: true,
search: true,
rowStyle: function(row, index) {
Expand Down
2 changes: 2 additions & 0 deletions InvenTree/templates/js/build.html
Expand Up @@ -21,12 +21,14 @@
url: options.url,
queryParams: filters,
groupBy: false,
name: 'builds',
original: params,
columns: [
{
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
{
field: 'title',
Expand Down
6 changes: 6 additions & 0 deletions InvenTree/templates/js/company.html
Expand Up @@ -27,16 +27,20 @@
queryParams: filters,
groupBy: false,
formatNoMatches: function() { return "{% trans "No company information found" %}"; },
showColumns: true,
name: 'company',
columns: [
{
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
{
field: 'name',
title: '{% trans "Company" %}',
sortable: true,
switchable: false,
formatter: function(value, row, index, field) {
var html = imageHoverIcon(row.image) + renderLink(value, row.url);

Expand Down Expand Up @@ -97,11 +101,13 @@
url: url,
method: 'get',
queryParams: filters,
name: 'supplierparts',
groupBy: false,
formatNoMatches: function() { return "{% trans "No supplier parts found" %}"; },
columns: [
{
checkbox: true,
switchable: false,
},
{
sortable: true,
Expand Down
4 changes: 4 additions & 0 deletions InvenTree/templates/js/order.html
Expand Up @@ -121,6 +121,7 @@
$(table).inventreeTable({
url: options.url,
queryParams: filters,
name: 'purchaseorder',
groupBy: false,
original: options.params,
formatNoMatches: function() { return "{% trans "No purchase orders found" %}"; },
Expand All @@ -129,6 +130,7 @@
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
{
sortable: true,
Expand Down Expand Up @@ -194,6 +196,7 @@
$(table).inventreeTable({
url: options.url,
queryParams: filters,
name: 'salesorder',
groupBy: false,
original: options.params,
formatNoMatches: function() { return "{% trans "No sales orders found" %}"; },
Expand All @@ -202,6 +205,7 @@
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
{
sortable: true,
Expand Down
2 changes: 2 additions & 0 deletions InvenTree/templates/js/part.html
Expand Up @@ -237,6 +237,7 @@
method: 'get',
queryParams: filters,
groupBy: false,
name: 'part',
original: params,
formatNoMatches: function() { return "{% trans "No parts found" %}"; },
columns: columns,
Expand Down Expand Up @@ -338,6 +339,7 @@
},
url: "{% url 'api-part-test-template-list' %}",
queryParams: filters,
name: 'testtemplate',
original: original,
columns: [
{
Expand Down
4 changes: 4 additions & 0 deletions InvenTree/templates/js/stock.html
Expand Up @@ -73,6 +73,7 @@
table.inventreeTable({
url: "{% url 'api-part-test-template-list' %}",
method: 'get',
name: 'testresult',
formatNoMatches: function() {
return "{% trans 'No test results found' %}";
},
Expand All @@ -84,6 +85,7 @@
field: 'pk',
title: 'ID',
visible: false,
switchable: false,
},
{
field: 'test_name',
Expand Down Expand Up @@ -264,6 +266,7 @@
queryParams: filters,
customSort: customGroupSorter,
groupBy: true,
name: 'stock',
original: original,
showColumns: true,
groupByField: options.groupByField || 'part',
Expand Down Expand Up @@ -405,6 +408,7 @@
checkbox: true,
title: '{% trans "Select" %}',
searchable: false,
switchable: false,
},
{
field: 'pk',
Expand Down