Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/PhieF/CarnetElectron.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhie <phie@phie.ovh>2019-09-24 18:35:57 +0300
committerPhie <phie@phie.ovh>2019-09-24 18:35:57 +0300
commitbab87956fc88b559af0f1239235c3f6c4dcff132 (patch)
treed83477b24824e07c6bc1289cfa5e74524e3a43df /settings
parentc134823c5cbde41441308e9939376360e385b1f3 (diff)
using settings helper for ui + settings cache
Diffstat (limited to 'settings')
-rw-r--r--settings/ui_settings_helper.js52
1 files changed, 45 insertions, 7 deletions
diff --git a/settings/ui_settings_helper.js b/settings/ui_settings_helper.js
index d8c8ce9..da19310 100644
--- a/settings/ui_settings_helper.js
+++ b/settings/ui_settings_helper.js
@@ -3,25 +3,63 @@ class UISettingsHelper {
static getInstance() {
if (UISettingsHelper.instance == undefined)
UISettingsHelper.instance = new UISettingsHelper();
+ return UISettingsHelper.instance
}
loadSettings(callback) {
- RequestBuilder.sRequestBuilder.get("settings/ui", (data) {
- this.settings = JSON.parse(data)
- })
- this.settings = JSON.parse('"sort-by":"custom"}')
+ if (this.settings == undefined) {
+ this.store = new Store();
+ try {
+ this.settings = JSON.parse(String(this.store.get("ui_settings_cache")))
+ callback(this.settings, true)
+ } catch (e) {
+ }
+ RequestBuilder.sRequestBuilder.get("settings/ui", function (error, data) {
+ console.oldlog("settings loaded " + data)
+
+ try {
+ data = JSON.parse(data)
+ } catch (e) {
+ data = {}
+ }
+ UISettingsHelper.instance.settings = data != null ? data : {}
+ UISettingsHelper.instance.loadDefaultSettings()
+ UISettingsHelper.instance.store.set("ui_settings_cache", JSON.stringify(UISettingsHelper.instance.settings))
+ callback(UISettingsHelper.instance.settings, false)
+ })
+ }
+ else
+ callback(this.settings, false)
}
set(key, value) {
- this.settings[key] = value;
+ if (this.settings != undefined) {
+ this.settings[key] = value;
+ }
}
get(key) {
- return this.settings[key]
+ if (this.settings != undefined)
+ return this.settings[key]
+ }
+
+ setDefaultSetting(key, value) {
+ if (this.settings[key] == undefined)
+ this.settings[key] = value
}
+ loadDefaultSettings() {
+ this.setDefaultSetting('sort_by', 'default')
+ this.setDefaultSetting('reversed', false)
+ this.setDefaultSetting('start_page', 'recent')
+ }
+
+
postSettings() {
+ this.store.set("ui_settings_cache", JSON.stringify(this.settings))
RequestBuilder.sRequestBuilder.post("settings/ui", {
- settings: this.settings
+ jsonSettings: JSON.stringify(this.settings)
+ }, function () {
+
})
}
} \ No newline at end of file