Created js function to load stock table

- Avoid duplication of code
This commit is contained in:
Oliver Walters 2019-04-17 22:59:52 +10:00
parent 0dc26eec82
commit ba1b8d9181
3 changed files with 71 additions and 104 deletions

View File

@ -45,50 +45,11 @@
}); });
}); });
$("#stock-table").bootstrapTable({ loadStockTable($("#stock-table"), {
sortable: true, params: {
search: true,
pagination: true,
queryParams: function(p) {
return {
part: {{ part.id }}, part: {{ part.id }},
in_stock: true,
}
}, },
columns: [ url: "{% url 'api-stock-list' %}",
{
field: 'pk',
title: 'ID',
visible: false,
},
{
checkbox: true,
},
{
field: 'location',
title: 'Location',
sortable: true,
formatter: function(value, row, index, field){
return renderLink(value.pathstring, value.url);
}
},
{
field: 'quantity',
title: 'Stock',
searchable: false,
sortable: true,
formatter: function(value, row, index, field) {
var text = renderLink(value, row.url)
text = text + "<span class='badge'>" + row.status + "</span>";
return text;
}
},
{
field: 'notes',
title: 'Notes',
},
],
url: "{% url 'api-stock-list' %}"
}); });
function selectedStock() { function selectedStock() {

View File

@ -278,3 +278,63 @@ function deleteStockItems(items, options) {
title: 'Delete ' + items.length + ' stock items' title: 'Delete ' + items.length + ' stock items'
}); });
} }
function loadStockTable(modal, options) {
modal.bootstrapTable({
sortable: true,
search: true,
method: 'get',
pagination: true,
rememberOrder: true,
queryParams: options.params,
columns: [
{
checkbox: true,
title: 'Select',
searchable: false,
},
{
field: 'pk',
title: 'ID',
visible: false,
},
{
field: 'part.name',
title: 'Part',
sortable: true,
formatter: function(value, row, index, field) {
return renderLink(value, row.part.url);
}
},
{
field: 'location',
title: 'Location',
sortable: true,
formatter: function(value, row, index, field) {
if (row.location) {
return renderLink(row.location.pathstring, row.location.url);
}
else {
return '';
}
}
},
{
field: 'quantity',
title: 'Quantity',
sortable: true,
formatter: function(value, row, index, field) {
var text = renderLink(value, row.url);
text = text + "<span class='badge'>" + row.status + "</span>";
return text;
}
},
{
field: 'notes',
title: 'Notes',
}
],
url: options.url,
});
};

View File

@ -9,6 +9,7 @@
<p>{{ location.description }}</p> <p>{{ location.description }}</p>
{% else %} {% else %}
<h3>Stock</h3> <h3>Stock</h3>
<p>All stock items</p>
{% endif %} {% endif %}
</div> </div>
<div class='col-sm-6'> <div class='col-sm-6'>
@ -160,67 +161,12 @@
return false; return false;
}); });
$("#stock-table").bootstrapTable({ loadStockTable($("#stock-table"), {
sortable: true, params: {
search: true,
method: 'get',
pagination: true,
rememberOrder: true,
{% if location %} {% if location %}
queryParams: function(p) {
return {
location: {{ location.id }} location: {{ location.id }}
}
},
{% endif %} {% endif %}
columns: [
{
checkbox: true,
title: 'Select',
searchable: false,
}, },
{
field: 'pk',
title: 'ID',
visible: false,
},
{
field: 'part.name',
title: 'Part',
sortable: true,
formatter: function(value, row, index, field) {
return renderLink(value, row.part.url);
}
},
{% if location == None %}
{
field: 'location',
title: 'Location',
sortable: true,
formatter: function(value, row, index, field) {
if (row.location) {
return renderLink(row.location.name, row.location.url);
}
else {
return '';
}
}
},
{% endif %}
{
field: 'quantity',
title: 'Stock',
sortable: true,
formatter: function(value, row, index, field) {
return renderLink(value, row.url);
}
},
{
field: 'status',
title: 'Status',
sortable: true,
}
],
url: "{% url 'api-stock-list' %}", url: "{% url 'api-stock-list' %}",
}); });