From af47b211fdaccce2194f2f3834797e83a8031d5e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 11 Jan 2021 17:22:04 +1100 Subject: [PATCH] Add dialog for selection of stock location labels --- InvenTree/stock/templates/stock/location.html | 11 ++- InvenTree/templates/js/label.js | 76 ++++++++++++++++--- 2 files changed, 75 insertions(+), 12 deletions(-) diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index fef3428373..81bafc5bf1 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -29,7 +29,7 @@ @@ -203,6 +203,15 @@ } }); }); + + $('#print-label').click(function() { + + var locs = [{{ location.pk }}]; + + printStockLocationLabels(locs); + + }); + {% endif %} $('#show-qr-code').click(function() { diff --git a/InvenTree/templates/js/label.js b/InvenTree/templates/js/label.js index e65162dcec..5d2afb0fb6 100644 --- a/InvenTree/templates/js/label.js +++ b/InvenTree/templates/js/label.js @@ -8,7 +8,7 @@ function printStockItemLabels(items, options={}) { if (items.length == 0) { showAlertDialog( '{% trans "Select Stock Items" %}', - '{% trans "Stock items must be selected before printing labels" %}' + '{% trans "Stock item(s) must be selected before printing labels" %}' ); return; @@ -29,16 +29,76 @@ function printStockItemLabels(items, options={}) { '{% trans "No Labels Found" %}', '{% trans "No labels found which match selected stock item(s)" %}', ); + return; } // Select label to print - selectLabel(response, items); + selectLabel( + response, + items, + { + success: function(pk) { + var href = `/api/label/stock/${pk}/print/?`; + + items.forEach(function(item) { + href += `items[]=${item}&`; + }); + + window.location.href = href; + } + } + ); } } ); } +function printStockLocationLabels(locations, options={}) { + + if (locations.length == 0) { + showAlertDialog( + '{% trans "Select Stock Locations" %}', + '{% trans "Stock location(s) must be selected before printing labels" %}' + ); + + return; + } + + // Request available labels from the server + inventreeGet( + '{% url "api-stocklocation-label-list" %}', + { + enabled: true, + locations: locations, + }, + { + success: function(response) { + if (response.length == 0) { + showAlertDialog( + '{% trans "No Labels Found" %}', + '{% trans "No labels found which match selected stock location(s)" %}', + ); + + return; + } + + // Select label to print + selectLabel( + response, + locations, + { + success: function(pk) { + // TODO - Print the label! + } + } + ); + } + } + ) +} + + function selectLabel(labels, items, options={}) { /** * Present the user with the available labels, @@ -48,8 +108,6 @@ function selectLabel(labels, items, options={}) { * (via AJAX) from the server. */ - var stock_items = items; - var modal = options.modal || '#modal-form'; var label_list = makeOptionsList( @@ -102,12 +160,8 @@ function selectLabel(labels, items, options={}) { closeModal(modal); - var href = `/api/label/stock/${pk}/print/?`; - - stock_items.forEach(function(item) { - href += `items[]=${item}&`; - }); - - window.location.href = href; + if (options.success) { + options.success(pk); + } }); } \ No newline at end of file