Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 21st, 2010 | Syntax: JavaScript | Size: 2.30 KB | Hits: 60 | Expires: Never
Copy text to clipboard
  1. /* Copyright 2009 Palm, Inc.  All rights reserved. */
  2. var DataManager = Class.create({
  3.     initialize: function() {
  4.         this.initCookie();
  5.     },
  6.  
  7.     initCookie: function() {
  8.         this.cookieVersion = 3;
  9.         this.cookieContainer = new Mojo.Model.Cookie("facebook");
  10.         this.cookie = this.cookieContainer.get();
  11.  
  12.         if(!this.cookie) {
  13.             this.cookie = {
  14.                 version: this.cookieVersion,
  15.                 isFirstLaunch: true,
  16.                 ignoreUpgrade: false,
  17.                 uid: null,
  18.                 username: "",
  19.                 photo: null,
  20.                 accountTag: null
  21.             };
  22.             this.saveCookie();
  23.         } else if(this.cookie.version != this.cookieVersion) {
  24.             // TODO: Handle cookie migration here
  25.         }
  26.     },
  27.  
  28.     setIsFirstLaunch: function(isFirstLaunch) {
  29.         this.cookie.isFirstLaunch = isFirstLaunch;
  30.         if(isFirstLaunch) {
  31.             this.setAccountTag(null);
  32.         }
  33.         this.saveCookie();
  34.     },
  35.  
  36.     isFirstLaunch: function() {
  37.         if (this.cookie.isFirstLaunch) {
  38.             return true;
  39.         }
  40.         return false;
  41.     },
  42.  
  43.     setIgnoreUpgrade: function(ignore) {
  44.         this.cookie.ignoreUpgrade = ignore;
  45.         this.saveCookie();
  46.     },
  47.  
  48.     isIgnoreUpgrade: function() {
  49.         return !!this.cookie.ignoreUpgrade;
  50.     },
  51.  
  52.     setUID: function(uid) {
  53.         this.cookie.uid = uid;
  54.         this.saveCookie();
  55.     },
  56.  
  57.     getUID: function() {
  58.         return this.cookie.uid;
  59.     },
  60.  
  61.     setUsername: function(name) {
  62.         this.cookie.username = name;
  63.         this.saveCookie();
  64.     },
  65.  
  66.     getUsername: function() {
  67.         return this.cookie.username;
  68.     },
  69.  
  70.     setPhoto: function(photoURL) {
  71.         this.cookie.photo = photoURL;
  72.         this.saveCookie();
  73.     },
  74.  
  75.     getPhoto: function() {
  76.         return this.cookie.photo;
  77.     },
  78.  
  79.     setAccountTag: function(accountTag) {
  80.         this.clearStreamBlob = true;
  81.         this.setPhoto("");
  82.         this.setUID(null);
  83.         this.cookie.accountTag = accountTag;
  84.         this.saveCookie();
  85.     },
  86.  
  87.     getAccountTag: function() {
  88.         return this.cookie.accountTag;
  89.     },
  90.  
  91.     // Private
  92.     saveCookie: function() {
  93.         this.cookieContainer.put(this.cookie);
  94.     }
  95. });