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

Download PDF for labels

This commit is contained in:
Oliver Walters
2021-01-09 21:50:42 +11:00
parent bdc7367e29
commit e133fff03e
6 changed files with 96 additions and 34 deletions

View File

@ -1,6 +1,45 @@
{% load i18n %}
function selectLabel(labels, options={}) {
function printStockItemLabels(items, options={}) {
/**
* Print stock item labels for the given stock items
*/
if (items.length == 0) {
showAlertDialog(
'{% trans "Select Stock Items" %}',
'{% trans "Stock items must be selected before printing labels" %}'
);
return;
}
// Request available labels from the server
inventreeGet(
'{% url "api-stockitem-label-list" %}',
{
enabled: true,
items: items,
},
{
success: function(response) {
if (response.length == 0) {
showAlertDialog(
'{% trans "No Labels Found" %}',
'{% trans "No labels found which match selected stock item(s)" %}',
);
return;
}
// Select label to print
selectLabel(response, items);
}
}
);
}
function selectLabel(labels, items, options={}) {
/**
* Present the user with the available labels,
* and allow them to select which label to print.
@ -9,6 +48,8 @@ function selectLabel(labels, options={}) {
* (via AJAX) from the server.
*/
var stock_items = items;
var modal = options.modal || '#modal-form';
var label_list = makeOptionsList(
@ -29,6 +70,7 @@ function selectLabel(labels, options={}) {
// Construct form
var html = `
<form method='post' action='' class='js-modal-form' enctype='multipart/form-data'>
<div class='form-group'>
<label class='control-label requiredField' for='id_label'>
@ -49,4 +91,23 @@ function selectLabel(labels, options={}) {
modalEnable(modal, true);
modalSetTitle(modal, '{% trans "Select Label Template" %}');
modalSetContent(modal, html);
attachSelect(modal);
modalSubmit(modal, function() {
var label = $(modal).find('#id_label');
var pk = label.val();
closeModal(modal);
var href = `/api/label/stock/${pk}/print/?`;
stock_items.forEach(function(item) {
href += `items[]=${item}&`;
});
window.location.href = href;
});
}

View File

@ -166,6 +166,15 @@ function setFieldValue(fieldName, value, options={}) {
field.val(value);
}
function getFieldValue(fieldName, options={}) {
var modal = options.modal || '#modal-form';
var field = getFieldByName(modal, fieldName);
return field.val();
}
function partialMatcher(params, data) {
/* Replacement function for the 'matcher' parameter for a select2 dropdown.

View File

@ -654,28 +654,7 @@ function loadStockTable(table, options) {
items.push(item.pk);
});
// Request available labels from the server
inventreeGet(
'{% url "api-stockitem-label-list" %}',
{
enabled: true,
items: items,
},
{
success: function(response) {
if (response.length == 0) {
showAlertDialog(
'{% trans "No Labels Found" %}',
'{% trans "No labels found which match selected stock item(s)" %}',
);
return;
}
var label = selectLabel(response);
}
}
);
printStockItemLabels(items);
});
$('#multi-item-stocktake').click(function() {