2017-04-15 23:16:20 +02:00
|
|
|
|
$('#save-quantityunit-button').on('click', function(e)
|
|
|
|
|
{
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2018-11-24 19:40:50 +01:00
|
|
|
|
var jsonData = $('#quantityunit-form').serializeJSON();
|
|
|
|
|
Grocy.FrontendHelpers.BeginUiBusy("quantityunit-form");
|
|
|
|
|
|
2017-04-15 23:16:20 +02:00
|
|
|
|
if (Grocy.EditMode === 'create')
|
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
|
Grocy.Api.Post('objects/quantity_units', jsonData,
|
2017-04-15 23:16:20 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2019-04-22 22:16:35 +02:00
|
|
|
|
Grocy.EditObjectId = result.created_object_id;
|
|
|
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/quantityunits');
|
|
|
|
|
});
|
2017-04-15 23:16:20 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("quantityunit-form");
|
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
|
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
|
Grocy.Api.Put('objects/quantity_units/' + Grocy.EditObjectId, jsonData,
|
2017-04-15 23:16:20 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2019-04-22 22:16:35 +02:00
|
|
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/quantityunits');
|
|
|
|
|
});
|
2017-04-15 23:16:20 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("quantityunit-form");
|
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();
|
2019-01-19 00:37:21 -07:00
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-04-22 22:16:35 +02:00
|
|
|
|
Grocy.Components.UserfieldsForm.Load();
|
2018-04-16 19:11:32 +02:00
|
|
|
|
$('#name').focus();
|
2018-07-11 19:43:05 +02:00
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('quantityunit-form');
|