Rework API to be more RESTful (references #139)

This commit is contained in:
Bernd Bestel
2019-01-19 14:51:51 +01:00
parent 0ce8d706a6
commit bfa59dd29c
52 changed files with 1110 additions and 1143 deletions

View File

@@ -5,7 +5,7 @@
var jsonData = $('#recipe-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("recipe-form");
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, jsonData,
Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, jsonData,
function(result)
{
window.location.href = U('/recipes');
@@ -113,8 +113,8 @@ $(document).on('click', '.recipe-pos-delete-button', function(e)
{
if (result === true)
{
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { });
Grocy.Api.Delete('object/recipes_pos/' + objectId,
Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { });
Grocy.Api.Delete('objects/recipes_pos/' + objectId, {},
function(result)
{
window.location.href = U('/recipe/' + Grocy.EditObjectId);
@@ -150,8 +150,8 @@ $(document).on('click', '.recipe-include-delete-button', function(e)
{
if (result === true)
{
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { });
Grocy.Api.Delete('object/recipes_nestings/' + objectId,
Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { });
Grocy.Api.Delete('objects/recipes_nestings/' + objectId, {},
function(result)
{
window.location.href = U('/recipe/' + Grocy.EditObjectId);
@@ -178,10 +178,10 @@ $(document).on('click', '.recipe-pos-order-missing-button', function(e)
jsonData.amount = productAmount;
jsonData.note = L('Added for recipe #1', recipeName);
Grocy.Api.Post('object/shopping_list', jsonData,
Grocy.Api.Post('objects/shopping_list', jsonData,
function(result)
{
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function () { }, function () { });
Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function () { }, function () { });
window.location.href = U('/recipe/' + Grocy.EditObjectId);
},
function(xhr)
@@ -202,7 +202,7 @@ $(document).on('click', '.recipe-pos-edit-button', function (e)
{
var recipePosId = $(e.currentTarget).attr('data-recipe-pos-id');
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result)
{
window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/' + recipePosId);
@@ -219,7 +219,7 @@ $(document).on('click', '.recipe-include-edit-button', function (e)
var id = $(e.currentTarget).attr('data-recipe-include-id');
var recipeId = $(e.currentTarget).attr('data-recipe-included-recipe-id');
console.log(recipeId);
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result)
{
$("#recipe-include-editform-title").text(L("Edit included recipe"));
@@ -238,7 +238,7 @@ $(document).on('click', '.recipe-include-edit-button', function (e)
$("#recipe-pos-add-button").on("click", function(e)
{
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result)
{
window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/new');
@@ -252,7 +252,7 @@ $("#recipe-pos-add-button").on("click", function(e)
$("#recipe-include-add-button").on("click", function(e)
{
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result)
{
$("#recipe-include-editform-title").text(L("Add included recipe"));
@@ -280,7 +280,7 @@ $('#save-recipe-include-button').on('click', function(e)
if (editMode === 'create')
{
Grocy.Api.Post('object/recipes_nestings', jsonData,
Grocy.Api.Post('objects/recipes_nestings', jsonData,
function(result)
{
window.location.href = U('/recipe/' + Grocy.EditObjectId);
@@ -293,7 +293,7 @@ $('#save-recipe-include-button').on('click', function(e)
}
else
{
Grocy.Api.Put('object/recipes_nestings/' + nestingId, jsonData,
Grocy.Api.Put('objects/recipes_nestings/' + nestingId, jsonData,
function(result)
{
window.location.href = U('/recipe/' + Grocy.EditObjectId);