2013-06-17 17:54:43 +00:00
|
|
|
(function () {
|
|
|
|
var ns = $.namespace("pskl");
|
|
|
|
|
|
|
|
ns.UserSettings = {
|
|
|
|
|
2013-06-17 19:03:22 +00:00
|
|
|
SHOW_GRID : 'SHOW_GRID',
|
2013-06-17 21:10:35 +00:00
|
|
|
CANVAS_BACKGROUND : 'CANVAS_BACKGROUND',
|
2013-06-17 17:54:43 +00:00
|
|
|
|
|
|
|
KEY_TO_DEFAULT_VALUE_MAP_ : {
|
2013-06-17 21:10:35 +00:00
|
|
|
'SHOW_GRID' : false,
|
|
|
|
'CANVAS_BACKGROUND' : 'medium-canvas-background'
|
2013-06-17 17:54:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2013-06-17 19:03:22 +00:00
|
|
|
cache_ : {},
|
2013-06-17 17:54:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Static method to access a user defined settings value ot its default
|
|
|
|
* value if not defined yet.
|
|
|
|
*/
|
|
|
|
get : function (key) {
|
|
|
|
this.checKeyValidity_(key);
|
|
|
|
if (key in this.cache_) {
|
2013-06-17 19:23:21 +00:00
|
|
|
return this.cache_[key];
|
2013-06-17 17:54:43 +00:00
|
|
|
}
|
|
|
|
return this.get_(key);
|
|
|
|
},
|
|
|
|
|
|
|
|
set : function (key, value) {
|
|
|
|
this.checKeyValidity_(key);
|
|
|
|
this.cache_[key] = value;
|
2013-06-17 18:24:27 +00:00
|
|
|
this.set_(key, value);
|
|
|
|
|
|
|
|
$.publish(Events.USER_SETTINGS_CHANGED, [key, value]);
|
2013-06-17 17:54:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
get_ : function(key) {
|
|
|
|
var value = window.localStorage[key];
|
|
|
|
if (value === undefined) {
|
|
|
|
value = this.KEY_TO_DEFAULT_VALUE_MAP_[key];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var entry = JSON.parse(value);
|
|
|
|
value = entry.jsonValue;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
set_ : function(key, value) {
|
|
|
|
var entry = { 'jsonValue': value };
|
|
|
|
window.localStorage[key] = JSON.stringify(entry);
|
|
|
|
},
|
|
|
|
|
2013-06-17 19:03:22 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2013-06-17 17:54:43 +00:00
|
|
|
checKeyValidity_ : function(key) {
|
|
|
|
if(key in this.KEY_TO_DEFAULT_VALUE_MAP_) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-17 19:03:22 +00:00
|
|
|
console.log("UserSettings key <"+ key +"> not find in supported keys.");
|
2013-06-17 17:54:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|