diff --git a/InvenTree/templates/js/translated/label.js b/InvenTree/templates/js/translated/label.js index 1c843917e6..2e1a477387 100644 --- a/InvenTree/templates/js/translated/label.js +++ b/InvenTree/templates/js/translated/label.js @@ -57,13 +57,20 @@ function printStockItemLabels(items) { response, items, { - success: function(pk) { + success: function(data) { + + var pk = data.label; + var href = `/api/label/stock/${pk}/print/?`; items.forEach(function(item) { href += `items[]=${item}&`; }); + if (data.plugin) { + href += `plugin=${data.plugin}`; + } + window.location.href = href; } } @@ -107,13 +114,20 @@ function printStockLocationLabels(locations) { response, locations, { - success: function(pk) { + success: function(data) { + + var pk = data.label; + var href = `/api/label/location/${pk}/print/?`; locations.forEach(function(location) { href += `locations[]=${location}&`; }); + if (data.plugin) { + href += `plugin=${data.plugin}`; + } + window.location.href = href; } } @@ -162,13 +176,20 @@ function printPartLabels(parts) { response, parts, { - success: function(pk) { + success: function(data) { + + var pk = data.label; + var url = `/api/label/part/${pk}/print/?`; parts.forEach(function(part) { url += `parts[]=${part}&`; }); + if (data.plugin) { + href += `plugin=${data.plugin}`; + } + window.location.href = url; } } @@ -188,18 +209,53 @@ function selectLabel(labels, items, options={}) { * (via AJAX) from the server. */ - // If only a single label template is provided, - // just run with that! + // Array of available plugins for label printing + var plugins = []; - if (labels.length == 1) { - if (options.success) { - options.success(labels[0].pk); + // Request a list of available label printing plugins from the server + inventreeGet( + '{% url "api-plugin-list" %}', + { + + }, + { + async: false, + success: function(response) { + response.forEach(function(plugin) { + if (plugin.mixins && plugin.mixins.labels) { + // This plugin supports label printing + plugins.push(plugin); + } + }); + } } + ); - return; + var plugin_selection = ''; + + + if (plugins.length > 0) { + plugin_selection =` +