From ba406a4da9289756849c7f40a3098757de1f77ad Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 3 Mar 2022 21:16:27 +1100 Subject: [PATCH] Refactorin' - Add the "download" button into the "filters" list - Cuts down on boilerplate code --- InvenTree/company/templates/company/detail.html | 11 ----------- .../company/templates/company/supplier_part.html | 4 ---- InvenTree/part/templates/part/category.html | 7 ------- InvenTree/part/templates/part/detail.html | 7 +------ InvenTree/stock/templates/stock/location.html | 4 ---- InvenTree/templates/js/translated/filters.js | 16 ++++++++++++++-- InvenTree/templates/js/translated/part.js | 2 +- InvenTree/templates/js/translated/stock.js | 2 +- InvenTree/templates/stock_table.html | 3 --- 9 files changed, 17 insertions(+), 39 deletions(-) diff --git a/InvenTree/company/templates/company/detail.html b/InvenTree/company/templates/company/detail.html index 3c9aa92c9a..0717d02d4d 100644 --- a/InvenTree/company/templates/company/detail.html +++ b/InvenTree/company/templates/company/detail.html @@ -170,9 +170,6 @@
- {% include "filter_list.html" with id="customerstock" %}
@@ -233,10 +230,6 @@ filterTarget: '#filter-list-customerstock', }); - $('#assigned-stock-export').click(function() { - downloadTableData($('#assigned-stock-table')); - }); - {% if company.is_customer %} loadSalesOrderTable("#sales-order-table", { url: "{% url 'api-so-list' %}", @@ -291,10 +284,6 @@ filterKey: "companystock", }); - $("#stock-export").click(function() { - downloadTableData($("#stock-table")); - }); - {% if company.is_manufacturer %} function reloadManufacturerPartTable() { diff --git a/InvenTree/company/templates/company/supplier_part.html b/InvenTree/company/templates/company/supplier_part.html index 1fe1ea86b4..44e6756845 100644 --- a/InvenTree/company/templates/company/supplier_part.html +++ b/InvenTree/company/templates/company/supplier_part.html @@ -308,10 +308,6 @@ loadStockTable($("#stock-table"), { url: "{% url 'api-stock-list' %}", }); -$("#stock-export").click(function() { - downloadTableData($("#stock-table")); -}); - $("#item-create").click(function() { createNewStockItem({ data: { diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index 8f30b9b46a..acbd0b16f1 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -164,9 +164,6 @@
- @@ -290,10 +287,6 @@ }); }); - $("#part-export").click(function() { - downloadTableData($('#part-table')); - }); - {% if roles.part.add %} $("#part-create").click(function() { diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 172315b50e..9007d91839 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -831,12 +831,7 @@ ], url: "{% url 'api-stock-list' %}", }); - - $("#stock-export").click(function() { - - downloadTableData($("#stock-table")); - }); - + $('#item-create').click(function () { createNewStockItem({ data: { diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 575a798fb2..1da0030bc6 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -239,10 +239,6 @@ }); {% endif %} - $("#stock-export").click(function() { - downloadTableData($('#stock-table')); - }); - $('#location-create').click(function () { createStockLocation({ diff --git a/InvenTree/templates/js/translated/filters.js b/InvenTree/templates/js/translated/filters.js index 78ed30eefa..1a8c0267ee 100644 --- a/InvenTree/templates/js/translated/filters.js +++ b/InvenTree/templates/js/translated/filters.js @@ -256,7 +256,7 @@ function generateFilterInput(tableKey, filterKey) { * @param {*} table - bootstrapTable element to update * @param {*} target - name of target element on page */ -function setupFilterList(tableKey, table, target) { +function setupFilterList(tableKey, table, target, options={}) { var addClicked = false; @@ -283,6 +283,11 @@ function setupFilterList(tableKey, table, target) { var buttons = ''; + // Add download button + if (options.download) { + buttons += ``; + } + buttons += ``; // If there are filters defined for this table, add more buttons @@ -295,7 +300,7 @@ function setupFilterList(tableKey, table, target) { } element.html(` -
+
${buttons}
`); @@ -322,6 +327,13 @@ function setupFilterList(tableKey, table, target) { $(table).bootstrapTable('refresh'); }); + // Add a callback for downloading table data + if (options.download) { + element.find(`#download-${tableKey}`).click(function() { + downloadTableData($(table)); + }); + } + // Add a callback for adding a new filter element.find(`#${add}`).click(function clicked() { diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index d42755a0f0..a0887f9473 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -1218,7 +1218,7 @@ function loadPartTable(table, url, options={}) { filters[key] = params[key]; } - setupFilterList('parts', $(table), options.filterTarget || null); + setupFilterList('parts', $(table), options.filterTarget, {download: true}); var columns = [ { diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 6239a886ab..dcca969a28 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -1571,7 +1571,7 @@ function loadStockTable(table, options) { original[k] = params[k]; } - setupFilterList(filterKey, table, filterTarget); + setupFilterList(filterKey, table, filterTarget, {download: true}); // Override the default values, or add new ones for (var key in params) { diff --git a/InvenTree/templates/stock_table.html b/InvenTree/templates/stock_table.html index a8a4ec6691..d609e78253 100644 --- a/InvenTree/templates/stock_table.html +++ b/InvenTree/templates/stock_table.html @@ -11,9 +11,6 @@
- {% if barcodes %}