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.
);
}
+ /*
+ * 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;
}])
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);
}
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;
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;
+ }
+ );
}
}])