@@ -24,12 +24,13 @@ javaxt.express.UserPreferences = function(callback, scope) {
2424 this . refresh = function ( callback , scope ) {
2525 get ( "UserPreferences?fields=key,value&format=json" , {
2626 success : function ( text ) {
27+ preferences = { } ;
2728 JSON . parse ( text ) . forEach ( ( r ) => {
2829 preferences [ r . key ] = r . value ;
2930 } ) ;
3031
3132 if ( ! scope ) scope = me ;
32- callback . apply ( scope , [ preferences ] ) ;
33+ callback . apply ( scope , [ clone ( preferences ) ] ) ;
3334 } ,
3435 failure : function ( ) {
3536
@@ -46,7 +47,8 @@ javaxt.express.UserPreferences = function(callback, scope) {
4647 this . get = function ( key ) {
4748 var val = preferences [ key . toLowerCase ( ) ] ;
4849 if ( typeof val === 'undefined' ) return null ;
49- return val ;
50+ if ( isObject ( val ) ) return clone ( val ) ;
51+ else return val ;
5052 } ;
5153
5254
@@ -63,10 +65,11 @@ javaxt.express.UserPreferences = function(callback, scope) {
6365 if ( preferences [ key ] === value ) return ;
6466
6567
66- if ( silent === true ) {
68+ if ( isObject ( value ) ) value = clone ( value ) ;
6769
68- preferences [ key ] = value ;
6970
71+ if ( silent === true ) {
72+ preferences [ key ] = value ;
7073 }
7174 else {
7275
@@ -89,8 +92,32 @@ javaxt.express.UserPreferences = function(callback, scope) {
8992 } ;
9093
9194
95+ //**************************************************************************
96+ //** isObject
97+ //**************************************************************************
98+ /** Returns true if the given value is an object
99+ */
100+ var isObject = function ( value ) {
101+ return value != null && typeof value == 'object' && ! Array . isArray ( value ) ;
102+ } ;
103+
104+
105+ //**************************************************************************
106+ //** clone
107+ //**************************************************************************
108+ /** Returns a clone of a given object
109+ */
110+ var clone = function ( json ) {
111+ return JSON . parse ( JSON . stringify ( json ) ) ;
112+ } ;
113+
114+
115+ //**************************************************************************
116+ //** Utils
117+ //**************************************************************************
92118 var post = javaxt . dhtml . utils . post ;
93119 var get = javaxt . dhtml . utils . get ;
94120
121+
95122 this . refresh ( callback , scope ) ;
96123} ;
0 commit comments