Fixed all (or most of) the broken stuff after the dependency upgrade party

This commit is contained in:
Bernd Bestel
2018-07-11 19:43:05 +02:00
parent 71701804ea
commit 778191fd11
51 changed files with 553 additions and 498 deletions

View File

@@ -30,6 +30,26 @@
}
});
$('#battery-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('battery-form');
});
$('#battery-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('battery-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-battery-button').click();
}
}
});
$('#name').focus();
$('#battery-form').validator();
$('#battery-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('battery-form');

View File

@@ -7,18 +7,18 @@
Grocy.Api.Get('batteries/get-battery-details/' + jsonForm.battery_id,
function (batteryDetails)
{
Grocy.Api.Get('batteries/track-charge-cycle/' + jsonForm.battery_id + '?tracked_time=' + $('#tracked_time').val(),
Grocy.Api.Get('batteries/track-charge-cycle/' + jsonForm.battery_id + '?tracked_time=' + $('#tracked_time').find('input').val(),
function(result)
{
toastr.success(L('Tracked charge cylce of battery #1 on #2', batteryDetails.battery.name, $('#tracked_time').val()));
toastr.success(L('Tracked charge cylce of battery #1 on #2', batteryDetails.battery.name, $('#tracked_time').find('input').val()));
$('#battery_id').val('');
$('#battery_id_text_input').focus();
$('#battery_id_text_input').val('');
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#tracked_time').trigger('change');
$('#tracked_time').find('input').val(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#tracked_time').find('input').trigger('change');
$('#battery_id_text_input').trigger('change');
$('#batterytracking-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
},
function(xhr)
{
@@ -40,26 +40,7 @@ $('#battery_id').on('change', function(e)
if (batteryId)
{
Grocy.Components.BatteryCard.Refresh(batteryId);
$('#tracked_time').focus();
}
});
$('.datetimepicker').datetimepicker(
{
format: 'YYYY-MM-DD HH:mm:ss',
showTodayButton: true,
calendarWeeks: true,
maxDate: moment()
});
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#tracked_time').trigger('change');
$('#tracked_time').on('focus', function(e)
{
if ($('#battery_id_text_input').val().length === 0)
{
$('#battery_id_text_input').focus();
$('#tracked_time').find('input').focus();
}
});
@@ -71,79 +52,31 @@ $('#battery_id').val('');
$('#battery_id_text_input').focus();
$('#battery_id_text_input').val('');
$('#battery_id_text_input').trigger('change');
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
$('#batterytracking-form').validator();
$('#batterytracking-form').validator('validate');
$('#batterytracking-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
});
$('#batterytracking-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if ($('#batterytracking-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('batterytracking-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-batterytracking-button').click();
}
}
});
$('#tracked_time').on('change', function(e)
$('#tracked_time').find('input').on('keypress', function (e)
{
var value = $('#tracked_time').val();
var now = new Date();
var centuryStart = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '00');
var centuryEnd = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '99');
if (value === 'x' || value === 'X') {
value = '29991231';
}
if (value.length === 4 && !(Number.parseInt(value) > centuryStart && Number.parseInt(value) < centuryEnd))
{
value = (new Date()).getFullYear().toString() + value;
}
if (value.length === 8 && $.isNumeric(value))
{
value = value.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
$('#tracked_time').val(value);
$('#batterytracking-form').validator('validate');
}
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
});
$('#tracked_time').on('keypress', function(e)
{
var element = $(e.target);
var value = element.val();
var dateObj = moment(element.val(), 'YYYY-MM-DD', true);
$('.datepicker').datepicker('hide');
//If input is empty and any arrow key is pressed, set date to today
if (value.length === 0 && (e.keyCode === 38 || e.keyCode === 40 || e.keyCode === 37 || e.keyCode === 39))
{
dateObj = moment(new Date(), 'YYYY-MM-DD', true);
}
if (dateObj.isValid())
{
if (e.keyCode === 38) //Up
{
element.val(dateObj.add(-1, 'days').format('YYYY-MM-DD'));
}
else if (e.keyCode === 40) //Down
{
element.val(dateObj.add(1, 'days').format('YYYY-MM-DD'));
}
else if (e.keyCode === 37) //Left
{
element.val(dateObj.add(-1, 'weeks').format('YYYY-MM-DD'));
}
else if (e.keyCode === 39) //Right
{
element.val(dateObj.add(1, 'weeks').format('YYYY-MM-DD'));
}
}
$('#batterytracking-form').validator('validate');
});

View File

@@ -3,9 +3,25 @@ $(function()
$('.datetimepicker').datetimepicker(
{
format: 'YYYY-MM-DD HH:mm:ss',
showTodayButton: true,
buttons: {
showToday: true,
showClose: true
},
calendarWeeks: true,
maxDate: moment(),
locale: moment.locale()
locale: moment.locale(),
defaultDate: moment().format('YYYY-MM-DD HH:mm:ss'),
icons: {
time: 'far fa-clock',
date: 'far fa-calendar',
up: 'fas fa-arrow-up',
down: 'fas fa-arrow-down',
previous: 'fas fa-chevron-left',
next: 'fas fa-chevron-right',
today: 'fas fa-calendar-check',
clear: 'far fa-trash-alt',
close: 'far fa-times-circle'
},
sideBySide: true
});
});

View File

@@ -23,7 +23,7 @@
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#consume-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('consume-form');
},
function(xhr)
{
@@ -50,26 +50,19 @@ $('#product_id').on('change', function(e)
function (productDetails)
{
$('#amount').attr('max', productDetails.stock_amount);
$('#consume-form').validator('update');
$('#amount_qu_unit').text(productDetails.quantity_unit_stock.name);
if ((productDetails.stock_amount || 0) === 0)
{
$('#product_id').val('');
$('#product_id_text_input').val('');
$('#product_id_text_input').addClass('has-error');
$('#product_id_text_input').parent('.input-group').addClass('has-error');
$('#product_id_text_input').closest('.form-group').addClass('has-error');
Grocy.FrontendHelpers.ValidateForm('consume-form');
$('#product-error').text(L('This product is not in stock'));
$('#product-error').show();
$('#product_id_text_input').focus();
}
else
{
$('#product_id_text_input').removeClass('has-error');
$('#product_id_text_input').parent('.input-group').removeClass('has-error');
$('#product_id_text_input').closest('.form-group').removeClass('has-error');
$('#product-error').hide();
Grocy.FrontendHelpers.ValidateForm('consume-form');
$('#amount').focus();
}
},
@@ -104,9 +97,6 @@ $('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#consume-form').validator();
$('#consume-form').validator('validate');
$('#amount').on('focus', function(e)
{
if ($('#product_id_text_input').val().length === 0)
@@ -119,14 +109,23 @@ $('#amount').on('focus', function(e)
}
});
$('#consume-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('consume-form');
});
$('#consume-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if ($('#consume-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('consume-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-consume-button').click();
}
}
});

