From d1fa45cbe9e60ee2a65d8fce4780e907a450c1b5 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 28 Oct 2016 16:29:15 -0400 Subject: [PATCH] Angular selfcheck WIP Signed-off-by: Bill Erickson --- .../src/templates/staff/circ/selfcheck/index.tt2 | 19 ++- .../web/js/ui/default/staff/circ/selfcheck/app.js | 129 ++++++++++++++++++++- 2 files changed, 140 insertions(+), 8 deletions(-) diff --git a/Open-ILS/src/templates/staff/circ/selfcheck/index.tt2 b/Open-ILS/src/templates/staff/circ/selfcheck/index.tt2 index 887dbe0065..b93c2aec0e 100644 --- a/Open-ILS/src/templates/staff/circ/selfcheck/index.tt2 +++ b/Open-ILS/src/templates/staff/circ/selfcheck/index.tt2 @@ -45,12 +45,25 @@ angular.module('egCoreMod').run(['egStrings', function(s) { ng-disabled="scanbox.disabled()" type="text"/> -
+
+
+
+
+
[% l('Barcode already scanned: [_1]', '{{scanbox.already_seen}}') %]
-
-
+
+ + [% l( + 'Item "[_1]" was not found in the system. Try re-scanning the item.', + '{{scanbox.text}}') + %] + +
+ +
+ diff --git a/Open-ILS/web/js/ui/default/staff/circ/selfcheck/app.js b/Open-ILS/web/js/ui/default/staff/circ/selfcheck/app.js index afccab462d..a1742334db 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/selfcheck/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/selfcheck/app.js @@ -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; + } + ); } }]) -- 2.11.0