adding a semicolon... yay!
[cxgn-jslib.git] / CXGN / DeveloperSettings.js
blob7492366852ad9134deef9c3d576ac7f3cf007925
1 /*
3 =head1 CXGN.DeveloperSettings
5  Manages the cookie and key/values for developer settings, on the client side
6  This is a singleton object
8 =head1 Functions
10 =cut
14 JSAN.use('CXGN.Cookie');
16 DeveloperSettings = window.DeveloperSettings || {};
18 var DeveloperSettings = {
19         data: new Object,
20         _init: function() {
21                 DeveloperSettings.parse(Cookie.get('developer_settings'));
22         },
25 =head2 parse( cookie_string )
27  Given a cookie_string, parses out key/value relationships and sets
28  them to the object (assc. array) DeveloperSettings.data
30 =cut
33         parse: function(cookie_string) {
34                 cookie_string = decodeURIComponent(cookie_string);
35                 var kvps = cookie_string.split(':');
36                 for(var j = 0; j < kvps.length; j++){
37                         var kv = kvps[j].split('=');
38                         var k = kv[0];
39                         var v = kv[1];
40                         DeveloperSettings.data[k] = v;
41                 }
42         },
45 =head2 build()
47  Build and returncookie string from DeveloperSettings.data object (assc. array)
49 =cut
52         build: function() {
53                 var data = DeveloperSettings.data;
54                 var cookie_string = '';
55                 var i = 0;
56                 for(key in data){
57                         if(i>0) cookie_string += ":";
58                         cookie_string += encodeURIComponent(key) + "=" + encodeURIComponent(data[key])
59                         i++;
60                 }
61                 return encodeURIComponent(cookie_string);
62         },
63                 
66 =head2 save()
68 Calls build() and sets this to the cookie
70 =cut
73         save: function() {
74                 Cookie.set('developer_settings', DeveloperSettings.build(), 1000);      
75         },
76 /* 
78 =head2 getValue(key)
80  Gets the current value for the key in the associative array
82 =cut
85     getValue: function(key) {
86                 return DeveloperSettings.data[key];
87         },
88 /* 
90 =head2 setValue(key, value)
92  Given a key and value, sets the associative array
94 =cut
97         setValue: function(key,value) {
98                 DeveloperSettings.data[key] = value;
99         }
102 DeveloperSettings._init();