View File

@@ -30,9 +30,29 @@
}
});
$('#habit-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('habit-form');
});
$('#habit-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('habit-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-habit-button').click();
}
}
});
$('#name').focus();
$('#habit-form').validator();
$('#habit-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('habit-form');
$('.input-group-habit-period-type').on('change', function(e)
{
@@ -42,10 +62,10 @@ $('.input-group-habit-period-type').on('change', function(e)
if (periodType === 'dynamic-regular')
{
$('#habit-period-type-info').text(L('This means it is estimated that a new execution of this habit is tracked #1 days after the last was tracked', periodDays.toString()));
$('#habit-period-type-info').show();
$('#habit-period-type-info').removeClass('d-none');
}
else
{
$('#habit-period-type-info').hide();
$('#habit-period-type-info').addClass('d-none');
}
});

View File

@@ -7,18 +7,18 @@
Grocy.Api.Get('habits/get-habit-details/' + jsonForm.habit_id,
function (habitDetails)
{
Grocy.Api.Get('habits/track-habit-execution/' + jsonForm.habit_id + '?tracked_time=' + $('#tracked_time').val(),
Grocy.Api.Get('habits/track-habit-execution/' + jsonForm.habit_id + '?tracked_time=' + $('#tracked_time').find('input').val(),
function(result)
{
toastr.success(L('Tracked execution of habit #1 on #2', habitDetails.habit.name, $('#tracked_time').val()));
toastr.success(L('Tracked execution of habit #1 on #2', habitDetails.habit.name, $('#tracked_time').find('input').val()));
$('#habit_id').val('');
$('#habit_id_text_input').focus();
$('#habit_id_text_input').val('');
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#tracked_time').trigger('change');
$('#tracked_time').find('input').val(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#tracked_time').find('input').trigger('change');
$('#habit_id_text_input').trigger('change');
$('#habittracking-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
},
function(xhr)
{
@@ -40,18 +40,7 @@ $('#habit_id').on('change', function(e)
if (habitId)
{
Grocy.Components.HabitCard.Refresh(habitId);
$('#tracked_time').focus();
}
});
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#tracked_time').trigger('change');
$('#tracked_time').on('focus', function(e)
{
if ($('#habit_id_text_input').val().length === 0)
{
$('#habit_id_text_input').focus();
$('#tracked_time').find('input').focus();
}
});
@@ -63,23 +52,30 @@ $('#habit_id').val('');
$('#habit_id_text_input').focus();
$('#habit_id_text_input').val('');
$('#habit_id_text_input').trigger('change');
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
$('#habittracking-form').validator();
$('#habittracking-form').validator('validate');
$('#habittracking-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
});
$('#habittracking-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if ($('#habittracking-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('habittracking-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-habittracking-button').click();
}
}
});
$('#tracked_time').on('keypress', function(e)
$('#tracked_time').find('input').on('keypress', function(e)
{
$('#habittracking-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
});

View File

@@ -40,14 +40,14 @@
}
else
{
$('#inventory-change-info').hide();
$('#inventory-change-info').addClass('d-none');
$('#new_amount').val('');
$('#best_before_date').val('');
$('#product_id').val('');
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#inventory-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('inventory-form');
}
},
function(xhr)
@@ -170,33 +170,6 @@ $('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#inventory-form').validator({
custom: {
'isodate': function($el)
{
if ($el.val().length !== 0 && !moment($el.val(), 'YYYY-MM-DD', true).isValid())
{
return 'Wrong date format, needs to be YYYY-MM-DD';
}
else if (moment($el.val()).isValid())
{
if (moment($el.val()).isBefore(moment(), 'day'))
{
return 'This value cannot be before today.';
}
}
},
'notequal': function($el)
{
if ($el.val().length !== 0 && $el.val().toString() === $el.attr('not-equal').toString())
{
return 'This value cannot be equal to ' + $el.attr('not-equal').toString();
}
}
}
});
$('#inventory-form').validator('validate');
$('#new_amount').on('focus', function(e)
{
if ($('#product_id_text_input').val().length === 0)
@@ -209,15 +182,24 @@ $('#new_amount').on('focus', function(e)
}
});
$('#inventory-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('inventory-form');
});
$('#inventory-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if ($('#inventory-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('inventory-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-inventory-button').click();
}
}
});
@@ -254,12 +236,12 @@ $('#new_amount').on('keypress', function(e)
$('#best_before_date').on('change', function(e)
{
$('#inventory-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('inventory-form');
});
$('#best_before_date').on('keypress', function(e)
{
$('#inventory-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('inventory-form');
});
$('#best_before_date').on('keydown', function(e)
@@ -270,11 +252,11 @@ $('#best_before_date').on('keydown', function(e)
}
});
$('#new_amount').on('change', function(e)
$('#new_amount').on('keyup', function(e)
{
if ($('#product_id').parent().hasClass('has-error'))
{
$('#inventory-change-info').hide();
$('#inventory-change-info').addClass('d-none');
return;
}
@@ -292,23 +274,22 @@ $('#new_amount').on('change', function(e)
{
var amountToAdd = newAmount - productDetails.stock_amount;
$('#inventory-change-info').text(L('This means #1 will be added to stock', amountToAdd.toString() + ' ' + productDetails.quantity_unit_stock.name));
$('#inventory-change-info').show();
$('#inventory-change-info').removeClass('d-none')
$('#best_before_date').attr('required', 'required');
}
else if (newAmount < productStockAmount)
{
var amountToRemove = productStockAmount - newAmount;
$('#inventory-change-info').text(L('This means #1 will be removed from stock', amountToRemove.toString() + ' ' + productDetails.quantity_unit_stock.name));
$('#inventory-change-info').show();
$('#inventory-change-info').removeClass('d-none')
$('#best_before_date').removeAttr('required');
}
else
{
$('#inventory-change-info').hide();
$('#inventory-change-info').addClass('d-none');
}
$('#inventory-form').validator('update');
$('#inventory-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('inventory-form');
},
function(xhr)
{

View File

@@ -30,6 +30,26 @@
}
});
$('#location-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('location-form');
});
$('#location-form input').keydown(function (event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('location-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-location-button').click();
}
}
});
$('#name').focus();
$('#location-form').validator();
$('#location-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('location-form');

View File

@@ -1,10 +1,7 @@
$('.logout-button').hide();
$('.logout-button-divider').hide();
$('#username').focus();
$('#username').focus();
if (GetUriParam('invalid') === 'true')
{
$('#login-error').text(L('Invalid credentials, please try again'));
$('#login-error').show();
$('#login-error').removeClass('d-none');
}

View File

@@ -82,15 +82,35 @@ $('.input-group-qu').on('change', function(e)
if (factor > 1)
{
$('#qu-conversion-info').text(L('This means 1 #1 purchased will be converted into #2 #3 in stock', $("#qu_id_purchase option:selected").text(), (1 * factor).toString(), $("#qu_id_stock option:selected").text()));
$('#qu-conversion-info').show();
$('#qu-conversion-info').removeClass('d-none');
}
else
{
$('#qu-conversion-info').hide();
$('#qu-conversion-info').addClass('d-none');
}
});
$('#product-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('product-form');
});
$('#product-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-product-button').click();
}
}
});
$('#name').focus();
$('#product-form').validator();
$('#product-form').validator('validate');
$('.input-group-qu').trigger('change');
Grocy.FrontendHelpers.ValidateForm('product-form');

