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,13 +10,26 @@
{
jsonForm.amount = jsonForm.amount * product.qu_factor_purchase_to_stock;
Grocy.PostJson('/api/add-object/stock', jsonForm,
function(result)
Grocy.FetchJson('/api/helper/uniqid',
function (uniqidResponse)
{
$('#product_id').val(null);
$('#amount').val(1);
$('#product_id').focus();
$('#purchase-form').validator('validate');
jsonForm.amount = jsonForm.amount * product.qu_factor_purchase_to_stock;
jsonForm.stock_id = uniqidResponse.uniqid;
Grocy.PostJson('/api/add-object/stock', jsonForm,
function(result)
{
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#amount').val(1);
$('#purchase-form').validator('validate');
},
function(xhr)
{
console.error(xhr);
}
);
},
function(xhr)
{
@@ -35,21 +48,29 @@ $('#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-purchase-qu-name').text(productStatistics.quantity_unit_purchase.name);
$('#selected-product-last-purchased').text(productStatistics.last_purchased || 'never');
$('#selected-product-last-used').text(productStatistics.last_used || 'never');
},
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-purchase-qu-name').text(productStatistics.quantity_unit_purchase.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 || ''));
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()
@@ -66,10 +87,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');
$('.combobox').combobox({ appendId: '_text_input' });
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#purchase-form').validator();
$('#purchase-form').validator('validate');
});