mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Rework API to be more RESTful (references #139)
This commit is contained in:
@@ -125,11 +125,18 @@ Grocy.Api.Get = function(apiFunction, success, error)
|
||||
{
|
||||
if (xhr.readyState === XMLHttpRequest.DONE)
|
||||
{
|
||||
if (xhr.status === 200)
|
||||
if (xhr.status === 200 || xhr.status === 204)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
if (xhr.status === 200)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
}
|
||||
else
|
||||
{
|
||||
success({ });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -155,11 +162,18 @@ Grocy.Api.Post = function(apiFunction, jsonData, success, error)
|
||||
{
|
||||
if (xhr.readyState === XMLHttpRequest.DONE)
|
||||
{
|
||||
if (xhr.status === 200)
|
||||
if (xhr.status === 200 || xhr.status === 204)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
if (xhr.status === 200)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
}
|
||||
else
|
||||
{
|
||||
success({ });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -186,11 +200,18 @@ Grocy.Api.Put = function(apiFunction, jsonData, success, error)
|
||||
{
|
||||
if (xhr.readyState === XMLHttpRequest.DONE)
|
||||
{
|
||||
if (xhr.status === 200)
|
||||
if (xhr.status === 200 || xhr.status === 204)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
if (xhr.status === 200)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
}
|
||||
else
|
||||
{
|
||||
success({ });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -217,11 +238,18 @@ Grocy.Api.Delete = function(apiFunction, jsonData, success, error)
|
||||
{
|
||||
if (xhr.readyState === XMLHttpRequest.DONE)
|
||||
{
|
||||
if (xhr.status === 200)
|
||||
if (xhr.status === 200 || xhr.status === 204)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
if (xhr.status === 200)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
}
|
||||
else
|
||||
{
|
||||
success({ });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -386,7 +414,7 @@ $(".user-setting-control").on("change", function()
|
||||
|
||||
jsonData = { };
|
||||
jsonData.value = value;
|
||||
Grocy.Api.Post('user/settings/' + settingKey, jsonData,
|
||||
Grocy.Api.Put('user/settings/' + settingKey, jsonData,
|
||||
function(result)
|
||||
{
|
||||
// Nothing to do...
|
||||
|
@@ -1,4 +1,4 @@
|
||||
Grocy.Api.Get('system/get-db-changed-time',
|
||||
Grocy.Api.Get('system/db-changed-time',
|
||||
function(result)
|
||||
{
|
||||
Grocy.DatabaseChangedTime = moment(result.changed_time);
|
||||
@@ -14,7 +14,7 @@
|
||||
// when there is no unsaved form data and when the user enabled auto reloading
|
||||
setInterval(function()
|
||||
{
|
||||
Grocy.Api.Get('system/get-db-changed-time',
|
||||
Grocy.Api.Get('system/db-changed-time',
|
||||
function(result)
|
||||
{
|
||||
var newDbChangedTime = moment(result.changed_time);
|
||||
|
@@ -52,7 +52,7 @@ $(document).on('click', '.battery-delete-button', function (e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('object/batteries/' + objectId,
|
||||
Grocy.Api.Delete('objects/batteries/' + objectId, { },
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/batteries');
|
||||
|
@@ -56,7 +56,7 @@ $(document).on('click', '.undo-battery-execution-button', function(e)
|
||||
var element = $(e.currentTarget);
|
||||
var chargeCycleId = $(e.currentTarget).attr('data-charge-cycle-id');
|
||||
|
||||
Grocy.Api.Post('batteries/' + chargeCycleId.toString() + '/undo',
|
||||
Grocy.Api.Post('batteries/' + chargeCycleId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
element.closest("tr").addClass("text-muted");
|
||||
|
@@ -66,7 +66,7 @@ $(document).on('click', '.track-charge-cycle-button', function(e)
|
||||
var batteryName = $(e.currentTarget).attr('data-battery-name');
|
||||
var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
Grocy.Api.Post('batteries/' + batteryId + '/charged?tracked_time=' + trackedTime,
|
||||
Grocy.Api.Post('batteries/' + batteryId + '/charge', { 'tracked_time': trackedTime },
|
||||
function()
|
||||
{
|
||||
Grocy.Api.Get('batteries/' + batteryId,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('object/batteries', jsonData,
|
||||
Grocy.Api.Post('objects/batteries', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/batteries');
|
||||
@@ -21,7 +21,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Put('object/batteries/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('objects/batteries/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/batteries');
|
||||
|
@@ -8,7 +8,7 @@
|
||||
Grocy.Api.Get('batteries/' + jsonForm.battery_id,
|
||||
function (batteryDetails)
|
||||
{
|
||||
Grocy.Api.Post('batteries/' + jsonForm.battery_id + '/charge?tracked_time=' + $('#tracked_time').find('input').val(),
|
||||
Grocy.Api.Post('batteries/' + jsonForm.battery_id + '/charge', { 'tracked_time': $('#tracked_time').find('input').val() },
|
||||
function(result)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("batterytracking-form");
|
||||
@@ -92,7 +92,7 @@ $('#tracked_time').find('input').on('keypress', function (e)
|
||||
|
||||
function UndoChargeCycle(chargeCycleId)
|
||||
{
|
||||
Grocy.Api.Post('batteries' + chargeCycleId.toString() + '/undo',
|
||||
Grocy.Api.Post('batteries/' + chargeCycleId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
toastr.success(L("Charge cycle successfully undone"));
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('object/chores', jsonData,
|
||||
Grocy.Api.Post('objects/chores', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/chores');
|
||||
@@ -21,7 +21,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Put('object/chores/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('objects/chores/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/chores');
|
||||
|
@@ -52,7 +52,7 @@ $(document).on('click', '.chore-delete-button', function (e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('object/chores/' + objectId,
|
||||
Grocy.Api.Delete('objects/chores/' + objectId, {},
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/chores');
|
||||
|
@@ -56,7 +56,7 @@ $(document).on('click', '.undo-chore-execution-button', function(e)
|
||||
var element = $(e.currentTarget);
|
||||
var executionId = $(e.currentTarget).attr('data-execution-id');
|
||||
|
||||
Grocy.Api.Post('chores/' + executionId.toString() + '/undo',
|
||||
Grocy.Api.Post('chores/' + executionId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
element.closest("tr").addClass("text-muted");
|
||||
|
@@ -66,7 +66,7 @@ $(document).on('click', '.track-chore-button', function(e)
|
||||
var choreName = $(e.currentTarget).attr('data-chore-name');
|
||||
var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
Grocy.Api.Post('chores/' + choreId + '/execute?tracked_time=' + trackedTime,
|
||||
Grocy.Api.Post('chores/' + choreId + '/execute', { 'tracked_time': trackedTime },
|
||||
function()
|
||||
{
|
||||
Grocy.Api.Get('chores/' + choreId,
|
||||
|
@@ -8,7 +8,7 @@
|
||||
Grocy.Api.Get('chores/' + jsonForm.chore_id,
|
||||
function (choreDetails)
|
||||
{
|
||||
Grocy.Api.Post('chores/' + jsonForm.chore_id + '/execute?tracked_time=' + Grocy.Components.DateTimePicker.GetValue() + "&done_by=" + Grocy.Components.UserPicker.GetValue(),
|
||||
Grocy.Api.Post('chores/' + jsonForm.chore_id + '/execute', { 'tracked_time': Grocy.Components.DateTimePicker.GetValue(), 'done_by': Grocy.Components.UserPicker.GetValue() },
|
||||
function(result)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("choretracking-form");
|
||||
@@ -89,7 +89,7 @@ Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
|
||||
|
||||
function UndoChoreExecution(executionId)
|
||||
{
|
||||
Grocy.Api.Post('chores/' + executionId.toString() + '/undo',
|
||||
Grocy.Api.Post('chores/' + executionId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
toastr.success(L("Chore execution successfully undone"));
|
||||
|
@@ -2,7 +2,7 @@ Grocy.Components.ProductCard = { };
|
||||
|
||||
Grocy.Components.ProductCard.Refresh = function(productId)
|
||||
{
|
||||
Grocy.Api.Get('stock/' + productId,
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
var stockAmount = productDetails.stock_amount || '0';
|
||||
@@ -58,7 +58,7 @@ Grocy.Components.ProductCard.Refresh = function(productId)
|
||||
}
|
||||
);
|
||||
|
||||
Grocy.Api.Get('stock/' + productId + '/pricehistory',
|
||||
Grocy.Api.Get('stock/products/' + productId + '/price-history',
|
||||
function(priceHistoryDataPoints)
|
||||
{
|
||||
if (priceHistoryDataPoints.length > 0)
|
||||
|
@@ -10,23 +10,21 @@
|
||||
jsonForm.amount = 1;
|
||||
}
|
||||
|
||||
var spoiled = 0;
|
||||
if ($('#spoiled').is(':checked'))
|
||||
{
|
||||
spoiled = 1;
|
||||
}
|
||||
var apiUrl = 'stock/products/' + jsonForm.product_id + '/consume';
|
||||
|
||||
var apiUrl = 'stock/' + jsonForm.product_id + '/consume/' + jsonForm.amount + '?spoiled=' + spoiled;
|
||||
var jsonData = {};
|
||||
jsonData.amount = jsonForm.amount;
|
||||
jsonData.spoiled = $('#spoiled').is(':checked');
|
||||
|
||||
if ($("#use_specific_stock_entry").is(":checked"))
|
||||
{
|
||||
apiUrl += "&stock_entry_id=" + jsonForm.specific_stock_entry;
|
||||
jsonData.stock_entry_id = jsonForm.specific_stock_entry;
|
||||
}
|
||||
|
||||
Grocy.Api.Get('stock/' + jsonForm.product_id,
|
||||
Grocy.Api.Get('stock/products/' + jsonForm.product_id,
|
||||
function(productDetails)
|
||||
{
|
||||
Grocy.Api.Post(apiUrl,
|
||||
Grocy.Api.Post(apiUrl, jsonData,
|
||||
function(result)
|
||||
{
|
||||
$("#specific_stock_entry").find("option").remove().end().append("<option></option>");
|
||||
@@ -70,17 +68,20 @@ $('#save-mark-as-open-button').on('click', function(e)
|
||||
jsonForm.amount = 1;
|
||||
}
|
||||
|
||||
var apiUrl = 'stock/' + jsonForm.product_id + '/open/' + jsonForm.amount;
|
||||
var apiUrl = 'stock/products/' + jsonForm.product_id + '/open';
|
||||
|
||||
jsonData = { };
|
||||
jsonData.amount = jsonForm.amount;
|
||||
|
||||
if ($("#use_specific_stock_entry").is(":checked"))
|
||||
{
|
||||
apiUrl += "&stock_entry_id=" + jsonForm.specific_stock_entry;
|
||||
jsonData.stock_entry_id = jsonForm.specific_stock_entry;
|
||||
}
|
||||
|
||||
Grocy.Api.Get('stock/' + jsonForm.product_id,
|
||||
Grocy.Api.Get('stock/products/' + jsonForm.product_id,
|
||||
function(productDetails)
|
||||
{
|
||||
Grocy.Api.Post(apiUrl,
|
||||
Grocy.Api.Post(apiUrl, jsonData,
|
||||
function(result)
|
||||
{
|
||||
$("#specific_stock_entry").find("option").remove().end().append("<option></option>");
|
||||
@@ -126,7 +127,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
{
|
||||
Grocy.Components.ProductCard.Refresh(productId);
|
||||
|
||||
Grocy.Api.Get('stock/' + productId,
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
$('#amount').attr('max', productDetails.stock_amount);
|
||||
@@ -161,8 +162,8 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
}
|
||||
);
|
||||
|
||||
Grocy.Api.Get("stock/" + productId,
|
||||
function (stockEntries)
|
||||
Grocy.Api.Get("stock/products/" + productId + '/entries',
|
||||
function(stockEntries)
|
||||
{
|
||||
stockEntries.forEach(stockEntry =>
|
||||
{
|
||||
@@ -249,7 +250,7 @@ $("#use_specific_stock_entry").on("change", function()
|
||||
|
||||
function UndoStockBooking(bookingId)
|
||||
{
|
||||
Grocy.Api.Post('booking/' + bookingId.toString() + '/undo',
|
||||
Grocy.Api.Post('stock/bookings/' + bookingId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
toastr.success(L("Booking successfully undone"));
|
||||
|
@@ -34,7 +34,7 @@ equipmentTable.on('select', function(e, dt, type, indexes)
|
||||
|
||||
function DisplayEquipment(id)
|
||||
{
|
||||
Grocy.Api.Get('object/equipment/' + id,
|
||||
Grocy.Api.Get('objects/equipment/' + id,
|
||||
function(equipmentItem)
|
||||
{
|
||||
$(".selected-equipment-name").text(equipmentItem.name);
|
||||
@@ -98,7 +98,7 @@ $(document).on('click', '.equipment-delete-button', function (e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('object/equipment/' + objectId,
|
||||
Grocy.Api.Delete('objects/equipment/' + objectId, {},
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/equipment');
|
||||
|
@@ -18,7 +18,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('object/equipment', jsonData,
|
||||
Grocy.Api.Post('objects/equipment', jsonData,
|
||||
function(result)
|
||||
{
|
||||
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)
|
||||
@@ -51,7 +51,7 @@
|
||||
{
|
||||
if (Grocy.DeleteInstructionManualOnSave)
|
||||
{
|
||||
Grocy.Api.DeleteFile(Grocy.InstructionManualFileNameName, 'equipmentmanuals',
|
||||
Grocy.Api.DeleteFile(Grocy.InstructionManualFileNameName, 'equipmentmanuals', {},
|
||||
function(result)
|
||||
{
|
||||
// Nothing to do
|
||||
@@ -64,7 +64,7 @@
|
||||
);
|
||||
};
|
||||
|
||||
Grocy.Api.Put('object/equipment/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('objects/equipment/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)
|
||||
|
@@ -5,10 +5,14 @@
|
||||
var jsonForm = $('#inventory-form').serializeJSON();
|
||||
Grocy.FrontendHelpers.BeginUiBusy("inventory-form");
|
||||
|
||||
Grocy.Api.Get('stock/' + jsonForm.product_id,
|
||||
Grocy.Api.Get('stock/products/' + jsonForm.product_id,
|
||||
function (productDetails)
|
||||
{
|
||||
Grocy.Api.Post('stock/' + jsonForm.product_id + '/inventory/' + jsonForm.new_amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue(),
|
||||
var jsonData = { };
|
||||
jsonData.new_amount = jsonForm.new_amount;
|
||||
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
|
||||
|
||||
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/inventory', jsonData,
|
||||
function(result)
|
||||
{
|
||||
var addBarcode = GetUriParam('addbarcodetoselection');
|
||||
@@ -24,7 +28,7 @@
|
||||
productDetails.product.barcode += ',' + addBarcode;
|
||||
}
|
||||
|
||||
Grocy.Api.Put('object/products/' + productDetails.product.id, productDetails.product,
|
||||
Grocy.Api.Put('objects/products/' + productDetails.product.id, productDetails.product,
|
||||
function (result) { },
|
||||
function(xhr)
|
||||
{
|
||||
@@ -73,7 +77,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
{
|
||||
Grocy.Components.ProductCard.Refresh(productId);
|
||||
|
||||
Grocy.Api.Get('stock/' + productId,
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
$('#new_amount').attr('not-equal', productDetails.stock_amount);
|
||||
@@ -157,7 +161,7 @@ $('#new_amount').on('keyup', function(e)
|
||||
|
||||
if (productId)
|
||||
{
|
||||
Grocy.Api.Get('stock/' + productId,
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
var productStockAmount = parseInt(productDetails.stock_amount || '0');
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('object/locations', jsonData,
|
||||
Grocy.Api.Post('objects/locations', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/locations');
|
||||
@@ -21,7 +21,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Put('object/locations/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('objects/locations/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/locations');
|
||||
|
@@ -52,7 +52,7 @@ $(document).on('click', '.location-delete-button', function (e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('object/locations/' + objectId,
|
||||
Grocy.Api.Delete('objects/locations/' + objectId, {},
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/locations');
|
||||
|
@@ -58,7 +58,7 @@ $(document).on('click', '.apikey-delete-button', function (e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('object/api_keys/' + objectId,
|
||||
Grocy.Api.Delete('objects/api_keys/' + objectId, {},
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/manageapikeys');
|
||||
|
@@ -25,7 +25,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('object/products', jsonData,
|
||||
Grocy.Api.Post('objects/products', jsonData,
|
||||
function (result)
|
||||
{
|
||||
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave)
|
||||
@@ -58,7 +58,7 @@
|
||||
{
|
||||
if (Grocy.DeleteProductPictureOnSave)
|
||||
{
|
||||
Grocy.Api.DeleteFile(Grocy.ProductPictureFileName, 'productpictures',
|
||||
Grocy.Api.DeleteFile(Grocy.ProductPictureFileName, 'productpictures', {},
|
||||
function(result)
|
||||
{
|
||||
// Nothing to do
|
||||
@@ -71,7 +71,7 @@
|
||||
);
|
||||
};
|
||||
|
||||
Grocy.Api.Put('object/products/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('objects/products/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave)
|
||||
@@ -110,7 +110,7 @@ $('#barcode-taginput').tagsManager({
|
||||
|
||||
if (Grocy.EditMode === 'edit')
|
||||
{
|
||||
Grocy.Api.Get('object/products/' + Grocy.EditObjectId,
|
||||
Grocy.Api.Get('objects/products/' + Grocy.EditObjectId,
|
||||
function (product)
|
||||
{
|
||||
if (product.barcode !== null && product.barcode.length > 0)
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('object/product_groups', jsonData,
|
||||
Grocy.Api.Post('objects/product_groups', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/productgroups');
|
||||
@@ -21,7 +21,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Put('object/product_groups/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('objects/product_groups/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/productgroups');
|
||||
|
@@ -52,7 +52,7 @@ $(document).on('click', '.product-group-delete-button', function(e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('object/product_groups/' + objectId,
|
||||
Grocy.Api.Delete('objects/product_groups/' + objectId, {},
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/productgroups');
|
||||
|
@@ -36,7 +36,7 @@ $(document).on('click', '.product-delete-button', function (e)
|
||||
var objectName = $(e.currentTarget).attr('data-product-name');
|
||||
var objectId = $(e.currentTarget).attr('data-product-id');
|
||||
|
||||
Grocy.Api.Get('stock/' + objectId,
|
||||
Grocy.Api.Get('stock/products/' + objectId,
|
||||
function(productDetails)
|
||||
{
|
||||
var stockAmount = productDetails.stock_amount || '0';
|
||||
@@ -59,7 +59,7 @@ $(document).on('click', '.product-delete-button', function (e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('object/products/' + objectId,
|
||||
Grocy.Api.Delete('objects/products/' + objectId, {},
|
||||
function (result)
|
||||
{
|
||||
window.location.href = U('/products');
|
||||
|
@@ -5,7 +5,7 @@
|
||||
var jsonForm = $('#purchase-form').serializeJSON();
|
||||
Grocy.FrontendHelpers.BeginUiBusy("purchase-form");
|
||||
|
||||
Grocy.Api.Get('stock/' + jsonForm.product_id,
|
||||
Grocy.Api.Get('stock/products/' + jsonForm.product_id,
|
||||
function(productDetails)
|
||||
{
|
||||
var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
|
||||
@@ -16,7 +16,12 @@
|
||||
price = parseFloat(jsonForm.price).toFixed(2);
|
||||
}
|
||||
|
||||
Grocy.Api.Post('stock/' + jsonForm.product_id + '/add/' + amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue() + '&price=' + price,
|
||||
var jsonData = {};
|
||||
jsonData.amount = amount;
|
||||
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
|
||||
jsonData.price = price;
|
||||
|
||||
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/add', jsonData,
|
||||
function(result)
|
||||
{
|
||||
var addBarcode = GetUriParam('addbarcodetoselection');
|
||||
@@ -32,7 +37,7 @@
|
||||
productDetails.product.barcode += ',' + addBarcode;
|
||||
}
|
||||
|
||||
Grocy.Api.Put('object/products/' + productDetails.product.id, productDetails.product,
|
||||
Grocy.Api.Put('objects/products/' + productDetails.product.id, productDetails.product,
|
||||
function (result) { },
|
||||
function(xhr)
|
||||
{
|
||||
@@ -89,7 +94,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
{
|
||||
Grocy.Components.ProductCard.Refresh(productId);
|
||||
|
||||
Grocy.Api.Get('stock/' + productId,
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('object/quantity_units', jsonData,
|
||||
Grocy.Api.Post('objects/quantity_units', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/quantityunits');
|
||||
@@ -21,7 +21,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Put('object/quantity_units/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('objects/quantity_units/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/quantityunits');
|
||||
|
@@ -52,7 +52,7 @@ $(document).on('click', '.quantityunit-delete-button', function (e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('object/quantity_units/' + objectId,
|
||||
Grocy.Api.Delete('objects/quantity_units/' + objectId, {},
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/quantityunits');
|
||||
|
@@ -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);
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('object/recipes_pos', jsonData,
|
||||
Grocy.Api.Post('objects/recipes_pos', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/recipe/' + Grocy.EditObjectParentId);
|
||||
@@ -23,7 +23,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Put('object/recipes_pos/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('objects/recipes_pos/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/recipe/' + Grocy.EditObjectParentId);
|
||||
@@ -45,7 +45,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
{
|
||||
Grocy.Components.ProductCard.Refresh(productId);
|
||||
|
||||
Grocy.Api.Get('stock/' + productId,
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function (productDetails)
|
||||
{
|
||||
if (!$("#only_check_single_unit_in_stock").is(":checked"))
|
||||
|
@@ -63,7 +63,7 @@ $("#selectedRecipeDeleteButton").on('click', function(e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('object/recipes/' + objectId,
|
||||
Grocy.Api.Delete('objects/recipes/' + objectId, {},
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/recipes');
|
||||
@@ -101,7 +101,7 @@ $(document).on('click', '.recipe-order-missing-button', function(e)
|
||||
{
|
||||
Grocy.FrontendHelpers.BeginUiBusy();
|
||||
|
||||
Grocy.Api.Post('recipes/' + objectId + '/shoppinglist',
|
||||
Grocy.Api.Post('recipes/' + objectId + '/add-not-fulfilled-products-to-shoppinglist', { },
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/recipes');
|
||||
@@ -140,7 +140,7 @@ $("#selectedRecipeConsumeButton").on('click', function(e)
|
||||
{
|
||||
Grocy.FrontendHelpers.BeginUiBusy();
|
||||
|
||||
Grocy.Api.Get('recipes/' + objectId + '/consume',
|
||||
Grocy.Api.Post('recipes/' + objectId + '/consume', { },
|
||||
function(result)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy();
|
||||
|
@@ -64,7 +64,7 @@ $(document).on('click', '.shoppinglist-delete-button', function (e)
|
||||
var shoppingListItemId = $(e.currentTarget).attr('data-shoppinglist-id');
|
||||
Grocy.FrontendHelpers.BeginUiBusy();
|
||||
|
||||
Grocy.Api.Delete('object/shopping_list/' + shoppingListItemId,
|
||||
Grocy.Api.Delete('objects/shopping_list/' + shoppingListItemId, {},
|
||||
function(result)
|
||||
{
|
||||
$('#shoppinglistitem-' + shoppingListItemId + '-row').fadeOut(500, function()
|
||||
@@ -84,7 +84,7 @@ $(document).on('click', '.shoppinglist-delete-button', function (e)
|
||||
|
||||
$(document).on('click', '#add-products-below-min-stock-amount', function(e)
|
||||
{
|
||||
Grocy.Api.Post('stock/shoppinglist',
|
||||
Grocy.Api.Post('stock/shoppinglist/add-missing-products', { },
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/shoppinglist');
|
||||
@@ -116,7 +116,7 @@ $(document).on('click', '#clear-shopping-list', function(e)
|
||||
{
|
||||
Grocy.FrontendHelpers.BeginUiBusy();
|
||||
|
||||
Grocy.Api.Post('stock/clearshoppinglist',
|
||||
Grocy.Api.Post('stock/shoppinglist/clear', { },
|
||||
function(result)
|
||||
{
|
||||
$('#shoppinglist-table tbody tr').fadeOut(500, function()
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('object/shopping_list', jsonData,
|
||||
Grocy.Api.Post('objects/shopping_list', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/shoppinglist');
|
||||
@@ -21,7 +21,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Put('object/shopping_list/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('objects/shopping_list/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/shoppinglist');
|
||||
@@ -43,7 +43,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
{
|
||||
Grocy.Components.ProductCard.Refresh(productId);
|
||||
|
||||
Grocy.Api.Get('stock/' + productId,
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function (productDetails)
|
||||
{
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
|
||||
|
@@ -56,7 +56,7 @@ $(document).on('click', '.undo-stock-booking-button', function(e)
|
||||
var element = $(e.currentTarget);
|
||||
var bookingId = $(e.currentTarget).attr('data-booking-id');
|
||||
|
||||
Grocy.Api.Get('booking/' + bookingId.toString() + '/undo',
|
||||
Grocy.Api.Post('stock/bookings/' + bookingId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
element.closest("tr").addClass("text-muted");
|
||||
|
@@ -92,10 +92,10 @@ $(document).on('click', '.product-consume-button', function(e)
|
||||
var productQuName = $(e.currentTarget).attr('data-product-qu-name');
|
||||
var consumeAmount = $(e.currentTarget).attr('data-consume-amount');
|
||||
|
||||
Grocy.Api.Post('stock/' + productId + '/consume/' + consumeAmount,
|
||||
Grocy.Api.Post('stock/products/' + productId + '/consume', { 'amount': consumeAmount },
|
||||
function()
|
||||
{
|
||||
Grocy.Api.Get('stock/' + productId,
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function(result)
|
||||
{
|
||||
var productRow = $('#product-' + productId + '-row');
|
||||
@@ -189,10 +189,10 @@ $(document).on('click', '.product-open-button', function(e)
|
||||
var productQuName = $(e.currentTarget).attr('data-product-qu-name');
|
||||
var button = $(e.currentTarget);
|
||||
|
||||
Grocy.Api.Get('stock/' + productId + 'open/1',
|
||||
Grocy.Api.Post('stock/products/' + productId + '/open', { 'amount': 1 },
|
||||
function()
|
||||
{
|
||||
Grocy.Api.Get('stock/' + productId,
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function(result)
|
||||
{
|
||||
var productRow = $('#product-' + productId + '-row');
|
||||
|
@@ -52,7 +52,7 @@ $(document).on('click', '.task-category-delete-button', function (e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('object/task_categories/' + objectId,
|
||||
Grocy.Api.Delete('objects/task_categories/' + objectId, {},
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/taskcategories');
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('object/task_categories', jsonData,
|
||||
Grocy.Api.Post('objects/task_categories', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/taskcategories');
|
||||
@@ -21,7 +21,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Put('object/task_categories/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('objects/task_categories/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/taskcategories');
|
||||
|
@@ -11,7 +11,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('object/tasks', jsonData,
|
||||
Grocy.Api.Post('objects/tasks', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/tasks');
|
||||
@@ -25,7 +25,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Put('object/tasks/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('objects/tasks/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/tasks');
|
||||
|
@@ -70,7 +70,7 @@ $(document).on('click', '.do-task-button', function(e)
|
||||
var taskName = $(e.currentTarget).attr('data-task-name');
|
||||
var doneTime = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
Grocy.Api.Get('tasks/' + taskId + '/complete?done_time=' + doneTime,
|
||||
Grocy.Api.Post('tasks/' + taskId + '/complete', { 'done_time': doneTime },
|
||||
function()
|
||||
{
|
||||
if (!$("#show-done-tasks").is(":checked"))
|
||||
@@ -123,7 +123,7 @@ $(document).on('click', '.delete-task-button', function (e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('object/tasks/' + objectId,
|
||||
Grocy.Api.Delete('objects/tasks/' + objectId, {},
|
||||
function(result)
|
||||
{
|
||||
$('#task-' + objectId + '-row').fadeOut(500, function ()
|
||||
|
@@ -52,7 +52,7 @@ $(document).on('click', '.user-delete-button', function (e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('users/delete/' + objectId,
|
||||
Grocy.Api.Delete('users/delete/' + objectId, {},
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/users');
|
||||
|
Reference in New Issue
Block a user