Implemented "Scan mode"

This commit is contained in:
Bernd Bestel
2020-01-26 15:35:01 +01:00
parent 7a048136c6
commit c7bcb9984a
16 changed files with 190 additions and 22 deletions

View File

@@ -38,6 +38,11 @@
Grocy.Api.Post(apiUrl, jsonData,
function(result)
{
if (BoolVal(Grocy.UserSettings.scan_mode_consume_enabled))
{
Grocy.UISound.Success();
}
bookingResponse = result;
var addBarcode = GetUriParam('addbarcodetoselection');
@@ -246,6 +251,11 @@ $("#location_id").on('change', function(e)
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{
if (BoolVal(Grocy.UserSettings.scan_mode_consume_enabled))
{
Grocy.UISound.BarcodeScannerBeep();
}
$("#specific_stock_entry").find("option").remove().end().append("<option></option>");
if ($("#use_specific_stock_entry").is(":checked"))
{
@@ -265,13 +275,14 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
$('#amount_qu_unit').text(productDetails.quantity_unit_stock.name);
$("#location_id").find("option").remove().end().append("<option></option>");
Grocy.Api.Get("stock/products/" + productId + '/locations',
Grocy.Api.Get("stock/products/" + productId + '/locations',
function(stockLocations)
{
var setDefault = 0;
stockLocations.forEach(stockLocation =>
{
if (productDetails.location.id == stockLocation.location_id) {
if (productDetails.location.id == stockLocation.location_id)
{
$("#location_id").append($("<option>", {
value: stockLocation.location_id,
text: stockLocation.location_name + " (" + __t("Default location") + ")"
@@ -294,6 +305,21 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
$("#location_id").trigger('change');
}
});
if (BoolVal(Grocy.UserSettings.scan_mode_consume_enabled))
{
$("#amount").val(1);
Grocy.FrontendHelpers.ValidateForm("consume-form");
if (document.getElementById("consume-form").checkValidity() === true)
{
$('#save-consume-button').click();
}
else
{
toastr.warning(__t("Scan mode is on but not all required fields could be populated automatically"));
Grocy.UISound.Error();
}
}
},
function(xhr)
{
@@ -495,3 +521,18 @@ if (GetUriParam("embedded") !== undefined)
$("#use_specific_stock_entry").trigger('change');
}
}
// Default input field
Grocy.Components.ProductPicker.GetInputElement().focus();
// Can only be set via JS however...
$("#scan-mode").addClass("user-setting-control");
$("#scan-mode").attr("data-setting-key", "scan_mode_consume_enabled");
$(document).on("change", "#scan-mode", function(e)
{
if ($(this).prop("checked"))
{
Grocy.UISound.AskForPermission();
}
});

View File

@@ -42,6 +42,11 @@
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/add', jsonData,
function(result)
{
if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled))
{
Grocy.UISound.Success();
}
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
{
@@ -122,6 +127,11 @@ if (Grocy.Components.ProductPicker !== undefined)
{
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{
if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled))
{
Grocy.UISound.BarcodeScannerBeep();
}
var productId = $(e.target).val();
if (productId)
@@ -129,7 +139,7 @@ if (Grocy.Components.ProductPicker !== undefined)
Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/products/' + productId,
function (productDetails)
function(productDetails)
{
$('#price').val(productDetails.last_price);
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
@@ -205,6 +215,21 @@ if (Grocy.Components.ProductPicker !== undefined)
$('#amount').focus();
}
}
if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled))
{
$("#amount").val(1);
Grocy.FrontendHelpers.ValidateForm("purchase-form");
if (document.getElementById("purchase-form").checkValidity() === true)
{
$('#save-purchase-button').click();
}
else
{
toastr.warning(__t("Scan mode is on but not all required fields could be populated automatically"));
Grocy.UISound.Error();
}
}
},
function(xhr)
{
@@ -336,3 +361,15 @@ function UndoStockTransaction(transactionId)
}
);
};
// Can only be set via JS however...
$("#scan-mode").addClass("user-setting-control");
$("#scan-mode").attr("data-setting-key", "scan_mode_purchase_enabled");
$(document).on("change", "#scan-mode", function(e)
{
if ($(this).prop("checked"))
{
Grocy.UISound.AskForPermission();
}
});

View File

@@ -440,3 +440,6 @@ if (GetUriParam("embedded") !== undefined)
$("#use_specific_stock_entry").trigger('change');
}
}
// Default input field
Grocy.Components.ProductPicker.GetInputElement().focus();