mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 12:26:15 +02:00
Fix scan mode
This commit is contained in:
parent
32daf9f481
commit
cfff3e568f
24
js/grocy.js
24
js/grocy.js
|
|
@ -503,29 +503,6 @@ class GrocyClass
|
|||
);
|
||||
}
|
||||
|
||||
ScanModeSubmit(singleUnit = true)
|
||||
{
|
||||
if (BoolVal(this.UserSettings.scan_mode_purchase_enabled))
|
||||
{
|
||||
if (singleUnit)
|
||||
{
|
||||
$("#display_amount").val(1);
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
}
|
||||
|
||||
this.FrontendHelpers.ValidateForm("purchase-form");
|
||||
if (document.getElementById("purchase-form").checkValidity() === true)
|
||||
{
|
||||
$('#save-purchase-button').click();
|
||||
}
|
||||
else
|
||||
{
|
||||
toastr.warning(this.translate("Scan mode is on but not all required fields could be populated automatically"));
|
||||
this.UISound.Error();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GetUriParam(key)
|
||||
{
|
||||
var currentUri = window.location.search.substring(1);
|
||||
|
|
@ -540,6 +517,7 @@ class GrocyClass
|
|||
return currentParam[1] === undefined ? true : decodeURIComponent(currentParam[1]);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
UpdateUriParam(key, value)
|
||||
|
|
|
|||
|
|
@ -160,8 +160,14 @@ class GrocyFrontendHelpers
|
|||
|
||||
ValidateForm(formId)
|
||||
{
|
||||
var form = null;
|
||||
var ret = false;
|
||||
|
||||
if (formId instanceof $)
|
||||
form = formId;
|
||||
else
|
||||
form = this.$scope("#" + formId);
|
||||
|
||||
var form = this.$scope("#" + formId);
|
||||
if (form.length == 0)
|
||||
{
|
||||
return;
|
||||
|
|
@ -170,6 +176,7 @@ class GrocyFrontendHelpers
|
|||
if (form[0].checkValidity() === true)
|
||||
{
|
||||
form.find(':submit').removeClass('disabled');
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -177,6 +184,7 @@ class GrocyFrontendHelpers
|
|||
}
|
||||
|
||||
form.addClass('was-validated');
|
||||
return ret;
|
||||
}
|
||||
|
||||
BeginUiBusy(formId = null)
|
||||
|
|
@ -471,6 +479,33 @@ class GrocyFrontendHelpers
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
ScanModeSubmit(singleUnit = true)
|
||||
{
|
||||
if (singleUnit)
|
||||
{
|
||||
this.$scope("#display_amount").val(1);
|
||||
this.$scope(".input-group-productamountpicker").trigger("change");
|
||||
}
|
||||
|
||||
var form = this.$scope('form[data-scanmode="enabled"]');
|
||||
|
||||
if (form.length == 0)
|
||||
{
|
||||
console.warn("ScanModeSubmit was triggered but no form[data-scanmode=\"enabled\"] was found in scope " + this.scopeSelector);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.ValidateForm(form) === true)
|
||||
{
|
||||
form.find('button[data-scanmode="submit"]').click();
|
||||
}
|
||||
else
|
||||
{
|
||||
toastr.warning(this.translate("Scan mode is on but not all required fields could be populated automatically"));
|
||||
this.UISound.Error();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { GrocyFrontendHelpers };
|
||||
|
|
@ -300,9 +300,11 @@ function consumeView(Grocy, scope = null)
|
|||
}
|
||||
);
|
||||
|
||||
if ($scope('#product_id').attr("barcode") == "null")
|
||||
if (BoolVal(Grocy.UserSettings.scan_mode_consume_enabled) &&
|
||||
$scope('#product_id').attr("barcode") == "null")
|
||||
{
|
||||
Grocy.ScanModeSubmit();
|
||||
|
||||
Grocy.FrontendHelpers.ScanModeSubmit();
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
|
|
@ -409,7 +411,8 @@ function consumeView(Grocy, scope = null)
|
|||
$scope(".input-group-productamountpicker").trigger("change");
|
||||
Grocy.FrontendHelpers.ValidateForm('consume-form');
|
||||
RefreshLocaleNumberInput();
|
||||
Grocy.ScanModeSubmit(false);
|
||||
if (BoolVal(Grocy.UserSettings.scan_mode_consume_enabled))
|
||||
Grocy.FrontendHelpers.ScanModeSubmit(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ function productformView(Grocy, scope = null)
|
|||
|
||||
// preload some views.
|
||||
Grocy.PreloadView("productgroupform");
|
||||
Grocy.PreloadView("productbarcodeform");
|
||||
|
||||
var shoppinglocationpicker = Grocy.Use("shoppinglocationpicker");
|
||||
var userfields = Grocy.Use("userfieldsform");
|
||||
|
|
|
|||
|
|
@ -398,8 +398,8 @@ function purchaseView(Grocy, scope = null)
|
|||
RefreshLocaleNumberInput();
|
||||
}
|
||||
}
|
||||
|
||||
Grocy.ScanModeSubmit(false);
|
||||
if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled))
|
||||
Grocy.FrontendHelpers.ScanModeSubmit(false);
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
|
|
@ -410,7 +410,8 @@ function purchaseView(Grocy, scope = null)
|
|||
else
|
||||
{
|
||||
$scope("#purchase-form").removeAttr("data-used-barcode");
|
||||
Grocy.ScanModeSubmit();
|
||||
if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled))
|
||||
Grocy.FrontendHelpers.ScanModeSubmit();
|
||||
}
|
||||
|
||||
$scope('#display_amount').trigger("keyup");
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ $classes = $embedded ? '' : 'col-md-6 col-xl-4';
|
|||
|
||||
<hr class="my-2">
|
||||
|
||||
<form id="consume-form"
|
||||
<form id="consume-form" data-scanmode="enabled"
|
||||
novalidate>
|
||||
|
||||
@include('components.productpicker', array(
|
||||
|
|
@ -138,7 +138,7 @@ $classes = $embedded ? '' : 'col-md-6 col-xl-4';
|
|||
))
|
||||
@endif
|
||||
|
||||
<button id="save-consume-button"
|
||||
<button id="save-consume-button" data-scanmode="submit"
|
||||
class="btn btn-success">{{ $__t('OK') }}</button>
|
||||
|
||||
@if(GROCY_FEATURE_FLAG_STOCK_PRODUCT_OPENED_TRACKING)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ $classes = $embedded ? '' : 'col-md-6 col-xl-4';
|
|||
|
||||
<hr class="my-2">
|
||||
|
||||
<form id="purchase-form"
|
||||
<form id="purchase-form" data-scanmode="enabled"
|
||||
novalidate>
|
||||
|
||||
@include('components.productpicker', array(
|
||||
|
|
@ -165,7 +165,7 @@ $classes = $embedded ? '' : 'col-md-6 col-xl-4';
|
|||
</div>
|
||||
@endif
|
||||
|
||||
<button id="save-purchase-button"
|
||||
<button id="save-purchase-button" data-scanmode="submit"
|
||||
class="btn btn-success d-block">{{ $__t('OK') }}</button>
|
||||
|
||||
</form>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user