2018-09-24 13:02:52 +02:00
|
|
|
|
$('#save-product-group-button').on('click', function(e)
|
|
|
|
|
{
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2018-11-24 19:40:50 +01:00
|
|
|
|
var jsonData = $('#product-group-form').serializeJSON();
|
|
|
|
|
Grocy.FrontendHelpers.BeginUiBusy("product-group-form");
|
|
|
|
|
|
2018-09-24 13:02:52 +02:00
|
|
|
|
if (Grocy.EditMode === 'create')
|
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
|
Grocy.Api.Post('objects/product_groups', jsonData,
|
2018-09-24 13:02:52 +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('/productgroups');
|
|
|
|
|
});
|
2018-09-24 13:02:52 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("product-group-form");
|
2018-09-24 13:02:52 +02:00
|
|
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
|
Grocy.Api.Put('objects/product_groups/' + Grocy.EditObjectId, jsonData,
|
2018-09-24 13:02:52 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2019-04-22 22:16:35 +02:00
|
|
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/productgroups');
|
|
|
|
|
});
|
2018-09-24 13:02:52 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("product-group-form");
|
2018-09-24 13:02:52 +02:00
|
|
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#product-group-form input').keyup(function (event)
|
|
|
|
|
{
|
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('product-group-form');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#product-group-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-09-24 13:02:52 +02:00
|
|
|
|
if (document.getElementById('product-group-form').checkValidity() === false) //There is at least one validation error
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$('#save-product-group-button').click();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-04-22 22:16:35 +02:00
|
|
|
|
Grocy.Components.UserfieldsForm.Load();
|
2018-09-24 13:02:52 +02:00
|
|
|
|
$('#name').focus();
|
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('product-group-form');
|