From 8172fdb25f075c017bb6bd32a121d8b76b274c9b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 18 Mar 2011 14:47:51 +0100 Subject: [PATCH] [IMP] implement local storage of session id and uid bzr revid: xmo@openerp.com-20110318134751-41mhkir4u5qb0ez1 --- addons/base/static/openerp/js/base_chrome.js | 76 ++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/addons/base/static/openerp/js/base_chrome.js b/addons/base/static/openerp/js/base_chrome.js index 0870f92a38c..52c3bfeea4a 100644 --- a/addons/base/static/openerp/js/base_chrome.js +++ b/addons/base/static/openerp/js/base_chrome.js @@ -135,10 +135,85 @@ openerp.base.Session = openerp.base.BasicController.extend({ this.password = ""; this.uid = false; this.session_id = false; + this.load_local(); this.module_list = []; this.module_loaded = {"base": true}; this.context = {}; }, + /** + * Reloads uid and session_id from local storage, if they exist + */ + load_local: function () { + this.uid = this.get_cookie('uid'); + this.session_id = this.get_cookie('session_id'); + }, + /** + * Saves the session id and uid locally + */ + save_local: function () { + this.set_local('uid', this.uid); + this.set_local('session_id', this.session_id); + }, + // TODO: clear_local + + /** + * Retrieves and return the value indexed by the key name from local + * storage, if it finds it. + * @param name the name of the value to get + */ + get_local: function (name) { + if(window.localStorage) { + return localStorage.getItem(name); + } + return this.get_cookie(name); + }, + /** + * Sets the value at the key name in local storage. + * + * The value has to be a String. + * + * @param name key to set the value at + * @param value value to store + */ + set_local: function (name, value) { + if(window.localStorage) { + localStorage.setItem(name, String(value)); + } + return this.set_cookie(name, value); + }, + + /** + * Fetches a cookie stored by an openerp session + * + * @param name the cookie's name + */ + get_cookie: function (name) { + var nameEQ = this.element_id + '|' + name + '='; + var cookies = document.cookie.split(';'); + for(var i=0; i