mirror of
https://github.com/grocy/grocy.git
synced 2025-08-17 11:06:36 +00:00
API - A bit more RESTful (#140)
* Restful routes * Change public/viewjs to match API routes * Move the GET and POST together. Fixed Typos. PUT for object/user edits. * Verb-less Generic Entity Interactions * Create Grocy.Api.Put * Create Grocy.Api.Delete * Fix Volatile Slim Error order in routes and adjust to english noun
This commit is contained in:
committed by
Bernd Bestel
parent
98d95f80df
commit
0ce8d706a6
@@ -21,12 +21,12 @@
|
||||
|
||||
localizedText = text;
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < placeholderValues.length; i++)
|
||||
{
|
||||
localizedText = localizedText.replace('#' + (i + 1), placeholderValues[i]);
|
||||
}
|
||||
|
||||
|
||||
return localizedText;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ if (window.localStorage.getItem("sidebar_state") === "collapsed")
|
||||
|
||||
$.timeago.settings.allowFuture = true;
|
||||
RefreshContextualTimeago = function()
|
||||
{
|
||||
{
|
||||
$("time.timeago").each(function()
|
||||
{
|
||||
var element = $(this);
|
||||
@@ -177,6 +177,68 @@ Grocy.Api.Post = function(apiFunction, jsonData, success, error)
|
||||
xhr.send(JSON.stringify(jsonData));
|
||||
};
|
||||
|
||||
Grocy.Api.Put = function(apiFunction, jsonData, success, error)
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = U('/api/' + apiFunction);
|
||||
|
||||
xhr.onreadystatechange = function()
|
||||
{
|
||||
if (xhr.readyState === XMLHttpRequest.DONE)
|
||||
{
|
||||
if (xhr.status === 200)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
error(xhr);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.open('PUT', url, true);
|
||||
xhr.setRequestHeader('Content-type', 'application/json');
|
||||
xhr.send(JSON.stringify(jsonData));
|
||||
};
|
||||
|
||||
Grocy.Api.Delete = function(apiFunction, jsonData, success, error)
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = U('/api/' + apiFunction);
|
||||
|
||||
xhr.onreadystatechange = function()
|
||||
{
|
||||
if (xhr.readyState === XMLHttpRequest.DONE)
|
||||
{
|
||||
if (xhr.status === 200)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
error(xhr);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.open('DELETE', url, true);
|
||||
xhr.setRequestHeader('Content-type', 'application/json');
|
||||
xhr.send(JSON.stringify(jsonData));
|
||||
};
|
||||
|
||||
Grocy.Api.UploadFile = function(file, group, fileName, success, error)
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
@@ -286,7 +348,7 @@ Grocy.FrontendHelpers.ShowGenericError = function(message, exception)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
console.error(exception);
|
||||
}
|
||||
|
||||
@@ -310,7 +372,7 @@ $(".user-setting-control").on("change", function()
|
||||
{
|
||||
inputType = element.attr("type").toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
if (inputType === "checkbox")
|
||||
{
|
||||
value = element.is(":checked");
|
||||
@@ -319,9 +381,9 @@ $(".user-setting-control").on("change", function()
|
||||
{
|
||||
var value = element.val();
|
||||
}
|
||||
|
||||
|
||||
Grocy.UserSettings[settingKey] = value;
|
||||
|
||||
|
||||
jsonData = { };
|
||||
jsonData.value = value;
|
||||
Grocy.Api.Post('user/settings/' + settingKey, jsonData,
|
||||
@@ -358,7 +420,7 @@ ResizeResponsiveEmbeds = function(fillEntireViewport = false)
|
||||
{
|
||||
var maxHeight = $("body").height();
|
||||
}
|
||||
|
||||
|
||||
$(".embed-responsive").attr("height", maxHeight.toString() + "px");
|
||||
}
|
||||
$(window).on('resize', function()
|
||||
|
Reference in New Issue
Block a user