mirror of
https://github.com/grocy/grocy.git
synced 2026-04-09 05:56:15 +02:00
Defer SaveUserSettings API calls until after Page 'load' event
This commit is contained in:
parent
4cde333d35
commit
05bbb2656b
61
js/grocy.js
61
js/grocy.js
|
|
@ -70,6 +70,7 @@ class GrocyClass
|
||||||
strings = this.Api.LoadLanguageSync("en");
|
strings = this.Api.LoadLanguageSync("en");
|
||||||
}
|
}
|
||||||
Object.assign(strings.messages[""], config.GettextPo.messages[""]);
|
Object.assign(strings.messages[""], config.GettextPo.messages[""]);
|
||||||
|
this.strings = strings;
|
||||||
this.Translator = new Translator(strings);
|
this.Translator = new Translator(strings);
|
||||||
|
|
||||||
this.FrontendHelpers = new GrocyFrontendHelpers(this, this.Api);
|
this.FrontendHelpers = new GrocyFrontendHelpers(this, this.Api);
|
||||||
|
|
@ -85,6 +86,21 @@ class GrocyClass
|
||||||
{
|
{
|
||||||
self.Nightmode.Initialize();
|
self.Nightmode.Initialize();
|
||||||
self.Nightmode.StartWatchdog();
|
self.Nightmode.StartWatchdog();
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('load', function()
|
||||||
|
{
|
||||||
|
if (self.documentReady) return;
|
||||||
|
|
||||||
|
// preload views
|
||||||
|
self.documentReady = true;
|
||||||
|
var element = self.preloadViews.pop();
|
||||||
|
while (element !== undefined)
|
||||||
|
{
|
||||||
|
self.PreloadView(element.viewName, element.loadCss, element.cb);
|
||||||
|
|
||||||
|
element = self.preloadViews.pop();
|
||||||
|
}
|
||||||
|
|
||||||
// DB Changed Handling
|
// DB Changed Handling
|
||||||
if (self.UserId !== -1)
|
if (self.UserId !== -1)
|
||||||
|
|
@ -107,21 +123,6 @@ class GrocyClass
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('load', function()
|
|
||||||
{
|
|
||||||
if (self.documentReady) return;
|
|
||||||
|
|
||||||
// preload views
|
|
||||||
self.documentReady = true;
|
|
||||||
var element = self.preloadViews.pop();
|
|
||||||
while (element !== undefined)
|
|
||||||
{
|
|
||||||
self.PreloadView(element.viewName, element.loadCss, element.cb);
|
|
||||||
|
|
||||||
element = self.preloadViews.pop();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// save the config
|
// save the config
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
|
|
@ -176,24 +177,27 @@ class GrocyClass
|
||||||
|
|
||||||
translate(text, ...placeholderValues)
|
translate(text, ...placeholderValues)
|
||||||
{
|
{
|
||||||
if (this.Mode === "dev")
|
this.logTranslation(text);
|
||||||
{
|
|
||||||
var text2 = text;
|
|
||||||
this.Api.Post('system/log-missing-localization', { "text": text2 });
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.Translator.__(text, ...placeholderValues)
|
return this.Translator.__(text, ...placeholderValues)
|
||||||
}
|
}
|
||||||
translaten(number, singularForm, pluralForm)
|
translaten(number, singularForm, pluralForm)
|
||||||
{
|
{
|
||||||
if (this.Mode === "dev")
|
this.logTranslation(singularForm);
|
||||||
{
|
|
||||||
var singularForm2 = singularForm;
|
|
||||||
this.Api.Post('system/log-missing-localization', { "text": singularForm2 });
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.Translator.n__(singularForm, pluralForm, number, number)
|
return this.Translator.n__(singularForm, pluralForm, number, number)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logTranslation(text)
|
||||||
|
{
|
||||||
|
if (this.Mode === "dev")
|
||||||
|
{
|
||||||
|
if (!(text in this.strings.messages[""]))
|
||||||
|
{
|
||||||
|
this.Api.Post('system/log-missing-localization', { "text": text });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FormatUrl(relativePath)
|
FormatUrl(relativePath)
|
||||||
{
|
{
|
||||||
return this.BaseUrl.replace(/\/$/, '') + relativePath;
|
return this.BaseUrl.replace(/\/$/, '') + relativePath;
|
||||||
|
|
@ -399,6 +403,11 @@ class GrocyClass
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegisterUnload(cb)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Unload()
|
Unload()
|
||||||
{
|
{
|
||||||
return; // root grocy instances never get unloaded.
|
return; // root grocy instances never get unloaded.
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,33 @@ class GrocyFrontendHelpers
|
||||||
this.dataTables = [];
|
this.dataTables = [];
|
||||||
|
|
||||||
this.InitDropdowns();
|
this.InitDropdowns();
|
||||||
|
|
||||||
|
this.deferredPutCalls = [];
|
||||||
|
var self = this;
|
||||||
|
window.addEventListener('load', function()
|
||||||
|
{
|
||||||
|
if (self.Grocy.documentReady && self.deferredPutCalls.length == 0) return;
|
||||||
|
|
||||||
|
// save user settings
|
||||||
|
var putcall = self.deferredPutCalls.pop();
|
||||||
|
while (putcall !== undefined)
|
||||||
|
{
|
||||||
|
self.Api.Put(putcall.uri, putcall.data,
|
||||||
|
function(result)
|
||||||
|
{
|
||||||
|
// Nothing to do...
|
||||||
|
},
|
||||||
|
function(xhr)
|
||||||
|
{
|
||||||
|
if (!xhr.statusText.isEmpty())
|
||||||
|
{
|
||||||
|
this.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
putcall = self.deferredPutCalls.pop();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_ApplyTemplate(data, template)
|
_ApplyTemplate(data, template)
|
||||||
|
|
@ -194,7 +221,15 @@ class GrocyFrontendHelpers
|
||||||
|
|
||||||
var jsonData = {};
|
var jsonData = {};
|
||||||
jsonData.value = value;
|
jsonData.value = value;
|
||||||
this.Api.Put('user/settings/' + settingsKey, jsonData,
|
|
||||||
|
let api = 'user/settings/' + settingsKey;
|
||||||
|
if (!this.Grocy.documentReady)
|
||||||
|
{
|
||||||
|
this.deferredPutCalls.push({ uri: api, data: jsonData });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Api.Put(api, jsonData,
|
||||||
function(result)
|
function(result)
|
||||||
{
|
{
|
||||||
// Nothing to do...
|
// Nothing to do...
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user