2017-04-15 23:16:20 +02:00
|
|
|
|
$('#save-quantityunit-button').on('click', function(e)
|
|
|
|
|
{
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
if (Grocy.EditMode === 'create')
|
|
|
|
|
{
|
2018-04-18 19:03:39 +02:00
|
|
|
|
Grocy.Api.Post('add-object/quantity_units', $('#quantityunit-form').serializeJSON(),
|
2017-04-15 23:16:20 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2018-04-18 19:03:39 +02:00
|
|
|
|
window.location.href = U('/quantityunits');
|
2017-04-15 23:16:20 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-09-08 09:26:12 +02:00
|
|
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
2017-04-15 23:16:20 +02:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-18 19:03:39 +02:00
|
|
|
|
Grocy.Api.Post('edit-object/quantity_units/' + Grocy.EditObjectId, $('#quantityunit-form').serializeJSON(),
|
2017-04-15 23:16:20 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2018-04-18 19:03:39 +02:00
|
|
|
|
window.location.href = U('/quantityunits');
|
2017-04-15 23:16:20 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-09-08 09:26:12 +02:00
|
|
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
2017-04-15 23:16:20 +02:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-07-11 19:43:05 +02:00
|
|
|
|
$('#quantityunit-form input').keyup(function(event)
|
|
|
|
|
{
|
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('quantityunit-form');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#quantityunit-form input').keydown(function(event)
|
|
|
|
|
{
|
|
|
|
|
if (event.keyCode === 13) //Enter
|
|
|
|
|
{
|
2018-09-29 13:41:56 +02:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
2018-07-11 19:43:05 +02:00
|
|
|
|
if (document.getElementById('quantityunit-form').checkValidity() === false) //There is at least one validation error
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$('#save-quantityunit-button').click();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-04-16 19:11:32 +02:00
|
|
|
|
$('#name').focus();
|
2018-07-11 19:43:05 +02:00
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('quantityunit-form');
|