/** * sessionHandler * * Store all Session utilities in an object * * @return Object */ var sessionHandler = { /** * Get stored variable name with user context * @param {String} storedName */ getName: function (storedName) { return storedName + "_" + PCK_GLOBAL_VARIABLES.userContext; }, /** * Store All sessionStorage Functions */ sessionStorage : { /** * set * @param key * @param value */ set : function (key, value) { sessionStorage.setItem(key + "_" + PCK_GLOBAL_VARIABLES.userContext, JSON.stringify(value)); }, /** * get * @param key * @returns {string} */ get : function (key) { var json; try { json = JSON.parse(sessionStorage.getItem(key + "_" + PCK_GLOBAL_VARIABLES.userContext)); } catch(e) { json = sessionStorage.getItem(key + "_" + PCK_GLOBAL_VARIABLES.userContext); } return json; }, /** * key * @param key */ removeItem: function (key) { sessionStorage.removeItem(key + "_" + PCK_GLOBAL_VARIABLES.userContext); }, /** * Clear sessionStorage */ clear: function () { var aux = Object.keys(sessionStorage); for (var i=0; i<=aux.length-1; i++) { if (aux[i].endsWith("_" + PCK_GLOBAL_VARIABLES.userContext)) sessionStorage.removeItem(aux[i]); } }, }, /** * Store All localStorage Functions */ localStorage : { /** * set * @param key * @param value */ set : function (key, value) { localStorage.setItem(key + "_" + PCK_GLOBAL_VARIABLES.userContext, JSON.stringify(value)); }, /** * get * @param key * @returns {string} */ get : function (key) { var json = ""; try { json = JSON.parse(localStorage.getItem(key + "_" + PCK_GLOBAL_VARIABLES.userContext)); } catch(e) { json = localStorage.getItem(key + "_" + PCK_GLOBAL_VARIABLES.userContext); } return json; }, /** * key * @param key */ removeItem: function(key) { localStorage.removeItem(key + "_" + PCK_GLOBAL_VARIABLES.userContext); }, /** * Clear localStorage */ clear: function() { var aux = Object.keys(localStorage); for (var i=0; i<=aux.length-1; i++) { if (aux[i].endsWith("_" + PCK_GLOBAL_VARIABLES.userContext)) localStorage.removeItem(aux[i]); } }, }, };