From 9bd2ed357223f668d2171ad248bd62b409220722 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 23 Nov 2009 00:12:56 +0000 Subject: [PATCH] fleshed out some circ/login error/event handling git-svn-id: svn://svn.open-ils.org/ILS/trunk@14999 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/openils/circ/nls/selfcheck.js | 8 +- .../web/js/ui/default/circ/selfcheck/selfcheck.js | 143 +++++++++++++++------ 2 files changed, 113 insertions(+), 38 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/circ/nls/selfcheck.js b/Open-ILS/web/js/dojo/openils/circ/nls/selfcheck.js index 8b426a8d2a..dfb012329d 100644 --- a/Open-ILS/web/js/dojo/openils/circ/nls/selfcheck.js +++ b/Open-ILS/web/js/dojo/openils/circ/nls/selfcheck.js @@ -5,6 +5,12 @@ 'TOTAL_HOLDS' : "You have ${0} total holds.", 'TOTAL_FINES_ACCOUNT' : "Total fines on account: $${0}.", 'HOLD_STATUS_READY' : 'Ready for pickup', - 'HOLD_STATUS_WAITING' : '#${0} in line with ${1} copies' + 'HOLD_STATUS_WAITING' : '#${0} in line with ${1} copies', + 'CHECKOUT_SUCCESS' : 'Checkout of item ${0} succeeded', + 'RENEW_SUCCESS' : 'Renewal of item ${0} succeeded', + 'ALREADY_OUT' : 'Item ${0} is already checked out', + 'GENERIC_CIRC_FAILURE' : 'Unable to check out item ${0}. Please see staff.', + 'LOGIN_FAILED' : 'Login for ${0} failed', + 'UNKNOWN_ERROR' : 'An unhandled exception occurred with error code ${0}' } diff --git a/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js b/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js index 66551c9c78..f721af0005 100644 --- a/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js +++ b/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js @@ -16,6 +16,8 @@ const SET_ALERT_ON_CHECKOUT_EVENT = 'circ.selfcheck.alert_on_checkout_event'; const SET_AUTO_OVERRIDE_EVENTS = 'circ.selfcheck.auto_override_checkout_events'; const SET_PATRON_PASSWORD_REQUIRED = 'circ.selfcheck.patron_password_required'; +//openils.Util.playAudioUrl('/xul/server/skin/media/audio/bonus.wav'); + function SelfCheckManager() { this.cgi = new openils.CGI(); @@ -32,13 +34,9 @@ function SelfCheckManager() { // are we currently performing a renewal? this.isRenewal = false; - // is a transaction pending? - this.pendingXact = false; - // dict of org unit settings for "here" this.orgSettings = {}; - // Construct a mock checkout for debugging purposes if(this.mockCheckouts = this.cgi.param('mock-circ')) { @@ -163,7 +161,8 @@ SelfCheckManager.prototype.loginPatron = function(barcode, passwd) { ); if(res == 0) { - return alert('login failed'); // TODO + // user-not-found results in login failure + this.handleXactResult('login', barcode, {textcode : 'ACTOR_USER_NOT_FOUND'}); } } @@ -175,25 +174,14 @@ SelfCheckManager.prototype.loginPatron = function(barcode, passwd) { var evt = openils.Event.parse(this.patron); if(evt) { + this.handleXactResult('login', barcode, evt); - // User login failed, why? - - switch(evt.textcode) { - - case 'ACTOR_USER_NOT_FOUND': - return alert('user not found'); // TODO - - case 'NO_SESSION': - return alert('staff login timed out'); // TODO + } else { - default: - return alert('unexpected patron login error occured: ' + evt.textcode); // TODO - } + dojo.byId('oils-selfck-status-div').innerHTML = ''; + dojo.byId('oils-selfck-user-banner').innerHTML = 'Welcome, ' + this.patron.usrname(); // TODO i18n + this.drawCircPage(); } - - // patron login succeeded - dojo.byId('oils-selfck-user-banner').innerHTML = 'Welcome, ' + this.patron.usrname(); // TODO i18n - this.drawCircPage(); } @@ -485,37 +473,112 @@ SelfCheckManager.prototype.checkout = function(barcode, override) { ]} ); + var stat = this.handleXactResult('checkout', barcode, result); + + console.log("Circ resulted in " + js2JSON(result)); + + if(stat.override) + this.checkout(barcode, true); + +} + + +SelfCheckManager.prototype.handleXactResult = function(action, item, result) { + + var displayText = ''; + var popup = false; + + // TODO handle lost/missing/etc checkin+checkout override steps + + if(result.textcode == 'NO_SESSION') { + + return this.logoutStaff(); + + } else if(result.textcode == 'SUCCESS') { + + if(action == 'checkout') { + + displayText = dojo.string.substitute( + localeStrings.CHECKOUT_SUCCESS, [item]); + this.displayCheckout(result); - if(dojo.isArray(result)) { - // list of results. See if we can override all of them. + } else if(action == 'renew') { + + displayText = dojo.string.substitute( + localeStrings.RENEW_SUCCESS, [item]); + this.displayCheckout(result); + } + + this.updateScanBox(); + + } else if(result.textcode == 'OPEN_CIRCULATION_EXISTS' && action == 'checkout') { + + this.renew(item); } else { - var evt = openils.Event.parse(result); - switch(evt.textcode) { - // standard result events + var overrideEvents = this.orgSettings[SET_AUTO_OVERRIDE_EVENTS]; + + if(overrideEvents && overrideEvents.length) { - case 'SUCCESS': - this.displayCheckout(evt); - break; + // see if the events we received are all in the list of + // events to override + + if(!result.length) result = [result]; + + var override = true; + for(var i = 0; i < result.length; i++) { + var match = overrideEvents.filter( + function(e) { return (e == result[i].textcode); })[0]; + if(!match) { + override = false; + break; + } + } - case 'OPEN_CIRCULATION_EXISTS': - // TODO renewal - break; + if(override) + return { override : true }; + } + + this.updateScanBox({select : true}); + popup = true; + + if(result.length) + result = result[0]; - case 'NO_SESSION': - // TODO logout staff? + switch(result.textcode) { + + case 'ACTOR_USER_NOT_FOUND' : + displayText = dojo.string.substitute( + localeStrings.LOGIN_FAILED, [item]); break; + case 'already-out' : + displayText = dojo.string.substitute( + localeStrings.ALREADY_OUT, [item]); + default: - dojo.byId('oils-selfck-status-div').innerHTML = evt.textcode; - this.updateScanBox({select:true}); + console.error('Unhandled event ' + result.textcode); + + if(action == 'checkout' || action == 'renew') { + displayText = dojo.string.substitute( + localeStrings.GENERIC_CIRC_FAILURE, [item]); + } else { + displayText = dojo.string.substitute( + localeStrings.UNKNOWN_ERROR, [result.textcode]); + } } } - console.log("Circ resulted in " + js2JSON(result)); + dojo.byId('oils-selfck-status-div').innerHTML = displayText; + + if(popup && this.orgSettings[SET_ALERT_ON_CHECKOUT_EVENT]) + alert(displayText); + + return {}; } + /** * Renew an item */ @@ -574,6 +637,12 @@ SelfCheckManager.prototype.printReceipt = function() { * Logout the patron and return to the login page */ SelfCheckManager.prototype.logoutPatron = function() { + + this.patron = null; + this.holdsSummary = null; + this.circSummary = null; + + this.drawLoginPage(); } -- 2.11.0