From: Galen Charlton Date: Thu, 8 Oct 2015 01:05:48 +0000 (+0000) Subject: webstaff: start teaching egHatch about sessionStorage X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e5659abd8176bbb318611ac2d7acc32a46fc65d8;p=working%2FEvergreen.git webstaff: start teaching egHatch about sessionStorage This patch adds getSessionItem(), setSessionItem(), and removeSessionItem(), which are all wrappers around $window.sessionStorage. This is done to support settings whose values are sticky for the duration of a session, which at present is the lifetime of the browser tab. An alternative would be using session cookies; some user testing is needed to see which lifetime makes the most sense. Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/web/js/ui/default/staff/services/hatch.js b/Open-ILS/web/js/ui/default/staff/services/hatch.js index 9e41d914f2..0b8935b62b 100644 --- a/Open-ILS/web/js/ui/default/staff/services/hatch.js +++ b/Open-ILS/web/js/ui/default/staff/services/hatch.js @@ -301,6 +301,12 @@ angular.module('egCoreMod') return JSON.parse(val); } + service.getSessionItem = function(key) { + var val = $window.sessionStorage.getItem(key); + if (val == null) return; + return JSON.parse(val); + } + service.setItem = function(key, value) { var str = JSON.stringify(value); return service.setRemoteItem(key, str)['catch']( @@ -333,6 +339,12 @@ angular.module('egCoreMod') $window.localStorage.setItem(key, jsonified); } + service.setSessionItem = function(key, value, jsonified) { + if (jsonified === undefined ) + jsonified = JSON.stringify(value); + $window.sessionStorage.setItem(key, jsonified); + } + // appends the value to the existing item stored at key. // If not item is found at key, this behaves just like setItem() service.appendItem = function(key, value) { @@ -391,6 +403,10 @@ angular.module('egCoreMod') $window.localStorage.removeItem(key); } + service.removeSessionItem = function(key) { + $window.sessionStorage.removeItem(key); + } + // if set, prefix limits the return set to keys starting with 'prefix' service.getKeys = function(prefix) { return service.getRemoteKeys(prefix)['catch'](