diff --git a/public/js/grocy.js b/public/js/grocy.js index 4da46fe7..2fd70681 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -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,37 @@ 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.UploadFile = function(file, group, fileName, success, error) { var xhr = new XMLHttpRequest(); @@ -286,7 +317,7 @@ Grocy.FrontendHelpers.ShowGenericError = function(message, exception) }); } }); - + console.error(exception); } @@ -310,7 +341,7 @@ $(".user-setting-control").on("change", function() { inputType = element.attr("type").toLowerCase(); } - + if (inputType === "checkbox") { value = element.is(":checked"); @@ -319,9 +350,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 +389,7 @@ ResizeResponsiveEmbeds = function(fillEntireViewport = false) { var maxHeight = $("body").height(); } - + $(".embed-responsive").attr("height", maxHeight.toString() + "px"); } $(window).on('resize', function()