Finalize project reorganization

This commit is contained in:
Bernd Bestel
2018-04-14 11:10:38 +02:00
parent 5a1d21ef31
commit 642f95a3f8
47 changed files with 254 additions and 233 deletions

View File

@@ -39,23 +39,8 @@ $('#battery_id').on('change', function(e)
if (batteryId)
{
Grocy.FetchJson('/api/batteries/get-battery-details/' + batteryId,
function(batteryDetails)
{
$('#selected-battery-name').text(batteryDetails.battery.name);
$('#selected-battery-last-charged').text((batteryDetails.last_charged || 'never'));
$('#selected-battery-last-charged-timeago').text($.timeago(batteryDetails.last_charged || ''));
$('#selected-battery-charge-cycles-count').text((batteryDetails.charge_cycles_count || '0'));
$('#tracked_time').focus();
Grocy.EmptyElementWhenMatches('#selected-battery-last-charged-timeago', 'NaN years ago');
},
function(xhr)
{
console.error(xhr);
}
);
Grocy.Components.BatteryCard.Refresh(batteryId);
$('#tracked_time').focus();
}
});

View File

@@ -0,0 +1,20 @@
Grocy.Components.BatteryCard = { };
Grocy.Components.BatteryCard.Refresh = function(batteryId)
{
Grocy.FetchJson('/api/batteries/get-battery-details/' + batteryId,
function(batteryDetails)
{
$('#batterycard-battery-name').text(batteryDetails.battery.name);
$('#batterycard-battery-last-charged').text((batteryDetails.last_charged || 'never'));
$('#batterycard-battery-last-charged-timeago').text($.timeago(batteryDetails.last_charged || ''));
$('#batterycard-battery-charge-cycles-count').text((batteryDetails.charge_cycles_count || '0'));
EmptyElementWhenMatches('#batterycard-battery-last-charged-timeago', 'NaN years ago');
},
function(xhr)
{
console.error(xhr);
}
);
};

View File

@@ -0,0 +1,20 @@
Grocy.Components.HabitCard = { };
Grocy.Components.HabitCard.Refresh = function (habitId)
{
Grocy.FetchJson('/api/habits/get-habit-details/' + habitId,
function(habitDetails)
{
$('#habitcard-habit-name').text(habitDetails.habit.name);
$('#habitcard-habit-last-tracked').text((habitDetails.last_tracked || 'never'));
$('#habitcard-habit-last-tracked-timeago').text($.timeago(habitDetails.last_tracked || ''));
$('#habitcard-habit-tracked-count').text((habitDetails.tracked_count || '0'));
EmptyElementWhenMatches('#habitcard-habit-last-tracked-timeago', 'NaN years ago');
},
function(xhr)
{
console.error(xhr);
}
);
};

View File

