mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
This is 1.0
This commit is contained in:
@@ -7,11 +7,11 @@
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + jsonForm.product_id,
|
||||
function (productDetails)
|
||||
{
|
||||
jsonForm.amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
|
||||
var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
|
||||
|
||||
Grocy.FetchJson('/api/stock/add-product/' + jsonForm.product_id + '/' + jsonForm.amount + '?bestbeforedate=' + $('#best_before_date').val(),
|
||||
Grocy.FetchJson('/api/stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + $('#best_before_date').val(),
|
||||
function (result) {
|
||||
toastr.success('Added ' + jsonForm.amount + ' ' + productDetails.quantity_unit_stock.name + ' of ' + productDetails.product.name + ' to stock');
|
||||
toastr.success('Added ' + amount + ' ' + productDetails.quantity_unit_stock.name + ' of ' + productDetails.product.name + ' to stock');
|
||||
|
||||
$('#amount').val(1);
|
||||
$('#best_before_date').val('');
|
||||
@@ -50,6 +50,12 @@ $('#product_id').on('change', function(e)
|
||||
$('#selected-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || ''));
|
||||
$('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
|
||||
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
||||
$('#new_amount_qu_unit').text(productDetails.quantity_unit_stock.name);
|
||||
|
||||
if (productDetails.product.default_best_before_days.toString() !== '0')
|
||||
{
|
||||
$('#best_before_date').val(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD'));
|
||||
}
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
||||
@@ -78,25 +84,19 @@ $(function()
|
||||
$('.datepicker').trigger('change');
|
||||
|
||||
$('.combobox').combobox({
|
||||
appendId: '_text_input',
|
||||
matcher: function(text)
|
||||
appendId: '_text_input'
|
||||
});
|
||||
|
||||
$('#product_id_text_input').on('change', function(e)
|
||||
{
|
||||
var input = $('#product_id_text_input').val().toString();
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
|
||||
|
||||
if (possibleOptionElement.length > 0)
|
||||
{
|
||||
var input = $('#product_id_text_input').val();
|
||||
var optionElement = $("#product_id option:contains('" + text + "')").first();
|
||||
var additionalSearchdata = optionElement.data('additional-searchdata');
|
||||
|
||||
if (text.contains(input))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (additionalSearchdata !== null && additionalSearchdata.length > 0)
|
||||
{
|
||||
return additionalSearchdata.contains(input);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$('#product_id').val(possibleOptionElement.val());
|
||||
$('#product_id').data('combobox').refresh();
|
||||
$('#product_id').trigger('change');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -120,6 +120,14 @@ $(function()
|
||||
});
|
||||
$('#purchase-form').validator('validate');
|
||||
|
||||
$('#best_before_date').on('focus', function(e)
|
||||
{
|
||||
if ($('#product_id_text_input').val().length === 0)
|
||||
{
|
||||
$('#product_id_text_input').focus();
|
||||
}
|
||||
});
|
||||
|
||||
$('#purchase-form input').keydown(function(event)
|
||||
{
|
||||
if (event.keyCode === 13) //Enter
|
||||
|
Reference in New Issue
Block a user