src/cm/media/js/client/c_preferences.js
author gibus
Tue, 30 Nov 2010 09:53:35 +0100
changeset 341 053551f213fb
parent 0 40c8f766c9b8
permissions -rw-r--r--
Coding style for js: expand tabs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     1
// manages user preferences through cookies
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     2
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     3
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     4
// globals used: gConf
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     5
// YUI3 used: cookie
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     6
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     7
Preferences = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
     8
  this.prefs = {} ;  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     9
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    10
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    11
Preferences.prototype = {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    12
  init : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    13
    this._read() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    14
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    15
  //read user preferences from cookie
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    16
  _read : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    17
    for (var key1 in gConf['defaultPrefs']) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    18
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    19
      this.prefs[key1] = {} ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    20
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    21
      for (var key2 in gConf['defaultPrefs'][key1]) {
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    22
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    23
        var val = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    24
        if (key1 == 'user' && (key2 == 'name' || key2 == 'email'))
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    25
          val = CY.Cookie.get("user_" + key2);
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    26
        else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    27
          val = CY.Cookie.getSub(key1, key2);
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    28
        this.prefs[key1][key2] = (val == null) ? gConf['defaultPrefs'][key1][key2] : val ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    29
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    30
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    31
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    32
  // to be used only on values in gDefaultPrefs
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    33
  persist : function(key1, key2, val) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    34
    var cookieOptions = {path:"/", expires:(new Date()).setFullYear(2100,0,1)} ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    35
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    36
    if (key1 == 'user' && (key2 == 'name' || key2 == 'email')) // special case want to get that from cookie set up by python code
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    37
      CY.Cookie.set("user_" + key2, val, cookieOptions);
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    38
    else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    39
      CY.Cookie.setSub(key1, key2, val, cookieOptions);
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    40
    this.prefs[key1][key2] = val ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    41
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    42
  get : function(key1, key2) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    43
    return this.prefs[key1][key2] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    44
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    45
  readDefault : function(key1, key2) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    46
    return gConf['defaultPrefs'][key1][key2] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    47
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    48
  reset : function(entries) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    49
    for (var i = 0; i < entries.length ; i++) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    50
      var key1 = entries[i] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    51
      for (var key2 in gConf['defaultPrefs'][key1]) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    52
        this.persist(key1, key2, gConf['defaultPrefs'][key1][key2]) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    53
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    54
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 0
diff changeset
    55
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    56
}