From a512ae01fc7e17385e2d2dd42f53f79ae1f55d3a Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Wed, 1 Apr 2020 16:06:33 +0000 Subject: [PATCH] Bug 24625: Store showLastPatron information using localStorage This patch removes the use of jquery.cookie to store "last patron" information, using localStorage instead. jquery.cookie.js is obsolete. See Bug 24624. localStorage has been chosen as an alternative in this situation because it does not require transmission between the client and the server. See Bug 12410. Because there is no "session only" option with localStorage, additional handling of the showLastPatron data is added to the login page. That takes care of "stale" last patron information if user didn't log out but the session expired for some reason. To test apply the patch and enable the showLastPatron system preference. 1. Load a patron's account for checkout 2. Navigate away from patron-related pages: Perform a catalog search from the search header form and open the detail page from the search results. Confirm that the correct last patron information still shows. 3. Load another patron's account for checkout - There should now be a "Last patron" link in the breadcrumbs bar which links to the patron in step 1. Hovering your mouse over the link should display a tooltip containing the patron's name and card number. - Click the "X" to clear the last patron information. The last patron link should go away. 4. Log out and log back in. The last patron information should be gone. Signed-off-by: David Nind Signed-off-by: Julian Maurice Signed-off-by: Jonathan Druart --- .../intranet-tmpl/prog/en/modules/auth.tt | 2 + .../intranet-tmpl/prog/js/staff-global.js | 52 +++++++++++-------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt index 4d73d26355..acdbeb327e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt @@ -126,6 +126,8 @@ if ( document.location.hash ) { $( '#loginform' ).append( '' ); } + // if showLastPatron information was not cleared during logout, clear it now + removeLastBorrower(); }); [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js index 41db5cf96b..05681d3d8d 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -99,34 +99,32 @@ $.fn.selectTabByID = function (tabID) { $("#catalog-search-dropdown a").toggleClass("catalog-search-dropdown-hover"); }); - if (typeof $.cookie("lastborrowernumber") !== "undefined" && $("#hiddenborrowernumber").val() != $.cookie("lastborrowernumber")) { - $("#lastborrower-window").detach().appendTo("#breadcrumbs"); - $("#lastborrowerlink").show(); - $("#lastborrowerlink").prop("title", $.cookie("lastborrowername") + " (" + $.cookie("lastborrowercard") + ")"); - $("#lastborrowerlink").prop("href", "/cgi-bin/koha/circ/circulation.pl?borrowernumber=" + $.cookie("lastborrowernumber")); - $("#lastborrower-window").css("display", "inline-block"); + if ( localStorage.getItem("lastborrowernumber") ){ + if( $("#hiddenborrowernumber").val() != localStorage.getItem("lastborrowernumber") ) { + $("#lastborrower-window").detach().appendTo("#breadcrumbs"); + $("#lastborrowerlink").show(); + $("#lastborrowerlink").prop("title", localStorage.getItem("lastborrowername") + " (" + localStorage.getItem("lastborrowercard") + ")"); + $("#lastborrowerlink").prop("href", "/cgi-bin/koha/circ/circulation.pl?borrowernumber=" + localStorage.getItem("lastborrowernumber")); + $("#lastborrower-window").css("display", "inline-block"); + } } - if ($("a#logout").length > 0) { - $("a#logout").click(function() { - delCookie("lastborrowernumber"); - delCookie("lastborrowername"); - delCookie("lastborrowercard"); - delCookie("currentborrowernumber"); - }); + + if( !localStorage.getItem("lastborrowernumber") || ( $("#hiddenborrowernumber").val() != localStorage.getItem("lastborrowernumber") && localStorage.getItem("currentborrowernumber") != $("#hiddenborrowernumber").val())) { + if( $("#hiddenborrowernumber").val() ){ + localStorage.setItem("lastborrowernumber", $("#hiddenborrowernumber").val() ); + localStorage.setItem("lastborrowername", $("#hiddenborrowername").val() ); + localStorage.setItem("lastborrowercard", $("#hiddenborrowercard").val() ); + } + } + + if( $("#hiddenborrowernumber").val() ){ + localStorage.setItem("currentborrowernumber", $("#hiddenborrowernumber").val() ); } + $("#lastborrower-remove").click(function() { - delCookie("lastborrowernumber"); - delCookie("lastborrowername"); - delCookie("lastborrowercard"); - delCookie("currentborrowernumber"); + removeLastBorrower(); $("#lastborrower-window").hide(); }); - if (typeof $.cookie("lastborrowernumber") === "undefined" || ($("#hiddenborrowernumber").val() != $.cookie("lastborrowernumber") && $.cookie("currentborrowernumber") != $("#hiddenborrowernumber").val())) { - $.cookie("lastborrowernumber", $("#hiddenborrowernumber").val(), { path: "/" }); - $.cookie("lastborrowername", $("#hiddenborrowername").val(), { path: "/" }); - $.cookie("lastborrowercard", $("#hiddenborrowercard").val(), { path: "/" }); - } - $.cookie("currentborrowernumber", $("#hiddenborrowernumber").val(), { path: "/" }); /* Search results browsing */ /* forms with action leading to search */ @@ -144,6 +142,13 @@ $.fn.selectTabByID = function (tabID) { }); +function removeLastBorrower(){ + localStorage.removeItem("lastborrowernumber"); + localStorage.removeItem("lastborrowername"); + localStorage.removeItem("lastborrowercard"); + localStorage.removeItem("currentborrowernumber"); +} + // http://jennifermadden.com/javascript/stringEnterKeyDetector.html function checkEnter(e){ //e is event object passed from function invocation var characterCode; // literal character code will be stored in this variable @@ -171,6 +176,7 @@ function logOut(){ delBasket('main', true); } clearHoldFor(); + removeLastBorrower(); } function openHelp(){ -- 2.39.5