From 93b3915fb8098a94de6621658d21d529b49f607e Mon Sep 17 00:00:00 2001 From: phasefx Date: Wed, 12 Apr 2006 16:59:40 +0000 Subject: [PATCH] simple offline detection git-svn-id: svn://svn.open-ils.org/ILS/trunk@3687 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../staff_client/chrome/content/util/error.js | 21 +++++++++ .../chrome/content/util/network.js | 6 ++- .../xul/staff_client/server/circ/checkin.js | 3 +- .../xul/staff_client/server/circ/checkout.js | 6 ++- .../staff_client/server/circ/copy_status.js | 13 +++--- .../staff_client/server/circ/in_house_use.js | 5 ++- Open-ILS/xul/staff_client/server/circ/util.js | 13 +++--- .../server/patron/barcode_entry.xul | 14 +++++- .../xul/staff_client/server/patron/display.js | 2 +- .../xul/staff_client/server/patron/summary.js | 43 ++++--------------- 10 files changed, 73 insertions(+), 53 deletions(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/util/error.js b/Open-ILS/xul/staff_client/chrome/content/util/error.js index fccfaac1cd..11f8d744ec 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/error.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/error.js @@ -204,6 +204,27 @@ util.error.prototype = { return this.OpenILS.data.entities['ilsevent.'+status]; }, + 'standard_network_error_alert' : function(msg) { + var obj = this; + if (!msg) msg = ''; + obj.yns_alert( + 'We experienced a network/server communication failure. Please check your internet connection and try this action again. Repeated failures may require attention from your local IT staff or your friendly Evergreen developers.\n\n' + msg, + 'Communication Failure', + 'Ok', null, null, 'Check here to confirm this message' + ); + }, + + 'standard_unexpected_error_alert' : function(msg,E) { + var obj = this; + if (!msg) msg = ''; + obj.yns_alert( + 'FIXME: If you encounter this alert, please inform your IT/ILS helpdesk staff or your friendly Evergreen developers.\n\n' + msg + '\n\n' + js2JSON(E), + 'Unhandled Error', + 'Ok', null, null, 'Check here to confirm this message' + ); + }, + + 'yns_alert' : function (s,title,b1,b2,b3,c) { /* diff --git a/Open-ILS/xul/staff_client/chrome/content/util/network.js b/Open-ILS/xul/staff_client/chrome/content/util/network.js index f18e91a9a1..6b6d846252 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/network.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/network.js @@ -99,7 +99,7 @@ util.network.prototype = { try { var obj = this; var robj = req.getResultObject(); - if (robj.ilsevent && robj.ilsevent == 1001) { + if (robj != null && robj.ilsevent && robj.ilsevent == 1001) { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite'); window.open( urls.XUL_AUTH_SIMPLE @@ -127,7 +127,7 @@ util.network.prototype = { try { var obj = this; var robj = req.getResultObject(); - if (robj.ilsevent && robj.ilsevent == 5000) { + if (robj != null && robj.ilsevent && robj.ilsevent == 5000) { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite'); window.open( urls.XUL_AUTH_SIMPLE @@ -179,6 +179,8 @@ util.network.prototype = { } var result = req.getResultObject(); + if (!result) return req; + if ( o_params.overridable_events.indexOf(result.ilsevent) != -1 ) { req = override([result]); } else { diff --git a/Open-ILS/xul/staff_client/server/circ/checkin.js b/Open-ILS/xul/staff_client/server/circ/checkin.js index 82541fa5ca..509503d88c 100644 --- a/Open-ILS/xul/staff_client/server/circ/checkin.js +++ b/Open-ILS/xul/staff_client/server/circ/checkin.js @@ -147,6 +147,7 @@ circ.checkin.prototype = { var checkin = circ.util.checkin_via_barcode( obj.session, barcode, backdate ); + if (!checkin) return; /* circ.util.checkin handles errors and returns null currently */ obj.list.append( { 'row' : { @@ -176,7 +177,7 @@ circ.checkin.prototype = { } } catch(E) { - obj.error.yns_alert('FIXME: If you see this alert, please let your friendly Evergreen Developers know.\n' + js2JSON(E), 'Check In Failed', 'Ok', null, null, 'Check here to confirm this message' ); + obj.error.standard_unexpected_error_alert('',E); if (typeof obj.on_failure == 'function') { obj.on_failure(E); } diff --git a/Open-ILS/xul/staff_client/server/circ/checkout.js b/Open-ILS/xul/staff_client/server/circ/checkout.js index c1bc515cb0..cb4d7a2bc1 100644 --- a/Open-ILS/xul/staff_client/server/circ/checkout.js +++ b/Open-ILS/xul/staff_client/server/circ/checkout.js @@ -305,7 +305,11 @@ circ.checkout.prototype = { } } catch(E) { - obj.error.yns_alert('FIXME: If you see this alert, please let your friendly Evergreen Developers know.\n' + js2JSON(E), 'Check Out Failed', 'Ok', null, null, 'Check here to confirm this message' ); + if (E.ilsevent && E.ilsevent == -1) { + obj.error.standard_network_error_alert('Check Out Failed. If you wish to use the offline interface, in the top menubar select Circulation -> Offline Interface'); + } else { + obj.error.standard_unexpected_error_alert('Check Out Failed',E); + } if (typeof obj.on_failure == 'function') { obj.on_failure(E); } diff --git a/Open-ILS/xul/staff_client/server/circ/copy_status.js b/Open-ILS/xul/staff_client/server/circ/copy_status.js index a8eb9c48c0..34ecdd9e7b 100644 --- a/Open-ILS/xul/staff_client/server/circ/copy_status.js +++ b/Open-ILS/xul/staff_client/server/circ/copy_status.js @@ -190,9 +190,12 @@ circ.copy_status.prototype = { JSAN.use('circ.util'); var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE_VIA_BARCODE', [ barcode ]); if (copy == null) { - throw('COPY NOT FOUND'); + throw('Something weird happened. null result'); } else if (copy.ilsevent) { - throw('COPY NOT FOUND\n' + js2JSON(copy)); + switch(copy.ilsevent) { + case -1: obj.error.standard_network_error_alert(); break; + default: throw(copy); break; + } } else { obj.list.append( { @@ -205,11 +208,11 @@ circ.copy_status.prototype = { } } ); + obj.controller.view.copy_status_barcode_entry_textbox.value = ''; + obj.controller.view.copy_status_barcode_entry_textbox.focus(); } - obj.controller.view.copy_status_barcode_entry_textbox.value = ''; - obj.controller.view.copy_status_barcode_entry_textbox.focus(); } catch(E) { - obj.error.yns_alert('FIXME: If you see this message, please inform your friendly Evergreen developers\n' + js2JSON(E), 'FIXME', 'Ok', null, null, 'Check here to confirm this message'); + obj.error.standard_unexpected_error_alert('',E); obj.controller.view.copy_status_barcode_entry_textbox.select(); obj.controller.view.copy_status_barcode_entry_textbox.focus(); } diff --git a/Open-ILS/xul/staff_client/server/circ/in_house_use.js b/Open-ILS/xul/staff_client/server/circ/in_house_use.js index b1fbd4a84e..d251fbab8a 100644 --- a/Open-ILS/xul/staff_client/server/circ/in_house_use.js +++ b/Open-ILS/xul/staff_client/server/circ/in_house_use.js @@ -140,8 +140,9 @@ circ.in_house_use.prototype = { var copy = obj.network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ barcode ]); if (copy.ilsevent) { switch(copy.ilsevent) { + case -1 : obj.error.standard_network_error_alert('In House Use Failed. If you wish to use the offline interface, in the top menubar select Circulation -> Offline Interface'); break; case 1502: obj.error.yns_alert(copy.textcode,'In House Use Failed','Ok',null,null,'Check here to confirm this message'); break; - default: obj.error.yns_alert('FIXME: If you see this alert, please let your friendly Evergreen Developers know.\n' + js2JSON(copy), 'In House Use Failed', 'Ok', null, null, 'Check here to confirm this message' ); break; + default: throw(copy); } return; } @@ -174,7 +175,7 @@ circ.in_house_use.prototype = { } } catch(E) { - obj.error.yns_alert('FIXME: If you see this alert, please let your friendly Evergreen Developers know.\n' + js2JSON(E), 'In House Use Failed', 'Ok', null, null, 'Check here to confirm this message' ); + obj.error.standard_unexpected_error_alert('In House Use Failed',E); if (typeof obj.on_failure == 'function') { obj.on_failure(E); } diff --git a/Open-ILS/xul/staff_client/server/circ/util.js b/Open-ILS/xul/staff_client/server/circ/util.js index 59e4ecf94f..dd5f894c7d 100644 --- a/Open-ILS/xul/staff_client/server/circ/util.js +++ b/Open-ILS/xul/staff_client/server/circ/util.js @@ -489,6 +489,11 @@ circ.util.checkin_via_barcode = function(session,barcode,backdate) { ); } + /* NETWORK TIMEOUT */ + if (check.ilsevent == -1) { + error.standard_network_error_alert('Check In Failed. If you wish to use the offline interface, in the top menubar select Circulation -> Offline Interface'); + } + // case '2': case 2: /* LOST??? */ // JSAN.use('patron.util'); // var au_obj = patron.util.retrieve_au_via_id( session, check.circ.usr() ); @@ -521,9 +526,7 @@ circ.util.checkin_via_barcode = function(session,barcode,backdate) { return check; } catch(E) { JSAN.use('util.error'); var error = new util.error(); - var msg = E + '\n---\n' + js2JSON(E); - error.sdump('D_ERROR',msg); - obj.error.yns_alert('FIXME: If you see this alert, please let your friendly Evergreen Developers know.\n' + (msg), 'Check In Failed', 'Ok', null, null, 'Check here to confirm this message' ); + obj.error.standard_unexpected_error_alert('Check In Failed',E); return null; } } @@ -552,9 +555,7 @@ circ.util.hold_capture_via_copy_barcode = function ( session, barcode, retrieve_ return check; } catch(E) { JSAN.use('util.error'); var error = new util.error(); - var msg = E + '\n---\n' + js2JSON(E); - error.sdump('D_ERROR',msg); - obj.error.yns_alert('FIXME: If you see this alert, please let your friendly Evergreen Developers know.\n' + (msg), 'Check In Failed', 'Ok', null, null, 'Check here to confirm this message' ); + obj.error.standard_unexpected_error_alert('Hold Capture Failed',E); return null; } } diff --git a/Open-ILS/xul/staff_client/server/patron/barcode_entry.xul b/Open-ILS/xul/staff_client/server/patron/barcode_entry.xul index 96e018d830..e962328997 100644 --- a/Open-ILS/xul/staff_client/server/patron/barcode_entry.xul +++ b/Open-ILS/xul/staff_client/server/patron/barcode_entry.xul @@ -71,7 +71,19 @@ try { window.xulG.set_tab_name('Patron Scan'); } catch(E) { alert(E); } } - if (g.cgi.param('error')) { alert(g.cgi.param('error')); } + if (g.cgi.param('error')) { + var error = g.cgi.param('error'); + var E = JSON2js( error ); + if (E.ilsevent) { + switch(E.ilsevent) { + case -1: g.error.standard_network_error_alert(); break; + case 1002: alert('No user was found with this barcode.'); break; + default: g.error.standard_unexpected_error_alert('',E); break; + } + } else { + g.error.standard_unexpected_error_alert('',E); + } + } } catch(E) { var err_msg = "!! This software has encountered an error. Please tell your friendly " + diff --git a/Open-ILS/xul/staff_client/server/patron/display.js b/Open-ILS/xul/staff_client/server/patron/display.js index 15b7c3f5ce..e86ae3639b 100644 --- a/Open-ILS/xul/staff_client/server/patron/display.js +++ b/Open-ILS/xul/staff_client/server/patron/display.js @@ -302,7 +302,7 @@ patron.display.prototype = { 'on_error' : function(E) { location.href = urls.XUL_PATRON_BARCODE_ENTRY + '?session=' + window.escape(obj.session) - + '&error=' + window.escape(E); + + '&error=' + window.escape(js2JSON(E)); } } ); diff --git a/Open-ILS/xul/staff_client/server/patron/summary.js b/Open-ILS/xul/staff_client/server/patron/summary.js index 37a9dd7cbe..a32f9c56fb 100644 --- a/Open-ILS/xul/staff_client/server/patron/summary.js +++ b/Open-ILS/xul/staff_client/server/patron/summary.js @@ -482,29 +482,19 @@ patron.summary.prototype = { JSAN.use('patron.util'); patron.util.set_penalty_css(obj.patron); - } else if (typeof robj.ilsevent != 'undefined') { - - if (robj.ilsevent == 0) { - - // are we moving toward a payload here? - - } else { - var error = obj.error.get_ilsevent( robj.ilsevent ); - throw(error); - } } else { - throw('result is not an au fm object'); + throw(robj); + } } else { - throw('result == false'); + throw(robj); + } } catch(E) { - var error = js2JSON(E); - obj.error.sdump('D_ERROR',error); - throw(error); + throw(E); } } ); @@ -554,36 +544,21 @@ patron.summary.prototype = { // Do it JSAN.use('util.exec'); obj.exec = new util.exec(); obj.exec.on_error = function(E) { - //location.href = urls.XUL_PATRON_BARCODE_ENTRY + '?session=' + window.escape(obj.session); - obj.patron = new au(); - obj.patron.checkouts( [] ); - obj.patron.hold_requests( [] ); - obj.patron.bills = []; - var home_ou = new aou(); - obj.patron.home_ou( home_ou ); - var card = new ac(); card.barcode( obj.barcode ); - obj.patron.card( card ); - obj.patron.family_name( 'Could not retrieve patron' ); - var error = ('Problem with barcode: ' + obj.barcode + '\n' + E); if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') { - obj.error.sdump('D_PATRON_SUMMARY', - 'patron.summary: Calling external .on_error()\n'); - window.xulG.on_error(error); + window.xulG.on_error(E); } else { - obj.error.sdump('D_PATRON_SUMMARY','patron.summary: No external .on_error()\n'); + alert(js2JSON(E)); } } this.exec.chain( chain ); } catch(E) { - var error = (js2JSON(E)); - this.error.sdump('D_ERROR',error); if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') { - window.xulG.on_error(error); + window.xulG.on_error(E); } else { - alert(error); + alert(js2JSON(E)); } } } -- 2.43.2