2019-04-20 17:04:40 +02:00
|
|
|
|
$('#save-shopping-list-button').on('click', function(e)
|
2017-04-21 15:36:04 +02:00
|
|
|
|
{
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2022-03-26 10:34:00 +01:00
|
|
|
|
if (!Grocy.FrontendHelpers.ValidateForm("shopping-list-form", true))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-31 13:45:14 +01:00
|
|
|
|
if ($(".combobox-menu-visible").length)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-20 17:04:40 +02:00
|
|
|
|
var jsonData = $('#shopping-list-form').serializeJSON();
|
|
|
|
|
Grocy.FrontendHelpers.BeginUiBusy("shopping-list-form");
|
2018-11-24 19:40:50 +01:00
|
|
|
|
|
2017-04-21 15:36:04 +02:00
|
|
|
|
if (Grocy.EditMode === 'create')
|
|
|
|
|
{
|
2019-04-20 17:04:40 +02:00
|
|
|
|
Grocy.Api.Post('objects/shopping_lists', jsonData,
|
2017-04-21 15:36:04 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2020-11-17 19:11:02 +01:00
|
|
|
|
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);
|
2025-01-10 17:15:09 +01:00
|
|
|
|
window.parent.postMessage(WindowMessageBag("CloseLastModal"), Grocy.BaseUrl);
|
2020-11-17 19:11:02 +01:00
|
|
|
|
});
|
2017-04-21 15:36:04 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2019-04-20 17:04:40 +02:00
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("shopping-list-form");
|
2020-10-29 11:09:35 -05:00
|
|
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
|
2017-04-21 15:36:04 +02:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-11-17 19:11:02 +01:00
|
|
|
|
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);
|
2025-01-10 17:15:09 +01:00
|
|
|
|
window.parent.postMessage(WindowMessageBag("CloseLastModal"), Grocy.BaseUrl);
|
2020-11-17 19:11:02 +01:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("shopping-list-form");
|
|
|
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
2017-04-21 15:36:04 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-04-20 17:04:40 +02:00
|
|
|
|
$('#shopping-list-form input').keyup(function(event)
|
2017-04-21 19:02:00 +02:00
|
|
|
|
{
|
2019-04-20 17:04:40 +02:00
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('shopping-list-form');
|
2018-07-11 19:43:05 +02:00
|
|
|
|
});
|
|
|
|
|
|
2020-08-30 12:18:16 +02:00
|
|
|
|
$('#shopping-list-form input').keydown(function(event)
|
2018-04-16 19:11:32 +02:00
|
|
|
|
{
|
2022-03-30 18:00:28 +02:00
|
|
|
|
if (event.keyCode === 13) // Enter
|
2017-04-21 15:36:04 +02:00
|
|
|
|
{
|
2018-09-29 13:41:56 +02:00
|
|
|
|
event.preventDefault();
|
2019-01-19 00:37:21 -07:00
|
|
|
|
|
2022-03-30 18:00:28 +02:00
|
|
|
|
if (!Grocy.FrontendHelpers.ValidateForm('shopping-list-form'))
|
2017-04-21 15:36:04 +02:00
|
|
|
|
{
|
2018-04-16 19:11:32 +02:00
|
|
|
|
return false;
|
2017-04-21 15:36:04 +02:00
|
|
|
|
}
|
2018-07-11 19:43:05 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2019-04-20 17:04:40 +02:00
|
|
|
|
$('#save-shopping-list-button').click();
|
2018-07-11 19:43:05 +02:00
|
|
|
|
}
|
2018-04-16 19:11:32 +02:00
|
|
|
|
}
|
2017-04-21 15:36:04 +02:00
|
|
|
|
});
|
2019-04-20 17:04:40 +02:00
|
|
|
|
|
2020-11-17 19:11:02 +01:00
|
|
|
|
Grocy.Components.UserfieldsForm.Load();
|
2021-11-08 21:59:02 +01:00
|
|
|
|
setTimeout(function()
|
|
|
|
|
{
|
|
|
|
|
$('#name').focus();
|
2025-01-31 15:35:34 +01:00
|
|
|
|
}, Grocy.FormFocusDelay);
|
2019-04-20 17:04:40 +02:00
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('shopping-list-form');
|