if a patron barcode regex is configured and a patron barcode is scanned into the...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 31 Jul 2008 16:44:18 +0000 (16:44 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 31 Jul 2008 16:44:18 +0000 (16:44 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_2@10224 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/extras/selfcheck/selfcheck.js

index 61140b3..dd84dd1 100644 (file)
@@ -19,6 +19,7 @@
 ----------------------------------------------------------------- */
 
 var STAFF_SES_PARAM = 'ses';
+var PATRON_BARCODE_COOKIE = 'pbcc';
 var patron = null
 var itemBarcode = null;
 var itemsOutTemplate = null;
@@ -31,6 +32,7 @@ var printTemplate;
 var successfulItems = {};
 var scanTimeout = 800;
 var scanTimeoutId;
+var patronBarcodeRegex;
 
 
 function selfckInit() {
@@ -43,6 +45,9 @@ function selfckInit() {
     patronTimeout = (t) ? parseInt(t) * 1000 : patronTimeout;
     */
 
+    var reg = fetchOrgSettingDefault(globalOrgTree.id(), 'opac.barcode_regex');
+    if(reg) patronBarcodeRegex = new RegExp(reg);
+
     if(!staff) {
         // should not happen when behind the proxy
         return alert('Staff must login');
@@ -69,9 +74,20 @@ function selfckInit() {
     printTemplate = printWrapper.removeChild($n(printWrapper, 'selfck-print-items-template'));
     itemsOutTemplate = $('selfck-items-out-tbody').removeChild($('selfck-items-out-row'));
 
+    selfckTryPatronCookie();
+
 //    selfckMkDummyCirc(); // testing only
 }
 
+function selfckTryPatronCookie() {
+    var pb = cookieManager.read(PATRON_BARCODE_COOKIE);
+    if(pb) {
+        cookieManager.write(PATRON_BARCODE_COOKIE, '');
+        $('selfck-patron-login-input').value = pb;
+        selfckPatronLogin();
+    }
+}
+
 
 function selfckItemBarcodeKeypress(evt) {
     if(userPressedEnter(evt)) {
@@ -165,6 +181,21 @@ function selfckPatronLogin(barcode) {
 }
 
 /**
+  * If a user barcode was scanned into the item barcode
+  * input, log out the current user and log in the new user
+  */
+function selfckCheckPatronBarcode(itemBc) {
+    if(patronBarcodeRegex) {
+        if(itemBc.match(patronBarcodeRegex)) {
+            cookieManager.write(PATRON_BARCODE_COOKIE, itemBc, -1);
+            selfckLogoutPatron();
+            return true;
+        }
+    }
+    return false;
+}
+
+/**
   * Sends the checkout request
   */
 function selfckCheckout() {
@@ -179,6 +210,9 @@ function selfckCheckout() {
     itemBarcode = $('selfck-item-barcode-input').value;
     if(!itemBarcode) return;
 
+    if(selfckCheckPatronBarcode(itemBarcode))
+        return;
+
     if (itemBarcode in successfulItems) {
         selfckShowMsgNode({textcode:'dupe-barcode'});
         $('selfck-item-barcode-input').select();