mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Functionalize loadPartTable
This commit is contained in:
parent
2a66224952
commit
0058207fad
@ -119,81 +119,18 @@
|
||||
|
||||
{% endif %}
|
||||
|
||||
$("#part-table").bootstrapTable({
|
||||
sortable: true,
|
||||
search: true,
|
||||
sortName: 'name',
|
||||
idField: 'pk',
|
||||
method: 'get',
|
||||
pagination: true,
|
||||
rememberOrder: true,
|
||||
queryParams: function(p) {
|
||||
return {
|
||||
active: true,
|
||||
loadPartTable(
|
||||
"#part-table",
|
||||
"{% url 'api-part-list' %}",
|
||||
{
|
||||
query: {
|
||||
{% if category %}
|
||||
category: {{ category.id }},
|
||||
include_child_categories: true,
|
||||
{% endif %}
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
checkbox: true,
|
||||
title: 'Select',
|
||||
searchable: false,
|
||||
buttons: ['#part-options'],
|
||||
},
|
||||
{
|
||||
field: 'pk',
|
||||
title: 'ID',
|
||||
visible: false,
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: 'Part',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
return imageHoverIcon(row.image_url) + renderLink(value, row.url);
|
||||
}
|
||||
},
|
||||
{
|
||||
sortable: true,
|
||||
field: 'description',
|
||||
title: 'Description',
|
||||
},
|
||||
{
|
||||
sortable: true,
|
||||
field: 'category_name',
|
||||
title: 'Category',
|
||||
formatter: function(value, row, index, field) {
|
||||
if (row.category) {
|
||||
return renderLink(row.category_name, "/part/category/" + row.category + "/");
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'total_stock',
|
||||
title: 'Stock',
|
||||
searchable: false,
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
if (value) {
|
||||
return renderLink(value, row.url + 'stock/');
|
||||
}
|
||||
else {
|
||||
return "<span class='label label-warning'>No stock</span>";
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
url: "{% url 'api-part-list' %}",
|
||||
});
|
||||
|
||||
linkButtonsToSelection(
|
||||
$("#part-table"),
|
||||
['#part-options']
|
||||
);
|
||||
|
||||
{% endblock %}
|
@ -73,3 +73,88 @@ function toggleStar(options) {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function loadPartTable(table, url, options={}) {
|
||||
/* Load part listing data into specified table.
|
||||
*
|
||||
* Args:
|
||||
* - table: HTML reference to the table
|
||||
* - url: Base URL for API query
|
||||
* - options: object containing following (optional) fields
|
||||
* query: extra query params for API request
|
||||
* buttons: If provided, link buttons to selection status of this table
|
||||
*/
|
||||
|
||||
// Default query params
|
||||
options.active = true;
|
||||
|
||||
$(table).bootstrapTable({
|
||||
url: url,
|
||||
sortable: true,
|
||||
search: true,
|
||||
sortName: 'name',
|
||||
method: 'get',
|
||||
pagination: true,
|
||||
pageSize: 25,
|
||||
rememberOrder: true,
|
||||
queryParams: function(p) {
|
||||
return options;
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
checkbox: true,
|
||||
title: 'Select',
|
||||
searchable: false,
|
||||
},
|
||||
{
|
||||
field: 'pk',
|
||||
title: 'ID',
|
||||
visible: false,
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: 'Part',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
return imageHoverIcon(row.image_url) + renderLink(value, row.url);
|
||||
}
|
||||
},
|
||||
{
|
||||
sortable: true,
|
||||
field: 'description',
|
||||
title: 'Description',
|
||||
},
|
||||
{
|
||||
sortable: true,
|
||||
field: 'category_name',
|
||||
title: 'Category',
|
||||
formatter: function(value, row, index, field) {
|
||||
if (row.category) {
|
||||
return renderLink(row.category_name, "/part/category/" + row.category + "/");
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'total_stock',
|
||||
title: 'Stock',
|
||||
searchable: false,
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
if (value) {
|
||||
return renderLink(value, row.url + 'stock/');
|
||||
}
|
||||
else {
|
||||
return "<span class='label label-warning'>No stock</span>";
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
});
|
||||
|
||||
if (options.buttons) {
|
||||
linkButtonsToSelection($(table), options.buttons);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user