Company table now in separate javascript file

(cherry picked from commit 95354f09da)
This commit is contained in:
Oliver Walters 2020-04-13 12:23:15 +10:00
parent 094a0fe709
commit edfb19db13
4 changed files with 88 additions and 56 deletions

View File

@ -0,0 +1,82 @@
function loadCompanyTable(table, url, options={}) {
/*
* Load company listing data into specified table.
*
* Args:
* - table: Table element on the page
* - url: Base URL for the API query
* - options: table options.
*/
// Query parameters
var params = options.params || {};
var filters = loadTableFilters("company");
for (var key in params) {
filters[key] = params[key];
}
setupFilterList("company", $(table));
$(table).inventreeTable({
url: url,
method: 'get',
queryParams: filters,
groupBy: false,
formatNoMatches: function() { return "No company information found"; },
columns: [
{
field: 'pk',
title: 'ID',
visible: false,
},
{
field: 'name',
title: 'Company',
sortable: true,
formatter: function(value, row, index, field) {
var html = imageHoverIcon(row.image) + renderLink(value, row.url);
if (row.is_customer) {
html += `<span title='Customer' class='fas fa-user label-right'></span>`;
}
if (row.is_manufacturer) {
html += `<span title='Manufacturer' class='fas fa-industry label-right'></span>`;
}
if (row.is_supplier) {
html += `<span title='Supplier' class='fas fa-building label-right'></span>`;
}
return html;
}
},
{
field: 'description',
title: 'Description',
sortable: true,
},
{
field: 'website',
title: 'Website',
formatter: function(value, row, index, field) {
if (value) {
return renderLink(value, value);
}
return '';
}
},
{
field: 'part_count',
title: 'Parts',
sortable: true,
formatter: function(value, row, index, field) {
return renderLink(value, row.url + 'parts/');
}
},
],
});
}

View File

@ -17,6 +17,7 @@ function defaultFilters() {
stock: "cascade=1", stock: "cascade=1",
build: "", build: "",
parts: "cascade=1", parts: "cascade=1",
company: "",
}; };
} }

View File

@ -33,61 +33,9 @@ InvenTree | {% trans "Supplier List" %}
}); });
}); });
$("#company-table").inventreeTable({ loadCompanyTable("#company-table", "{% url 'api-company-list' %}",
formatNoMatches: function() { return "No company information found"; },
columns: [
{ {
field: 'pk',
title: '{% trans "ID" %}',
visible: false,
},
{
field: 'name',
title: '{% trans "Supplier" %}',
sortable: true,
formatter: function(value, row, index, field) {
var html = imageHoverIcon(row.image) + renderLink(value, row.url);
if (row.is_customer) {
html += `<span title='Customer' class='fas fa-user label-right'></span>`;
} }
);
if (row.is_manufacturer) {
html += `<span title='Manufacturer' class='fas fa-industry label-right'></span>`;
}
if (row.is_supplier) {
html += `<span title='Supplier' class='fas fa-building label-right'></span>`;
}
return html;
}
},
{
field: 'description',
title: '{% trans "Description" %}',
sortable: true,
},
{
field: 'website',
title: '{% trans "Website" %}',
formatter: function(value, row, index, field) {
if (value) {
return renderLink(value, value);
}
return '';
}
},
{
field: 'part_count',
title: '{% trans "Parts" %}',
sortable: true,
formatter: function(value, row, index, field) {
return renderLink(value, row.url + 'parts/');
}
},
],
url: "{% url 'api-company-list' %}"
});
{% endblock %} {% endblock %}

View File

@ -108,6 +108,7 @@ InvenTree
<script type='text/javascript' src="{% static 'script/inventree/build.js' %}"></script> <script type='text/javascript' src="{% static 'script/inventree/build.js' %}"></script>
<script type='text/javascript' src="{% static 'script/inventree/modals.js' %}"></script> <script type='text/javascript' src="{% static 'script/inventree/modals.js' %}"></script>
<script type='text/javascript' src="{% static 'script/inventree/order.js' %}"></script> <script type='text/javascript' src="{% static 'script/inventree/order.js' %}"></script>
<script type='text/javascript' src="{% static 'script/inventree/company.js' %}"></script>
<script type='text/javascript' src="{% static 'script/inventree/notification.js' %}"></script> <script type='text/javascript' src="{% static 'script/inventree/notification.js' %}"></script>
<script type='text/javascript' src="{% static 'script/inventree/sidenav.js' %}"></script> <script type='text/javascript' src="{% static 'script/inventree/sidenav.js' %}"></script>