General improvements

This commit is contained in:
Bernd Bestel
2017-04-16 23:11:03 +02:00
parent b7852d78d0
commit bd29f5da25
30 changed files with 473 additions and 293 deletions

View File

@@ -10,12 +10,13 @@
spoiled = 1;
}
Grocy.FetchJson('/api/consume-product/' + jsonForm.product_id + '/' + jsonForm.amount + '?spoiled=' + spoiled,
Grocy.FetchJson('/api/stock/consume-product/' + jsonForm.product_id + '/' + jsonForm.amount + '?spoiled=' + spoiled,
function(result)
{
$('#product_id').val(null);
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#amount').val(1);
$('#product_name').focus();
$('#consumption-form').validator('validate');
},
function(xhr)
@@ -29,22 +30,30 @@ $('#product_id').on('change', function(e)
{
var productId = $(e.target).val();
Grocy.FetchJson('/api/get-product-statistics/' + productId,
function(productStatistics)
{
$('#selected-product-name').text(productStatistics.product.name);
$('#selected-product-stock-amount').text(productStatistics.stock_amount || '0');
$('#selected-product-stock-qu-name').text(productStatistics.quantity_unit_stock.name);
$('#selected-product-stock-qu-name2').text(productStatistics.quantity_unit_stock.name);
$('#selected-product-last-purchased').text(productStatistics.last_purchased || 'never');
$('#selected-product-last-used').text(productStatistics.last_used || 'never');
$('#amount').attr('max', productStatistics.stock_amount);
},
function(xhr)
{
console.error(xhr);
}
);
if (productId)
{
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
function(productStatistics)
{
$('#selected-product-name').text(productStatistics.product.name);
$('#selected-product-stock-amount').text(productStatistics.stock_amount || '0');
$('#selected-product-stock-qu-name').text(productStatistics.quantity_unit_stock.name);
$('#selected-product-stock-qu-name2').text(productStatistics.quantity_unit_stock.name);
$('#selected-product-last-purchased').text((productStatistics.last_purchased || 'never').substring(0, 10));
$('#selected-product-last-purchased-timeago').text($.timeago(productStatistics.last_purchased || ''));
$('#selected-product-last-used').text((productStatistics.last_used || 'never').substring(0, 10));
$('#selected-product-last-used-timeago').text($.timeago(productStatistics.last_used || ''));
$('#amount').attr('max', productStatistics.stock_amount);
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
},
function(xhr)
{
console.error(xhr);
}
);
}
});
$(function()
@@ -61,10 +70,11 @@ $(function()
$('.datepicker').val(moment().format('YYYY-MM-DD'));
$('.datepicker').trigger('change');
$('.combobox').combobox();
$('#product_id').focus();
$('#product_id').val(null);
$('#product_name').trigger('change');
$('#purchase-form').validator();
$('#purchase-form').validator('validate');
$('.combobox').combobox({ appendId: '_text_input' });
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#consumption-form').validator();
$('#consumption-form').validator('validate');
});