2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Allow offloading of label printing to the configured plugin

This commit is contained in:
Oliver
2022-03-24 14:57:01 +11:00
parent f1f07a1977
commit 6c25a5805d
4 changed files with 111 additions and 28 deletions

View File

@ -14,11 +14,41 @@
*/
/* exported
printLabels,
printPartLabels,
printStockItemLabels,
printStockLocationLabels,
*/
/*
* Perform the "print" action.
*/
function printLabels(url, plugin=null) {
if (plugin) {
// If a plugin is provided, do not redirect the browser.
// Instead, perform an API request and display a message
url = url + `plugin=${plugin}`;
inventreeGet(url, {}, {
success: function(response) {
showMessage(
'{% trans "Labels sent to printer" %}',
{
style: 'success',
}
);
}
});
} else {
window.location.href = url;
}
}
function printStockItemLabels(items) {
/**
* Print stock item labels for the given stock items
@ -67,11 +97,7 @@ function printStockItemLabels(items) {
href += `items[]=${item}&`;
});
if (data.plugin) {
href += `plugin=${data.plugin}`;
}
window.location.href = href;
printLabels(href, data.plugin);
}
}
);
@ -80,6 +106,7 @@ function printStockItemLabels(items) {
);
}
function printStockLocationLabels(locations) {
if (locations.length == 0) {
@ -124,11 +151,7 @@ function printStockLocationLabels(locations) {
href += `locations[]=${location}&`;
});
if (data.plugin) {
href += `plugin=${data.plugin}`;
}
window.location.href = href;
printLabels(href, data.plugin);
}
}
);
@ -186,11 +209,7 @@ function printPartLabels(parts) {
url += `parts[]=${part}&`;
});
if (data.plugin) {
href += `plugin=${data.plugin}`;
}
window.location.href = url;
printLabels(href, data.plugin);
}
}
);
@ -234,7 +253,6 @@ function selectLabel(labels, items, options={}) {
var plugin_selection = '';
if (plugins.length > 0) {
plugin_selection =`
<div class='form-group'>