grocy/public/viewjs/shoppinglistform.js
Bernd Bestel 887526c727
Squashed commit
Fixed number input min/max amount handling
Only (auto) save valid user inputs
More filters on the stock journal pages
Save the last price per used barcode and preselect that as a total price on purchase if not empty (closes #1131)
Don't apply conversions for only_check_single_unit_in_stock ingredients (fixes #1120)
Render shopping list userfields (closes #1052)
Fixed Focus when adding included recipes (closes #1019)
Order all base objects with NOCASE (closes #1086)
2020-11-17 19:11:02 +01:00

74 lines
2.1 KiB
JavaScript

$('#save-shopping-list-button').on('click', function(e)
{
e.preventDefault();
var jsonData = $('#shopping-list-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("shopping-list-form");
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('objects/shopping_lists', jsonData,
function(result)
{
Grocy.EditObjectId = result.created_object_id;
Grocy.Components.UserfieldsForm.Save(function()
{
window.parent.postMessage(WindowMessageBag("ShoppingListChanged", result.created_object_id), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl);
});
},
function(xhr)
{
Grocy.FrontendHelpers.EndUiBusy("shopping-list-form");
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
}
);
}
else
{
Grocy.Components.UserfieldsForm.Save(function()
{
Grocy.Api.Put('objects/shopping_lists/' + Grocy.EditObjectId, jsonData,
function(result)
{
window.parent.postMessage(WindowMessageBag("ShoppingListChanged", Grocy.EditObjectId), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl);
},
function(xhr)
{
Grocy.FrontendHelpers.EndUiBusy("shopping-list-form");
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
}
);
});
}
});
$('#shopping-list-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('shopping-list-form');
});
$('#shopping-list-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
if (document.getElementById('shopping-list-form').checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
$('#save-shopping-list-button').click();
}
}
});
Grocy.Components.UserfieldsForm.Load();
$('#name').focus();
Grocy.FrontendHelpers.ValidateForm('shopping-list-form');