var service = {
// auto-override these events after the first override
- checkout_overrides : {},
+ auto_override_checkout_events : {},
org_addr_cache : {}
};
service.reset = function() {
- service.checkout_overrides = {};
+ service.auto_override_checkout_events = {};
}
+ // these events can be overridden by staff
+ service.overridable_events = [
+ 'PATRON_EXCEEDS_OVERDUE_COUNT',
+ 'PATRON_EXCEEDS_CHECKOUT_COUNT',
+ 'PATRON_EXCEEDS_FINES',
+ 'PATRON_BARRED',
+ 'CIRC_EXCEEDS_COPY_RANGE',
+ 'ITEM_DEPOSIT_REQUIRED',
+ 'ITEM_RENTAL_FEE_REQUIRED',
+ 'PATRON_EXCEEDS_LOST_COUNT',
+ 'COPY_CIRC_NOT_ALLOWED',
+ 'COPY_NOT_AVAILABLE', // HM?
+ 'COPY_IS_REFERENCE',
+ 'COPY_ALERT_MESSAGE',
+ 'ITEM_ON_HOLDS_SHELF'
+ ]
+
+ // after the first override of any of these events,
+ // auto-override them in subsequent calls.
+ service.auto_override_after_first = [
+ 'PATRON_EXCEEDS_OVERDUE_COUNT',
+ 'PATRON_BARRED',
+ 'PATRON_EXCEEDS_LOST_COUNT',
+ 'PATRON_EXCEEDS_CHECKOUT_COUNT',
+ 'PATRON_EXCEEDS_FINES'
+ ]
+
// Performs a checkout.
// Returns a promise resolved with the original params and options
// and the final checkout event (e.g. in the case of override).
});
}
+ service.handle_overridable_checkout_event = function(evt, params, options) {
+
+ if (options.override) {
+ // override attempt already made and failed.
+ // NOTE: I don't think we'll ever get here, since the
+ // override attempt should produce a perm failure...
+ console.debug('override failed: ' + evt.textcode);
+ return $q.reject();
+
+ } else {
+ if (service.auto_override_checkout_events[evt.textcode]) {
+ // user has already opted to override this type
+ // of event. Re-run the checkout w/ override.
+ options.override = true;
+ return service.checkout(params, options);
+ }
+ }
+
+ // Ask the user if they would like to override this event.
+ // Some events offer a stock override dialog, while others
+ // require additional context.
+
+ switch(evt.textcode) {
+ case 'COPY_NOT_AVAILABLE':
+ return service.copy_not_avail_dialog(evt, params, options);
+ default:
+ return service.override_dialog(evt, params, options);
+ }
+ }
+
+ //TODO: copy_alert_dialog
+
service.handle_checkout_resp = function(evt, params, options) {
var final_resp = {evt : evt, params : params, options : options};
// track the barcode regardless of whether it refers to a copy
evt.copy_barcode = params.copy_barcode;
+ // Overridable Events
+ if (service.overridable_events.indexOf(evt.textcode) > -1)
+ return service.handle_overridable_checkout_event(evt, params, options);
+
+ // Other events
switch (evt.textcode) {
case 'SUCCESS':
return $q.when(final_resp);
case 'ITEM_NOT_CATALOGED':
return service.precat_dialog(params, options);
- case 'PATRON_EXCEEDS_OVERDUE_COUNT':
- case 'PATRON_EXCEEDS_FINES':
- case 'PATRON_EXCEEDS_CHECKOUT_COUNT':
- case 'PATRON_EXCEEDS_LOST_COUNT':
- if (options.override) {
- // NOTE: I don't think we'll ever get here, since the
- // override attempt should produce a perm failure...
- console.debug('override failed: ' + evt.textcode);
-
- } else {
- if (service.checkout_overrides[evt.textcode]) {
- // user has already opted to override this type
- // of event. Re-run the checkout w/ override.
- options.override = true;
- return service.checkout(params, options);
- } else {
- // ask the user if they would like to override this
- // event type.
- return service.override_dialog(evt, params, options);
- }
- }
- break;
-
case 'OPEN_CIRCULATION_EXISTS':
return service.circ_exists_dialog(evt, params, options);
case 'COPY_IN_TRANSIT':
return service.copy_in_transit_dialog(evt, params, options);
- /* stuff to consider
+ case 'PATRON_CARD_INACTIVE':
+ case 'PATRON_INACTIVE':
+ case 'PATRON_ACCOUNT_EXPIRED':
+ return service.exit_alert(egCore.strings[evt.textcode]);
+
+ /* stuff yet to consider
PERM_FAILURE
- PATRON_BARRED
- CIRC_EXCEEDS_COPY_RANGE
- PATRON_ACCOUNT_EXPIRED
- ITEM_DEPOSIT_REQUIRED
- ITEM_RENTAL_FEE_REQUIRED
- ITEM_DEPOSIT_PAID
- ACTION_CIRCULATION_NOT_FOUND
- PATRON_EXCEEDS_CHECKOUT_COUNT
- COPY_CIRC_NOT_ALLOWED
- COPY_NOT_AVAILABLE
- COPY_IS_REFERENCE
- COPY_NEEDED_FOR_HOLD
- MAX_RENEWALS_REACHED
CIRC_CLAIMS_RETURNED
COPY_ALERT_MESSAGE
*/
default:
- console.warn('unhandled circ response : ' + evt.textcode);
- return $q.when(final_resp);
+ return service.exit_alert(
+ egCore.strings.CHECKOUT_FAILED_GENERIC, {
+ barcode : params.copy_barcode,
+ textcode : evt.textcode
+ }
+ );
}
}
});
}
+ service.exit_alert = function(msg, scope) {
+ return egAlertDialog.open(msg, scope).result.then(
+ function() {return $q.reject()});
+ }
+
// opens a dialog asking the user if they would like to override
// the returned event.
service.override_dialog = function(evt, params, options) {
['$scope', '$modalInstance',
function($scope, $modalInstance) {
$scope.evt = evt;
+ $scope.auto_override =
+ service.auto_override_after_first.indexOf(evt.textcode) > -1;
$scope.ok = function() { $modalInstance.close() }
$scope.cancel = function ($event) {
$modalInstance.dismiss();
}]
}).result.then(
function() {
- service.checkout_overrides[evt.textcode] = true;
+ if (service.auto_override_after_first.indexOf(evt.textcode) > -1)
+ service.auto_override_checkout_events[evt.textcode] = true;
+ options.override = true;
+ return service.checkout(params, options);
+ }
+ );
+ }
+
+ service.copy_not_avail_dialog = function(evt, params, options) {
+ return $modal.open({
+ templateUrl: './circ/share/t_copy_not_avail_dialog',
+ controller:
+ ['$scope','$modalInstance','copyStatus',
+ function($scope , $modalInstance , copyStatus) {
+ $scope.copyStatus = copyStatus;
+ $scope.ok = function() {$modalInstance.close()}
+ $scope.cancel = function() {$modalInstance.dismiss()}
+ }],
+ resolve : {
+ copyStatus : function() {
+ return egCore.pcrud.retrieve(
+ 'ccs', evt.payload.status());
+ }
+ }
+ }).result.then(
+ function() {
options.override = true;
return service.checkout(params, options);
}