Angular selfcheck WIP
authorBill Erickson <berickxx@gmail.com>
Fri, 28 Oct 2016 20:29:15 +0000 (16:29 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 11 Aug 2017 19:20:25 +0000 (15:20 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/circ/selfcheck/index.tt2
Open-ILS/web/js/ui/default/staff/circ/selfcheck/app.js

index 887dbe0..b93c2ae 100644 (file)
@@ -45,12 +45,25 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
           ng-disabled="scanbox.disabled()"
           type="text"/> 
       </div>
-      <div class="col-md-5">
+      <div class="col-md-5"></div>
+    </div>
+    <div class="row">
+      <div class="col-md-3"></div>
+      <div class="col-md-6">
         <div class="alert alert-warning" ng-if="scanbox.already_seen">
           [% l('Barcode already scanned: [_1]', '{{scanbox.already_seen}}') %]
         </div>
-      </div>
-    </div>
+        <div class="alert alert-warning" ng-if="scanbox.error_code">
+          <span ng-if="scanbox.error_code == 'ITEM_NOT_CATALOGED'">
+            [% l(
+              'Item "[_1]" was not found in the system.  Try re-scanning the item.', 
+              '{{scanbox.text}}') 
+            %]
+          </span>
+        </div>
+      </div><!-- col -->
+      <div class="col-md-3"></div>
+    </div><!-- row -->
   </div>
 </div>
 
index afccab4..a174233 100644 (file)
@@ -117,7 +117,8 @@ function($q , $timeout , $window , $location , $timeout , egCore , egConfirmDial
         total_owed_count : 0,
 
         pending_barcode : null, // most recently scanned barcode
-        scanned_barcodes : [], // all scanned barcodes
+        scanned_barcodes : [],  // all scanned barcodes
+        session_circs : [],
     };
 
     // patron_id is set in cases where the patron has not yet been fetched.
@@ -324,6 +325,108 @@ function($q , $timeout , $window , $location , $timeout , egCore , egConfirmDial
         );
     }
 
+    /*
+     * Attempts a copy check out.
+     * Note the checkout behavior in self-check is considerably
+     * different than staff checkout, hence this code does not leverage
+     * egCirc.checkout().  Instead it re-implements a subset of that
+     * behavior here.
+     */
+    service.checkout = function(barcode, options) {
+        if (!options) options = {};
+
+        var method = 'open-ils.circ.checkout.full';
+        if (options.override) method += '.override';
+
+        var params = {
+            copy_barcode : barcode, 
+            patron_id : service.patron.id()
+        };
+
+        return egCore.net.request(
+            'open-ils.circ', method, egCore.auth.token(), params)
+        .then(function(result) {
+            if (!angular.isArray(result)) result = [result];
+
+            var events = result.map(
+                function(e) { return egCore.evt.parse(e) });
+
+            return service.process_checkout_events(events);
+        })
+    }
+
+    service.process_checkout_events = function(events, action) {
+
+        // For the initial checks, only look at the first event returned.
+        // Usually there will only be one, but in some cases where an
+        // override is required, multiple override-able events may 
+        // be returned.
+
+        var first_evt = events[0];
+        var payload = first_evt.payload;
+        var textcode = first_evt.textcode;
+
+        console.log('checkout event: ' + js2JSON(first_evt));
+
+        switch(textcode) {
+
+            case 'SUCCESS':
+                service.set_user_stats();
+                service.session_circs.push(payload);
+                return $q.when();
+                break;
+
+            case 'OPEN_CIRCULATION_EXISTS':
+                if (action == 'checkout') {
+                    // TODO
+                }
+                break;
+
+            default:
+                // TODO: try overridable events
+        }
+
+        // No event handlers have succeeded so far.  Handle blocking 
+        // penalties.
+
+
+        return $q.reject(first_evt);
+
+        /*
+        switch(textcode) {
+
+            case 'MAX_RENEWALS_REACHED' :
+                displayText = dojo.string.substitute(
+                    localeStrings.MAX_RENEWALS, [item]);
+                break;
+
+            case 'ITEM_NOT_CATALOGED' :
+                displayText = dojo.string.substitute(
+                    localeStrings.ITEM_NOT_CATALOGED, [item]);
+                break;
+
+            case 'OPEN_CIRCULATION_EXISTS' :
+                displayText = dojo.string.substitute(
+                    localeStrings.OPEN_CIRCULATION_EXISTS, [item]);
+
+                break;
+
+            default:
+                console.error('Unhandled event ' + result.textcode);
+
+                if (!(displayText = this.failPartMessage(result))) {
+                    if (action == 'checkout' || action == 'renew') {
+                        displayText = dojo.string.substitute(
+                            localeStrings.GENERIC_CIRC_FAILURE, [item]);
+                    } else {
+                        displayText = dojo.string.substitute(
+                            localeStrings.UNKNOWN_ERROR, [result.textcode]);
+                    }
+                }
+        }
+        */
+    }
+
     return service;
 }])
 
@@ -359,6 +462,8 @@ function($scope,  $q,  $location , egCore,  scSvc) {
 
         changed : function($event) {
             delete $scope.scanbox.already_seen;
+            delete $scope.scanbox.error_code;
+            delete $scope.scanbox.error_txt;
             if ($event.keyCode != 13) return; // submit on enter.
             scanbox_handler($scope.scanbox.text);
         }
@@ -446,6 +551,7 @@ function($scope,  $q,  $location , egCore,  scSvc) {
 function($scope,  $q,  $location , egCore,  scSvc) {
     scSvc.new_path_init();
     $scope.scanbox.focus = true;
+    $scope.circs = scSvc.session_circs;
 
     $scope.scanbox.handle_barcode = function() {
         var barcode = scSvc.pending_barcode;
@@ -453,10 +559,23 @@ function($scope,  $q,  $location , egCore,  scSvc) {
 
         console.debug('Processing copy barcode ' + barcode);
 
-        // TODO: checkout item and toss it into the list.
-    
-        // always re-focus after scan
-        $scope.scanbox.focus = true;
+        scSvc.checkout(barcode).then(
+            function() {
+                // checkout succeeded.
+            },
+            function(evt) { // checkout failed
+                if (evt) {
+                    $scope.scanbox.error_code = evt.textcode;
+                    // TODO: result.payload.fail_part
+                    // $scope.scanbox.error_txt;
+                }
+            }
+        )['finally'](
+            function() {
+                // always re-focus after scan
+                $scope.scanbox.focus = true;
+            }
+        );
     }
 
 }])