@@ -72,9 +73,35 @@ function makeBarcodeInput(placeholderText='') {
}
+function showBarcodeError(modal, message, style='danger') {
+
+ var html = `
`;
+
+ html += message;
+
+ html += "
";
+
+ $(modal + ' #barcode-error-message').html(html);
+}
+
+function clearBarcodeError(modal, message) {
+
+ $(modal + ' #barcode-error-message').html('');
+}
+
+
function getBarcodeData(modal) {
- return $(modal + ' #barcode').val();
+ modal = modal || '#modal-form';
+
+ var el = $(modal + ' #barcode');
+
+ var barcode = el.val();
+
+ el.val('');
+ el.focus();
+
+ return barcode;
}
@@ -164,7 +191,26 @@ function barcodeScanDialog() {
{
method: 'POST',
success: function(response, status) {
+
console.log(response);
+
+ if (status == 'success') {
+
+ if ('success' in response) {
+ if ('url' in response) {
+ // Redirect to the URL!
+ $(modal).modal('hide');
+ window.location.href = response.url;
+ }
+
+ } else if ('error' in response) {
+ showBarcodeError(modal, response.error, 'warning');
+ } else {
+ showBarcodeError(modal, "Unknown response from server", 'warning');
+ }
+ } else {
+ showBarcodeError(modal, `Invalid server response.
Status code: '${status}'`);
+ }
},
},
);
diff --git a/InvenTree/barcode/api.py b/InvenTree/barcode/api.py
index 52d8a01f85..cc340f96f6 100644
--- a/InvenTree/barcode/api.py
+++ b/InvenTree/barcode/api.py
@@ -2,6 +2,7 @@
import hashlib
+from django.urls import reverse
from django.conf.urls import url
from django.utils.translation import ugettext as _
@@ -86,6 +87,7 @@ class BarcodeScan(APIView):
if item is not None:
response['stockitem'] = plugin.renderStockItem(item)
+ response['url'] = reverse('stock-item-detail', kwargs={'pk': item.id})
match_found = True
# Try to associate with a stock location
@@ -93,6 +95,7 @@ class BarcodeScan(APIView):
if loc is not None:
response['stocklocation'] = plugin.renderStockLocation(loc)
+ response['url'] = reverse('location-detail', kwargs={'pk': loc.id})
match_found = True
# Try to associate with a part
@@ -100,6 +103,7 @@ class BarcodeScan(APIView):
if part is not None:
response['part'] = plugin.renderPart(part)
+ response['url'] = reverse('part-detail', kwargs={'pk': part.id})
match_found = True
response['hash'] = plugin.hash()
@@ -118,6 +122,7 @@ class BarcodeScan(APIView):
item = StockItem.objects.get(uid=hash)
serializer = StockItemSerializer(item, part_detail=True, location_detail=True, supplier_part_detail=True)
response['stockitem'] = serializer.data
+ response['url'] = reverse('stock-item-detail', kwargs={'pk': item.id})
match_found = True
except StockItem.DoesNotExist:
pass
diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html
index 86420201b3..f6dcf82f88 100644
--- a/InvenTree/stock/templates/stock/item_base.html
+++ b/InvenTree/stock/templates/stock/item_base.html
@@ -390,10 +390,11 @@ $('#stock-add').click(function() {
$("#stock-delete").click(function () {
launchModalForm(
- "{% url 'stock-item-delete' item.id %}",
- {
- redirect: "{% url 'part-stock' item.part.id %}"
- });
+ "{% url 'stock-item-delete' item.id %}",
+ {
+ redirect: "{% url 'part-stock' item.part.id %}"
+ }
+ );
});
{% endblock %}