JBAS-1728 SCKO post-dev repairs
authorBill Erickson <berickxx@gmail.com>
Wed, 21 Jun 2017 18:31:13 +0000 (14:31 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Avoid use of 'this' in nested functions, use the main checkout manager
object ref.

More logout code consolidation.

Move new timeout values to variables declared along the top of the
script.

Remove deprecated function.

More code comments.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/web/js/ui/kcls/circ/selfcheck/selfcheck.js

index 61ddf18..2dbb17b 100644 (file)
@@ -31,6 +31,13 @@ var itemsOutCopy = [];
 var currentItemsOut = [];
 var readyHolds = false;
 
+// Rest on the Thank You page this many ms.
+var thankYouPageTimeout = 5000;
+
+// Ignore duplicate barcode scans that happen within this many ms.
+// Dupe scans that happen farther apart result in a patron warning.
+var dblScanWarnTimeout = 5000;
+
 const SET_BARCODE_REGEX = 'opac.barcode_regex';
 const SET_PATRON_TIMEOUT = 'circ.selfcheck.patron_login_timeout';
 const SET_AUTO_OVERRIDE_EVENTS = 'circ.selfcheck.auto_override_checkout_events';
@@ -529,7 +536,7 @@ SelfCheckManager.prototype.drawCircPage = function() {
           barcodesSeen[scannedBarcode] = barcode;
           var selfckScanbox = document.getElementById('selfckScanBox');
           if(barcodesSeen[scannedBarcode - 1] == barcode ){
-            if(new Date().getTime() - timeScanned < 5000){
+            if(new Date().getTime() - timeScanned < dblScanWarnTimeout){
                 console.log("Date: " + new Date().getTime());
                 console.log("Time scanned: " + timeScanned);
                 console.log(new Date().getTime() - timeScanned);
@@ -1619,50 +1626,18 @@ SelfCheckManager.prototype.printFinesReceipt = function(callback) {
 /**
  * Logout the patron and return to the login page
  */
-SelfCheckManager.prototype.logoutPatronWithEmail = function(email) {
-    var return_url = this.cgi.param('return-to') || location.href;
-    if(email && this.checkouts.length) {
-        this.emailSessionReceipt(
-            function() {
-                location.href = return_url;
-            }
-        );
-    } else {
-        location.href = return_url;
-    }
-}
-
-/**
- * Logout the patron and return to the login page
- */
 SelfCheckManager.prototype.logoutPatron = function(print, email) {
 
-
     var scannedBarcode = 0;
     if(print && this.checkouts.length) {
         progressDialog.show(true); // prevent patron from clicking logout link twice
-        this.printSessionReceipt(
-            function() {
-                openils.Util.show('step4');
-                switchTo('step4');
-                this.processLogout();
-                //location.href = return_url;
-            }
-        );
+        this.printSessionReceipt(selfCheckManager.processLogout);
+
     } else if(email && this.checkouts.length) {
-        this.emailSessionReceipt(
-            function() {
-                openils.Util.show('step4');
-                switchTo('step4');
-                this.processLogout();
-                //location.href = return_url;
-            }
-        );
+        this.emailSessionReceipt(selfCheckManager.processLogout);
+
     } else {
-        openils.Util.show('step4');
-        switchTo('step4');
-        this.processLogout();
-        //location.href = return_url;
+        selfCheckManager.processLogout();
     }
 }
 
@@ -1670,6 +1645,14 @@ SelfCheckManager.prototype.logoutPatron = function(print, email) {
 SelfCheckManager.prototype.processLogout = function() {
     var return_url = this.cgi.param('return-to') || location.href;
 
+    // Display the Thank-You page
+    openils.Util.show('step4');
+    switchTo('step4');
+
+    // NOTE: The variable resets below are likely not necessary, since
+    // the page reloads after a few seconds.  Leaving for now in case
+    // there's something I'm missing.
+
     this.timer = null;
     this.cgi = new openils.CGI();
     this.staff = null; 
@@ -1697,7 +1680,7 @@ SelfCheckManager.prototype.processLogout = function() {
     // dict of org unit settings for "here"
     this.orgSettings = {};
 
-    setTimeout(function() {location.href = return_url;}, 5000);
+    setTimeout(function() {location.href = return_url;}, thankYouPageTimeout);
 }
 
 //TODO: Remove
@@ -1754,4 +1737,6 @@ function swapStyleSheet(sheet1, sheet2) {
   } else {
     currentStyle.setAttribute('href', sheet2);
   }
-}
\ No newline at end of file
+}
+
+