mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
If printing plugins are available, let the user select them when printing
This commit is contained in:
parent
86b5655c5f
commit
e62b6063bb
@ -57,13 +57,20 @@ function printStockItemLabels(items) {
|
|||||||
response,
|
response,
|
||||||
items,
|
items,
|
||||||
{
|
{
|
||||||
success: function(pk) {
|
success: function(data) {
|
||||||
|
|
||||||
|
var pk = data.label;
|
||||||
|
|
||||||
var href = `/api/label/stock/${pk}/print/?`;
|
var href = `/api/label/stock/${pk}/print/?`;
|
||||||
|
|
||||||
items.forEach(function(item) {
|
items.forEach(function(item) {
|
||||||
href += `items[]=${item}&`;
|
href += `items[]=${item}&`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (data.plugin) {
|
||||||
|
href += `plugin=${data.plugin}`;
|
||||||
|
}
|
||||||
|
|
||||||
window.location.href = href;
|
window.location.href = href;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,13 +114,20 @@ function printStockLocationLabels(locations) {
|
|||||||
response,
|
response,
|
||||||
locations,
|
locations,
|
||||||
{
|
{
|
||||||
success: function(pk) {
|
success: function(data) {
|
||||||
|
|
||||||
|
var pk = data.label;
|
||||||
|
|
||||||
var href = `/api/label/location/${pk}/print/?`;
|
var href = `/api/label/location/${pk}/print/?`;
|
||||||
|
|
||||||
locations.forEach(function(location) {
|
locations.forEach(function(location) {
|
||||||
href += `locations[]=${location}&`;
|
href += `locations[]=${location}&`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (data.plugin) {
|
||||||
|
href += `plugin=${data.plugin}`;
|
||||||
|
}
|
||||||
|
|
||||||
window.location.href = href;
|
window.location.href = href;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,13 +176,20 @@ function printPartLabels(parts) {
|
|||||||
response,
|
response,
|
||||||
parts,
|
parts,
|
||||||
{
|
{
|
||||||
success: function(pk) {
|
success: function(data) {
|
||||||
|
|
||||||
|
var pk = data.label;
|
||||||
|
|
||||||
var url = `/api/label/part/${pk}/print/?`;
|
var url = `/api/label/part/${pk}/print/?`;
|
||||||
|
|
||||||
parts.forEach(function(part) {
|
parts.forEach(function(part) {
|
||||||
url += `parts[]=${part}&`;
|
url += `parts[]=${part}&`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (data.plugin) {
|
||||||
|
href += `plugin=${data.plugin}`;
|
||||||
|
}
|
||||||
|
|
||||||
window.location.href = url;
|
window.location.href = url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,17 +209,52 @@ function selectLabel(labels, items, options={}) {
|
|||||||
* (via AJAX) from the server.
|
* (via AJAX) from the server.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// If only a single label template is provided,
|
// Array of available plugins for label printing
|
||||||
// just run with that!
|
var plugins = [];
|
||||||
|
|
||||||
if (labels.length == 1) {
|
// Request a list of available label printing plugins from the server
|
||||||
if (options.success) {
|
inventreeGet(
|
||||||
options.success(labels[0].pk);
|
'{% 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 =`
|
||||||
|
<div class='form-group'>
|
||||||
|
<label class='control-label requiredField' for='id_plugin'>
|
||||||
|
{% trans "Select Printer" %}
|
||||||
|
</label>
|
||||||
|
<div class='controls'>
|
||||||
|
<select id='id_plugin' class='select form-control' name='plugin'>
|
||||||
|
<option value='' title='{% trans "Export to PDF" %}'>{% trans "Export to PDF" %}</option>
|
||||||
|
`;
|
||||||
|
|
||||||
|
plugins.forEach(function(plugin) {
|
||||||
|
plugin_selection += `<option value='${plugin.key}' title='${plugin.meta.human_name}'>${plugin.meta.description} - <small>${plugin.meta.human_name}</small></option>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
plugin_selection += `
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
var modal = options.modal || '#modal-form';
|
var modal = options.modal || '#modal-form';
|
||||||
|
|
||||||
@ -233,14 +289,15 @@ function selectLabel(labels, items, options={}) {
|
|||||||
<form method='post' action='' class='js-modal-form' enctype='multipart/form-data'>
|
<form method='post' action='' class='js-modal-form' enctype='multipart/form-data'>
|
||||||
<div class='form-group'>
|
<div class='form-group'>
|
||||||
<label class='control-label requiredField' for='id_label'>
|
<label class='control-label requiredField' for='id_label'>
|
||||||
{% trans "Select Label" %}
|
{% trans "Select Label Template" %}
|
||||||
</label>
|
</label>
|
||||||
<div class='controls'>
|
<div class='controls'>
|
||||||
<select id='id_label' class='select form-control name='label'>
|
<select id='id_label' class='select form-control' name='label'>
|
||||||
${label_list}
|
${label_list}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
${plugin_selection}
|
||||||
</form>`;
|
</form>`;
|
||||||
|
|
||||||
openModal({
|
openModal({
|
||||||
@ -255,14 +312,17 @@ function selectLabel(labels, items, options={}) {
|
|||||||
|
|
||||||
modalSubmit(modal, function() {
|
modalSubmit(modal, function() {
|
||||||
|
|
||||||
var label = $(modal).find('#id_label');
|
var label = $(modal).find('#id_label').val();
|
||||||
|
var plugin = $(modal).find('#id_plugin').val();
|
||||||
var pk = label.val();
|
|
||||||
|
|
||||||
closeModal(modal);
|
closeModal(modal);
|
||||||
|
|
||||||
if (options.success) {
|
if (options.success) {
|
||||||
options.success(pk);
|
options.success({
|
||||||
|
// Return the selected label template and plugin
|
||||||
|
label: label,
|
||||||
|
plugin: plugin,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user