@@ -0,0 +1,25 @@
Grocy.Components.ProductCard = { };
Grocy.Components.ProductCard.Refresh = function(productId)
{
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
function(productDetails)
{
$('#productcard-product-name').text(productDetails.product.name);
$('#productcard-product-stock-amount').text(productDetails.stock_amount || '0');
$('#productcard-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
$('#productcard-product-stock-qu-name2').text(productDetails.quantity_unit_stock.name);
$('#productcard-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
$('#productcard-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || ''));
$('#productcard-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
$('#productcard-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
EmptyElementWhenMatches('#productcard-product-last-purchased-timeago', 'NaN years ago');
EmptyElementWhenMatches('#productcard-product-last-used-timeago', 'NaN years ago');
},
function(xhr)
{
console.error(xhr);
}
);
};

View File

@@ -44,24 +44,15 @@ $('#product_id').on('change', function(e)
if (productId)
{
Grocy.Components.ProductCard.Refresh(productId);
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
function (productDetails)
{
$('#selected-product-name').text(productDetails.product.name);
$('#selected-product-stock-amount').text(productDetails.stock_amount || '0');
$('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
$('#selected-product-stock-qu-name2').text(productDetails.quantity_unit_stock.name);
$('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
$('#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 || ''));
$('#amount').attr('max', productDetails.stock_amount);
$('#consume-form').validator('update');
$('#amount_qu_unit').text(productDetails.quantity_unit_stock.name);
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
if ((productDetails.stock_amount || 0) === 0)
{
$('#product_id').val('');

View File

@@ -39,23 +39,8 @@ $('#habit_id').on('change', function(e)
if (habitId)
{
Grocy.FetchJson('/api/habits/get-habit-details/' + habitId,
function(habitDetails)
{
$('#selected-habit-name').text(habitDetails.habit.name);
$('#selected-habit-last-tracked').text((habitDetails.last_tracked || 'never'));
$('#selected-habit-last-tracked-timeago').text($.timeago(habitDetails.last_tracked || ''));
$('#selected-habit-tracked-count').text((habitDetails.tracked_count || '0'));
$('#tracked_time').focus();
Grocy.EmptyElementWhenMatches('#selected-habit-last-tracked-timeago', 'NaN years ago');
},
function(xhr)
{
console.error(xhr);
}
);
Grocy.Components.HabitCard.Refresh(habitId);
$('#tracked_time').focus();
}
});

View File

@@ -10,7 +10,7 @@
Grocy.FetchJson('/api/stock/inventory-product/' + jsonForm.product_id + '/' + jsonForm.new_amount + '?bestbeforedate=' + $('#best_before_date').val(),
function(result)
{
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
{
var existingBarcodes = productDetails.product.barcode || '';
@@ -33,7 +33,6 @@
}
toastr.success('Stock amount of ' + productDetails.product.name + ' is now ' + jsonForm.new_amount.toString() + ' ' + productDetails.quantity_unit_stock.name);
Grocy.Wait(1000);
if (addBarcode !== undefined)
{
@@ -70,24 +69,15 @@ $('#product_id').on('change', function(e)
if (productId)
{
Grocy.Components.ProductCard.Refresh(productId);
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
function(productDetails)
{
$('#selected-product-name').text(productDetails.product.name);
$('#selected-product-stock-amount').text(productDetails.stock_amount || '0');
$('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
$('#selected-product-purchase-qu-name').text(productDetails.quantity_unit_purchase.name);
$('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
$('#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').attr('not-equal', productDetails.stock_amount);
$('#new_amount_qu_unit').text(productDetails.quantity_unit_stock.name);
$('#new_amount').focus();
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
},
function(xhr)
{
@@ -121,7 +111,7 @@ $(function()
var input = $('#product_id_text_input').val().toString();
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
if (Grocy.GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
if (GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
{
$('#product_id').val(possibleOptionElement.val());
$('#product_id').data('combobox').refresh();
@@ -130,7 +120,7 @@ $(function()
else
{
var optionElement = $("#product_id option:contains('" + input + "')").first();
if (input.length > 0 && optionElement.length === 0 && Grocy.GetUriParam('addbarcodetoselection') === undefined )
if (input.length > 0 && optionElement.length === 0 && GetUriParam('addbarcodetoselection') === undefined )
{
bootbox.dialog({
message: '<strong>' + input + '</strong> could not be resolved to a product, how do you want to proceed?',
@@ -246,7 +236,7 @@ $(function()
}
});
var prefillProduct = Grocy.GetUriParam('createdproduct');
var prefillProduct = GetUriParam('createdproduct');
if (prefillProduct !== undefined)
{
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first();
@@ -264,7 +254,7 @@ $(function()
}
}
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
{
$('#addbarcodetoselection').text(addBarcode);

View File

@@ -4,7 +4,7 @@
$('#username').focus();
if (Grocy.GetUriParam('invalid') === 'true')
if (GetUriParam('invalid') === 'true')
{
$('#login-error').text('Invalid credentials, please try again.');
$('#login-error').show();

View File

@@ -3,7 +3,7 @@
e.preventDefault();
var redirectDestination = '/products';
var returnTo = Grocy.GetUriParam('returnto');
var returnTo = GetUriParam('returnto');
if (returnTo !== undefined)
{
redirectDestination = returnTo + '?createdproduct=' + encodeURIComponent($('#name').val());
@@ -69,14 +69,14 @@ $(function()
$('#product-form').validator();
$('#product-form').validator('validate');
var prefillName = Grocy.GetUriParam('prefillname');
var prefillName = GetUriParam('prefillname');
if (prefillName !== undefined)
{
$('#name').val(prefillName);
$('#name').focus();
}
var prefillBarcode = Grocy.GetUriParam('prefillbarcode');
var prefillBarcode = GetUriParam('prefillbarcode');
if (prefillBarcode !== undefined)
{
$('#barcode-taginput').tagsManager('pushTag', prefillBarcode);

View File

@@ -12,7 +12,7 @@
Grocy.FetchJson('/api/stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + $('#best_before_date').val(),
function(result)
{
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
{
var existingBarcodes = productDetails.product.barcode || '';
@@ -35,7 +35,6 @@
}
toastr.success('Added ' + amount + ' ' + productDetails.quantity_unit_stock.name + ' of ' + productDetails.product.name + ' to stock');
Grocy.Wait(1000);
if (addBarcode !== undefined)
{
@@ -71,17 +70,11 @@ $('#product_id').on('change', function(e)
if (productId)
{
Grocy.Components.ProductCard.Refresh(productId);
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
function(productDetails)
{
$('#selected-product-name').text(productDetails.product.name);
$('#selected-product-stock-amount').text(productDetails.stock_amount || '0');
$('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
$('#selected-product-purchase-qu-name').text(productDetails.quantity_unit_purchase.name);
$('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
$('#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 || ''));
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
if (productDetails.product.default_best_before_days.toString() !== '0')
@@ -93,10 +86,7 @@ $('#product_id').on('change', function(e)
else
{
$('#best_before_date').focus();
}
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
}
},
function(xhr)
{
@@ -130,7 +120,7 @@ $(function()
var input = $('#product_id_text_input').val().toString();
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
if (Grocy.GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
if (GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
{
$('#product_id').val(possibleOptionElement.val());
$('#product_id').data('combobox').refresh();
@@ -139,7 +129,7 @@ $(function()
else
{
var optionElement = $("#product_id option:contains('" + input + "')").first();
if (input.length > 0 && optionElement.length === 0 && Grocy.GetUriParam('addbarcodetoselection') === undefined )
if (input.length > 0 && optionElement.length === 0 && GetUriParam('addbarcodetoselection') === undefined )
{
bootbox.dialog({
message: '<strong>' + input + '</strong> could not be resolved to a product, how do you want to proceed?',
@@ -256,7 +246,7 @@ $(function()
}
});
var prefillProduct = Grocy.GetUriParam('createdproduct');
var prefillProduct = GetUriParam('createdproduct');
if (prefillProduct !== undefined)
{
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first();
@@ -274,7 +264,7 @@ $(function()
}
}
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
{
$('#addbarcodetoselection').text(addBarcode);
@@ -282,7 +272,7 @@ $(function()
$('#barcode-lookup-disabled-hint').removeClass('hide');
}
Grocy.EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago');
EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago');
});
$('#best_before_date-datepicker-button').on('click', function(e)
@@ -314,7 +304,7 @@ $('#best_before_date').on('change', function(e)
}
$('#best-before-timeago').text($.timeago($('#best_before_date').val()));
Grocy.EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago');
EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago');
});
$('#best_before_date').on('keydown', function(e)

View File

@@ -49,8 +49,8 @@ $('#product_id').on('change', function(e)
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
if ($('#product_id').hasClass('suppress-next-custom-validate-event'))
{