mirror of
https://github.com/grocy/grocy.git
synced 2025-10-14 17:24:07 +00:00
More improvements on the REST API (references #139)
This commit is contained in:
@@ -270,17 +270,24 @@ Grocy.Api.Delete = function(apiFunction, jsonData, success, error)
|
||||
Grocy.Api.UploadFile = function(file, group, fileName, success, error)
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = U('/api/file/' + group + '?file_name=' + encodeURIComponent(fileName));
|
||||
var url = U('/api/files/' + group + '/' + btoa(fileName));
|
||||
|
||||
xhr.onreadystatechange = function()
|
||||
{
|
||||
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
|
||||
@@ -301,17 +308,24 @@ Grocy.Api.UploadFile = function(file, group, fileName, success, error)
|
||||
Grocy.Api.DeleteFile = function(fileName, group, success, error)
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = U('/api/file/' + group + '?file_name=' + encodeURIComponent(fileName));
|
||||
var url = U('/api/files/' + group + '/' + btoa(fileName));
|
||||
|
||||
xhr.onreadystatechange = function()
|
||||
{
|
||||
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
|
||||
|
@@ -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/charge-cycles/' + chargeCycleId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
element.closest("tr").addClass("text-muted");
|
||||
|
@@ -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/charge-cycles/' + chargeCycleId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
toastr.success(L("Charge cycle successfully undone"));
|
||||
|
@@ -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/executions/' + executionId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
element.closest("tr").addClass("text-muted");
|
||||
|
@@ -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/executions/' + executionId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
toastr.success(L("Chore execution successfully undone"));
|
||||
|
@@ -41,7 +41,7 @@ Grocy.Components.ProductCard.Refresh = function(productId)
|
||||
{
|
||||
$("#productcard-no-product-picture").addClass("d-none");
|
||||
$("#productcard-product-picture").removeClass("d-none");
|
||||
$("#productcard-product-picture").attr("src", U('/api/file/productpictures?file_name=' + productDetails.product.picture_file_name));
|
||||
$("#productcard-product-picture").attr("src", U('/api/files/productpictures/' + btoa(productDetails.product.picture_file_name)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -43,7 +43,7 @@ function DisplayEquipment(id)
|
||||
|
||||
if (equipmentItem.instruction_manual_file_name !== null && !equipmentItem.instruction_manual_file_name.isEmpty())
|
||||
{
|
||||
var pdfUrl = U('/api/file/equipmentmanuals?file_name=' + equipmentItem.instruction_manual_file_name);
|
||||
var pdfUrl = U('/api/files/equipmentmanuals/' + btoa(equipmentItem.instruction_manual_file_name));
|
||||
$("#selected-equipment-instruction-manual").attr("src", pdfUrl);
|
||||
$("#selected-equipment-instruction-manual").removeClass("d-none");
|
||||
$("#selected-equipment-has-no-instruction-manual-hint").addClass("d-none");
|
||||
|
@@ -197,7 +197,7 @@ $('#new_amount').on('keyup', function(e)
|
||||
|
||||
function UndoStockBooking(bookingId)
|
||||
{
|
||||
Grocy.Api.Get('booking/' + bookingId.toString() + '/undo',
|
||||
Grocy.Api.Post('stock/bookings/' + bookingId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
toastr.success(L("Booking successfully undone"));
|
||||
|
@@ -202,7 +202,7 @@ if (GetUriParam("flow") === "shoppinglistitemtostock")
|
||||
|
||||
function UndoStockBooking(bookingId)
|
||||
{
|
||||
Grocy.Api.Get('sbooking/' + bookingId.toString() + '/undo',
|
||||
Grocy.Api.Post('stock/bookings/' + bookingId.toString() + '/undo', { },
|
||||
function(result)
|
||||
{
|
||||
toastr.success(L("Booking successfully undone"));
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('users/create', jsonData,
|
||||
Grocy.Api.Post('users', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/users');
|
||||
@@ -21,7 +21,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Post('users/edit/' + Grocy.EditObjectId, jsonData,
|
||||
Grocy.Api.Put('users/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/users');
|
||||
|
Reference in New Issue
Block a user