From 1abdc5e561a26136039117751f673d8e914c55de Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 8 Oct 2015 01:05:48 +0000 Subject: [PATCH] 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 Signed-off-by: Kathy Lussier --- .../web/js/ui/default/staff/services/hatch.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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']( -- 2.43.2