JBAS-822 Adopt stock login timer logic
authorBill Erickson <berickxx@gmail.com>
Wed, 22 Jul 2015 15:55:41 +0000 (11:55 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
In prep for LP#1474051, which modifies the timeout behavior, start using
(as much as possible) the stock login timer code.  This will ease
migration when the logout warning code is merged in.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/openils/var/templates_kcls/circ/selfcheck/main.tt2
Open-ILS/web/js/ui/kcls/circ/selfcheck/selfcheck.js

index 64ddaec..9011b6e 100644 (file)
@@ -6,6 +6,7 @@
 <div id="selfcheck-main">
 <script type="text/javascript">
 function switchTo(str,subpage) {
+    selfckResetTimer(); // reset login timer
        var pages = [];
        var sidebarLinks = [];
        pages['step0'] = document.getElementById('step0');
index e4655ff..191a919 100644 (file)
@@ -11,12 +11,15 @@ dojo.require('openils.widget.OrgUnitFilteringSelect');
 
 dojo.requireLocalization('openils.circ', 'selfcheck');
 var localeStrings = dojo.i18n.getLocalization('openils.circ', 'selfcheck');
+
+// set patron timeout default
+var patronTimeout = 180000; /* 3 minutes */
+var timerId = null;
+
 var selfCheckMgr;
 var itemsOutCirc = [];
 var itemsOutMod = [];
 var itemsOutCopy = [];
-var TIMEOUT = 60; // logout timer
-
 
 const SET_BARCODE_REGEX = 'opac.barcode_regex';
 const SET_PATRON_TIMEOUT = 'circ.selfcheck.patron_login_timeout';
@@ -30,6 +33,26 @@ const SET_CC_PAYMENT_ALLOWED = 'credit.payments.allow';
 // This setting only comes into play if COPY_NOT_AVAILABLE is in the SET_AUTO_OVERRIDE_EVENTS list
 const SET_BLOCK_CHECKOUT_ON_COPY_STATUS = 'circ.selfcheck.block_checkout_on_copy_status';
 
+// set before the login dialog is rendered
+openils.User.default_login_agent = 'selfcheck';
+
+// start the logout timer
+function selfckStartTimer() {
+    timerId = setTimeout(
+        function() {
+            SelfCheckManager.prototype.logoutPatron();
+        },
+        patronTimeout
+    );
+}
+
+// reset the logout timer
+function selfckResetTimer() {
+    console.log('resetting timer');
+    clearTimeout(timerId);
+    selfckStartTimer();
+}
+
 function SelfCheckManager() {
        selfCheckMgr = this;
        switchTo('step1');
@@ -83,11 +106,6 @@ function SelfCheckManager() {
     this.initPrinter();
 }
 
-SelfCheckManager.prototype.keepMeLoggedIn = function() {
-       //alert(this.timer);
-       if(this.timer) try {clearTimeout(this.timer)} catch(e){}
-       this.timer = setTimeout('selfCheckMgr.logoutPatron();', TIMEOUT*1000);
-}
 
 /**
  * Fetch the org-unit settings, initialize the display, etc.
@@ -118,7 +136,6 @@ SelfCheckManager.prototype.init = function() {
             switchTo('step3','step3c');
                        openils.Util.hide('oils-selfck-fines-tbody');
                        openils.Util.show('pay_fines');
-                       self.keepMeLoggedIn();
             self.drawPayFinesPage(
                 self.patron,
                 self.getSelectedFinesTotal(),
@@ -279,6 +296,9 @@ SelfCheckManager.prototype.loadOrgSettings = function() {
 
     if(settings[SET_BARCODE_REGEX]) 
         this.patronBarcodeRegex = new RegExp(settings[SET_BARCODE_REGEX].value);
+
+    if(settings[SET_PATRON_TIMEOUT])
+        patronTimeout = parseInt(settings[SET_PATRON_TIMEOUT].value) * 1000;
 }
 
 SelfCheckManager.prototype.drawLoginPage = function() {
@@ -315,6 +335,9 @@ SelfCheckManager.prototype.drawLoginPage = function() {
  * Login the patron.  
  */
 SelfCheckManager.prototype.loginPatron = function(barcode_or_usrname, passwd) {
+
+    // reset timeout
+    selfckResetTimer();
        
     //if(this.orgSettings[SET_PATRON_PASSWORD_REQUIRED]) { // password always reqired, per KCLS - fail safe
         if(!passwd) {
@@ -471,7 +494,6 @@ SelfCheckManager.prototype.updateScanBox = function(args) {
  *  Sets up the checkout/renewal interface
  */
 SelfCheckManager.prototype.drawCircPage = function() {
-       this.keepMeLoggedIn();
     openils.Util.show('oils-selfck-circ-tbody', 'table-row-group');
        switchTo('step3');
 
@@ -528,7 +550,6 @@ SelfCheckManager.prototype.updateFinesSummary = function() {
 
 
 SelfCheckManager.prototype.drawItemsOutPage = function() {
-       this.keepMeLoggedIn();
        switchTo('step3','step3d');
        
        // Reset items checked out in case it changed
@@ -594,6 +615,9 @@ SelfCheckManager.prototype.goToTab = function(name) {
     openils.Util.hide('oils-selfck-holds-page');
     openils.Util.hide('oils-selfck-circ-page');
     openils.Util.hide('oils-selfck-pay-fines-link');
+
+    // reset timeout
+    selfckResetTimer();
     
     switch(name) {
         case 'checkout':
@@ -616,7 +640,9 @@ SelfCheckManager.prototype.goToTab = function(name) {
 
 
 SelfCheckManager.prototype.printList = function(which) {
-       this.keepMeLoggedIn();
+    // reset timeout
+    selfckResetTimer();
+
     switch(which) {
         case 'checkout':
             this.printSessionReceipt();
@@ -687,7 +713,6 @@ SelfCheckManager.prototype.updateCircSummary = function(increment) {
 
 
 SelfCheckManager.prototype.drawHoldsPage = function(bool) {
-       this.keepMeLoggedIn();
        if(bool) switchTo('step3','step3f'); else switchTo('step3','step3e');
 
     this.holdTbody = dojo.byId('oils-selfck-hold-tbody');
@@ -737,7 +762,6 @@ SelfCheckManager.prototype.drawHoldsPage = function(bool) {
  * Fetch and add a single hold to the list of holds
  */
 SelfCheckManager.prototype.drawHolds = function(holds) {
-       //this.keepMeLoggedIn();
     this.holds = holds;
     progressDialog.hide();
        
@@ -771,7 +795,6 @@ SelfCheckManager.prototype.drawHolds = function(holds) {
 
 
 SelfCheckManager.prototype.drawFinesPage = function() {
-       this.keepMeLoggedIn();
     // TODO add option to hid scanBox
     // this.updateScanBox(...)
 
@@ -910,7 +933,6 @@ SelfCheckManager.prototype.checkin = function(barcode, abortTransit) {
  * out to the patron, redirect to renew()
  */
 SelfCheckManager.prototype.checkout = function(barcode, override) {
-       this.keepMeLoggedIn();
     this.prevCirc = null;
 
     if(!barcode) {
@@ -1491,7 +1513,6 @@ SelfCheckManager.prototype.logoutPatron = function(print) {
 
 
 function checkLogin() {
-       selfCheckMgr.keepMeLoggedIn();
        if(selfCheckMgr.orgSettings[SET_PATRON_PASSWORD_REQUIRED]) {
                switchTo('step2');
                try{dojo.byId('patron-login-password').focus();}catch(e){}