From 117fd701cded3ab728dbc66a81f1bba5fbb8b38d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 16 May 2019 22:19:49 +1000 Subject: [PATCH] Refactor some code --- InvenTree/part/templates/part/stock.html | 39 ------------------ InvenTree/static/script/inventree/stock.js | 36 ++++++++++++++++ InvenTree/stock/templates/stock/location.html | 41 +------------------ 3 files changed, 37 insertions(+), 79 deletions(-) diff --git a/InvenTree/part/templates/part/stock.html b/InvenTree/part/templates/part/stock.html index 60f283bea9..8b9561ea2e 100644 --- a/InvenTree/part/templates/part/stock.html +++ b/InvenTree/part/templates/part/stock.html @@ -44,43 +44,4 @@ url: "{% url 'api-stock-list' %}", }); - function selectedStock() { - return $("#stock-table").bootstrapTable('getSelections'); - } - - $("#multi-item-move").click(function() { - - var items = selectedStock(); - - moveStockItems(items, - { - success: function() { - $("#stock-table").bootstrapTable('refresh'); - } - }); - - return false; - }); - - $("#multi-item-stocktake").click(function() { - updateStockItems({ - action: 'stocktake' - }); - return false; - }); - - $("#multi-item-remove").click(function() { - updateStockItems({ - action: 'remove', - }); - return false; - }); - - $("#multi-item-add").click(function() { - updateStockItems({ - action: 'add', - }); - return false; - }) - {% endblock %} \ No newline at end of file diff --git a/InvenTree/static/script/inventree/stock.js b/InvenTree/static/script/inventree/stock.js index 8824965c41..b8d674556b 100644 --- a/InvenTree/static/script/inventree/stock.js +++ b/InvenTree/static/script/inventree/stock.js @@ -434,6 +434,42 @@ function loadStockTable(table, options) { if (options.buttons) { linkButtonsToSelection(table, options.buttons); } + + // Automatically link button callbacks + $('#multi-item-stocktake').click(function() { + updateStockItems({ + action: 'stocktake', + }); + return false; + }); + + $('#multi-item-remove').click(function() { + updateStockItems({ + action: 'remove', + }); + return false; + }); + + $('#multi-item-add').click(function() { + updateStockItems({ + action: 'add', + }); + return false; + }); + + $("#multi-item-move").click(function() { + + var items = $("#stock-table").bootstrapTable('getSelections'); + + moveStockItems(items, + { + success: function() { + $("#stock-table").bootstrapTable('refresh'); + } + }); + + return false; + }); } diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 311f0773cd..ae36078ece 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -132,46 +132,7 @@ return false; }); - - function selectedStock() { - return $("#stock-table").bootstrapTable('getSelections'); - } - - $("#multi-item-move").click(function() { - - var items = selectedStock(); - - moveStockItems(items, - { - success: function() { - $("#stock-table").bootstrapTable('refresh'); - } - }); - - return false; - }); - - $('#multi-item-stocktake').click(function() { - updateStockItems({ - action: 'stocktake', - }); - return false; - }); - - $('#multi-item-remove').click(function() { - updateStockItems({ - action: 'remove', - }); - return false; - }); - - $('#multi-item-add').click(function() { - updateStockItems({ - action: 'add', - }); - return false; - }); - + loadStockTable($("#stock-table"), { buttons: [ '#stock-options',