mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
99 lines
1.7 KiB
JavaScript
99 lines
1.7 KiB
JavaScript
L = function(text, ...placeholderValues)
|
|
{
|
|
var localizedText = Grocy.LocalizationStrings[text];
|
|
if (localizedText === undefined)
|
|
{
|
|
localizedText = text;
|
|
}
|
|
|
|
for (var i = 0; i < placeholderValues.length; i++)
|
|
{
|
|
localizedText = localizedText.replace('#' + (i + 1), placeholderValues[i]);
|
|
}
|
|
|
|
return localizedText;
|
|
}
|
|
|
|
U = function(relativePath)
|
|
{
|
|
return Grocy.BaseUrl.replace(/\/$/, '') + relativePath;
|
|
}
|
|
|
|
if (!Grocy.ActiveNav.isEmpty())
|
|
{
|
|
var menuItem = $('.nav').find("[data-nav-for-page='" + Grocy.ActiveNav + "']");
|
|
menuItem.addClass('active');
|
|
}
|
|
|
|
$.timeago.settings.allowFuture = true;
|
|
$('time.timeago').timeago();
|
|
|
|
toastr.options = {
|
|
toastClass: 'alert',
|
|
closeButton: true,
|
|
timeOut: 20000,
|
|
extendedTimeOut: 5000
|
|
};
|
|
|
|
Grocy.Api = { };
|
|
Grocy.Api.Get = function(apiFunction, 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('GET', url, true);
|
|
xhr.send();
|
|
};
|
|
|
|
Grocy.Api.Post = 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('POST', url, true);
|
|
xhr.setRequestHeader('Content-type', 'application/json');
|
|
xhr.send(JSON.stringify(jsonData));
|
|
};
|