View File

@@ -48,7 +48,7 @@
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#purchase-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('purchase-form');
}
},
function(xhr)
@@ -180,26 +180,6 @@ $('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#purchase-form').validator({
custom: {
'isodate': function($el)
{
if ($el.val().length !== 0 && !moment($el.val(), 'YYYY-MM-DD', true).isValid())
{
return 'Wrong date format, needs to be YYYY-MM-DD';
}
else if (moment($el.val()).isValid())
{
if (moment($el.val()).isBefore(moment(), 'day'))
{
return 'This value cannot be before today.';
}
}
}
}
});
$('#purchase-form').validator('validate');
$('#best_before_date').on('focus', function(e)
{
if ($('#product_id_text_input').val().length === 0)
@@ -220,15 +200,24 @@ $('#amount').on('focus', function(e)
}
});
$('#purchase-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
$('#purchase-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if ($('#purchase-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('purchase-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-purchase-button').click();
}
}
});
@@ -260,10 +249,15 @@ if (addBarcode !== undefined)
$('#best_before_date').on('change', function(e)
{
$('#purchase-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
$('#best_before_date').on('keypress', function(e)
{
$('#purchase-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
$('#amount').on('change', function (e)
{
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});

View File

@@ -30,6 +30,26 @@
}
});
$('#quantityunit-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('quantityunit-form');
});
$('#quantityunit-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('quantityunit-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-quantityunit-button').click();
}
}
});
$('#name').focus();
$('#quantityunit-form').validator();
$('#quantityunit-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('quantityunit-form');

View File

@@ -42,43 +42,6 @@ $('#product_id').on('change', function(e)
function (productDetails)
{
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
if ($('#product_id').hasClass('suppress-next-custom-validate-event'))
{
$('#product_id').removeClass('suppress-next-custom-validate-event');
}
else
{
Grocy.Api.Get('get-objects/shopping_list',
function (currentShoppingListItems)
{
if (currentShoppingListItems.filter(function (e) { return e.product_id === productId; }).length > 0)
{
$('#product_id').val('');
$('#product_id_text_input').val('');
$('#product_id_text_input').addClass('has-error');
$('#product_id_text_input').parent('.input-group').addClass('has-error');
$('#product_id_text_input').closest('.form-group').addClass('has-error');
$('#product-error').text('This product is already on the shopping list.');
$('#product-error').show();
$('#product_id_text_input').focus();
}
else
{
$('#product_id_text_input').removeClass('has-error');
$('#product_id_text_input').parent('.input-group').removeClass('has-error');
$('#product_id_text_input').closest('.form-group').removeClass('has-error');
$('#product-error').hide();
$('#amount').focus();
}
},
function(xhr)
{
console.error(xhr);
}
);
}
},
function(xhr)
{
@@ -113,8 +76,7 @@ if (Grocy.EditMode === 'edit')
$('#product_id').trigger('change');
}
$('#shoppinglist-form').validator();
$('#shoppinglist-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
$('#amount').on('focus', function(e)
{
@@ -124,14 +86,23 @@ $('#amount').on('focus', function(e)
}
});
$('#shoppinglist-form input').keydown(function(event)
$('#shoppinglist-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
});
$('#shoppinglist-form input').keydown(function (event)
{
if (event.keyCode === 13) //Enter
{
if ($('#shoppinglist-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('shoppinglist-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-shoppinglist-button').click();
}
}
});