mirror of
https://github.com/grocy/grocy.git
synced 2025-10-15 01:37:13 +00:00
Implemented meal plan sections (closes #370)
This commit is contained in:
75
public/viewjs/mealplansectionform.js
Normal file
75
public/viewjs/mealplansectionform.js
Normal file
@@ -0,0 +1,75 @@
|
||||
$('#save-mealplansection-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
var jsonData = $('#mealplansection-form').serializeJSON();
|
||||
Grocy.FrontendHelpers.BeginUiBusy("mealplansection-form");
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('objects/meal_plan_sections', jsonData,
|
||||
function(result)
|
||||
{
|
||||
if (GetUriParam("embedded") !== undefined)
|
||||
{
|
||||
window.parent.postMessage(WindowMessageBag("Reload"), Grocy.BaseUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = U('/mealplansections');
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("mealplansection-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Put('objects/meal_plan_sections/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
if (GetUriParam("embedded") !== undefined)
|
||||
{
|
||||
window.parent.postMessage(WindowMessageBag("Reload"), Grocy.BaseUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = U('/mealplansections');
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("mealplansection-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$('#mealplansection-form input').keyup(function(event)
|
||||
{
|
||||
Grocy.FrontendHelpers.ValidateForm('mealplansection-form');
|
||||
});
|
||||
|
||||
$('#mealplansection-form input').keydown(function(event)
|
||||
{
|
||||
if (event.keyCode === 13) //Enter
|
||||
{
|
||||
event.preventDefault();
|
||||
|
||||
if (document.getElementById('mealplansection-form').checkValidity() === false) //There is at least one validation error
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#save-mealplansections-button').click();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Grocy.FrontendHelpers.ValidateForm('mealplansection-form');
|
||||
$('#name').focus();
|
Reference in New Issue
Block a user