From a1720e4e4db7c06a13b67855b7ca6938253f23d4 Mon Sep 17 00:00:00 2001 From: phasefx Date: Tue, 9 May 2006 17:16:54 +0000 Subject: [PATCH] use offline patron list git-svn-id: svn://svn.open-ils.org/ILS/trunk@4183 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../chrome/content/circ/offline.js | 124 +++++++++++------- .../chrome/content/circ/offline_checkout.js | 31 ++++- .../chrome/content/circ/offline_register.js | 32 ++++- .../chrome/content/circ/offline_renew.js | 31 ++++- .../staff_client/chrome/content/main/menu.js | 3 + 5 files changed, 172 insertions(+), 49 deletions(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/circ/offline.js b/Open-ILS/xul/staff_client/chrome/content/circ/offline.js index a0b3326a91..8ebe4ce41e 100644 --- a/Open-ILS/xul/staff_client/chrome/content/circ/offline.js +++ b/Open-ILS/xul/staff_client/chrome/content/circ/offline.js @@ -61,60 +61,92 @@ circ.offline.prototype = { } ); - function backup_receipt_templates() { - data.print_list_templates = { - 'offline_checkout' : { - 'type' : 'offline_checkout', - 'header' : 'Patron %patron_barcode%\r\nYou checked out the following items:
    ', - 'line_item' : '
  1. Barcode: %barcode%\r\nDue: %due_date%\r\n', - 'footer' : '

%TODAY%', - }, - 'offline_checkin' : { - 'type' : 'offline_checkin', - 'header' : 'You checked in the following items:
    ', - 'line_item' : '
  1. Barcode: %barcode%\r\n', - 'footer' : '

%TODAY%', - }, - 'offline_renew' : { - 'type' : 'offline_renew', - 'header' : 'You renewed the following items:
    ', - 'line_item' : '
  1. Barcode: %barcode%\r\n', - 'footer' : '

%TODAY%', - }, - 'offline_inhouse_use' : { - 'type' : 'offline_inhouse_use', - 'header' : 'You marked the following in-house items used:
    ', - 'line_item' : '
  1. Barcode: %barcode%\r\nUses: %COUNT%', - 'footer' : '

%TODAY%', - }, - }; - data.stash('print_list_templates'); - } + obj.receipt_init(); - JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); - JSAN.use('util.file'); var file = new util.file('print_list_templates'); - if (file._file.exists()) { - try { - var x = file.get_object(); - if (x) { - data.print_list_templates = x; - data.stash('print_list_templates'); - } else { - backup_receipt_templates(); - } - } catch(E) { - alert(E); + obj.patron_init(); + + } catch(E) { + this.error.sdump('D_ERROR','circ.offline.init: ' + E + '\n'); + } + }, + + 'receipt_init' : function() { + function backup_receipt_templates() { + data.print_list_templates = { + 'offline_checkout' : { + 'type' : 'offline_checkout', + 'header' : 'Patron %patron_barcode%\r\nYou checked out the following items:
    ', + 'line_item' : '
  1. Barcode: %barcode%\r\nDue: %due_date%\r\n', + 'footer' : '

%TODAY%', + }, + 'offline_checkin' : { + 'type' : 'offline_checkin', + 'header' : 'You checked in the following items:
    ', + 'line_item' : '
  1. Barcode: %barcode%\r\n', + 'footer' : '

%TODAY%', + }, + 'offline_renew' : { + 'type' : 'offline_renew', + 'header' : 'You renewed the following items:
    ', + 'line_item' : '
  1. Barcode: %barcode%\r\n', + 'footer' : '

%TODAY%', + }, + 'offline_inhouse_use' : { + 'type' : 'offline_inhouse_use', + 'header' : 'You marked the following in-house items used:
    ', + 'line_item' : '
  1. Barcode: %barcode%\r\nUses: %COUNT%', + 'footer' : '

%TODAY%', + }, + }; + data.stash('print_list_templates'); + } + + JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); + JSAN.use('util.file'); var file = new util.file('print_list_templates'); + if (file._file.exists()) { + try { + var x = file.get_object(); + if (x) { + data.print_list_templates = x; + data.stash('print_list_templates'); + } else { backup_receipt_templates(); } - } else { + } catch(E) { + alert(E); backup_receipt_templates(); } - file.close(); + } else { + backup_receipt_templates(); + } + file.close(); + }, - } catch(E) { - this.error.sdump('D_ERROR','circ.offline.init: ' + E + '\n'); + 'patron_init' : function() { + JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); + JSAN.use('util.file'); var file = new util.file('offline_patron_list'); + if (file._file.exists()) { + var lines = file.get_content().split(/\n/); + var hash = {}; + for (var i = 0; i < lines.length; i++) { + hash[ lines[i].split(/\s+/)[0] ] = lines[i].split(/\s+/)[1]; + } + delete(lines); + data.bad_patrons = hash; + data.stash('bad_patrons'); + var file2 = new util.file('offline_patron_list.date'); + if (file2._file.exists()) { + data.bad_patrons_date = file2.get_content(); + data.stash('bad_patrons_date'); + } + file2.close(); + } else { + data.bad_patrons = {}; + data.stash('bad_patrons'); } + file.close(); }, + } dump('exiting circ.offline.js\n'); diff --git a/Open-ILS/xul/staff_client/chrome/content/circ/offline_checkout.js b/Open-ILS/xul/staff_client/chrome/content/circ/offline_checkout.js index 3dafde5236..ab1879924b 100644 --- a/Open-ILS/xul/staff_client/chrome/content/circ/offline_checkout.js +++ b/Open-ILS/xul/staff_client/chrome/content/circ/offline_checkout.js @@ -30,6 +30,8 @@ function my_init() { $('duedate').setAttribute('value',todayPlus); $('duedate').addEventListener('change',check_date,false); + $('p_barcode').addEventListener('change',test_patron,false); + $('p_barcode').addEventListener('keypress',handle_keypress,false); $('p_barcode').focus(); @@ -81,6 +83,33 @@ function my_init() { function $(id) { return document.getElementById(id); } +function test_patron(ev) { + try { + var barcode = ev.target.value; + if (g.data.bad_patrons[barcode]) { + var msg = 'Warning: As of ' + g.data.bad_patrons_date.substr(0,15) + ', this barcode (' + barcode + ') was flagged '; + switch(g.data.bad_patrons[barcode]) { + case 'L' : msg += 'Lost'; break; + case 'E' : msg += 'Expired'; break; + case 'B' : msg += 'Barred'; break; + case 'D' : msg += 'Blocked'; break; + default : msg += ' with an unknown code: ' + g.data.bad_patrons[barcode]; break; + } + var r = g.error.yns_alert(msg,'Barcode Warning','Ok','Clear',null,'Check here to confirm this message'); + if (r == 1) { + setTimeout( + function() { + ev.target.value = ''; + ev.target.focus(); + },0 + ); + } + } + } catch(E) { + alert(E); + } +} + function check_date(ev) { JSAN.use('util.date'); try { @@ -99,7 +128,7 @@ function check_date(ev) { function handle_keypress(ev) { if ( (! ev.keyCode) || (ev.keyCode != 13) ) return; switch(ev.target) { - case $('p_barcode') : $('p_barcode').disabled = true; $('i_barcode').focus(); break; + case $('p_barcode') : /*$('p_barcode').disabled = true;*/ setTimeout( function() { $('i_barcode').focus(); },0 ); break; case $('i_barcode') : append_to_list('barcode'); break; default: break; } diff --git a/Open-ILS/xul/staff_client/chrome/content/circ/offline_register.js b/Open-ILS/xul/staff_client/chrome/content/circ/offline_register.js index a5569d02e5..e4a167ad05 100644 --- a/Open-ILS/xul/staff_client/chrome/content/circ/offline_register.js +++ b/Open-ILS/xul/staff_client/chrome/content/circ/offline_register.js @@ -7,10 +7,13 @@ function my_init() { JSAN.use('util.error'); g.error = new util.error(); g.error.sdump('D_TRACE','my_init() for offline_register.xul'); + JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'}); + if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') { try { window.xulG.set_tab_name('Standalone'); } catch(E) { alert(E); } } + $('barcode').addEventListener('change',test_patron,false); $('barcode').addEventListener('keypress',handle_keypress,false); $('submit').addEventListener('command',next_patron,false); @@ -77,6 +80,33 @@ function my_init() { function $(id) { return document.getElementById(id); } +function test_patron(ev) { + try { + var barcode = ev.target.value; + if (g.data.bad_patrons[barcode]) { + var msg = 'Warning: As of ' + g.data.bad_patrons_date.substr(0,15) + ', this barcode (' + barcode + ') was flagged '; + switch(g.data.bad_patrons[barcode]) { + case 'L' : msg += 'Lost'; break; + case 'E' : msg += 'Expired'; break; + case 'B' : msg += 'Barred'; break; + case 'D' : msg += 'Blocked'; break; + default : msg += ' with an unknown code: ' + g.data.bad_patrons[barcode]; break; + } + var r = g.error.yns_alert(msg,'Barcode Warning','Ok','Clear',null,'Check here to confirm this message'); + if (r == 1) { + setTimeout( + function() { + ev.target.value = ''; + ev.target.focus(); + },0 + ); + } + } + } catch(E) { + alert(E); + } +} + function handle_check_date(ev) { ev.target.value = check_date(ev.target.value); } @@ -123,7 +153,7 @@ function render_surveys(node,obj) { function handle_keypress(ev) { if ( (! ev.keyCode) || (ev.keyCode != 13) ) return; switch(ev.target) { - case $('barcode') : $('family_name').focus(); break; + case $('barcode') : setTimeout( function() { $('family_name').focus(); },0 ); break; default: break; } } diff --git a/Open-ILS/xul/staff_client/chrome/content/circ/offline_renew.js b/Open-ILS/xul/staff_client/chrome/content/circ/offline_renew.js index ae03acb64b..eee5de9e7c 100644 --- a/Open-ILS/xul/staff_client/chrome/content/circ/offline_renew.js +++ b/Open-ILS/xul/staff_client/chrome/content/circ/offline_renew.js @@ -28,6 +28,8 @@ function my_init() { $('duedate').setAttribute('value',todayPlus); $('duedate').addEventListener('change',check_date,false); + $('p_barcode').addEventListener('change',test_patron,false); + $('p_barcode').addEventListener('keypress',handle_keypress,false); $('p_barcode').focus(); @@ -52,10 +54,37 @@ function my_init() { function $(id) { return document.getElementById(id); } +function test_patron(ev) { + try { + var barcode = ev.target.value; + if (g.data.bad_patrons[barcode]) { + var msg = 'Warning: As of ' + g.data.bad_patrons_date.substr(0,15) + ', this barcode (' + barcode + ') was flagged '; + switch(g.data.bad_patrons[barcode]) { + case 'L' : msg += 'Lost'; break; + case 'E' : msg += 'Expired'; break; + case 'B' : msg += 'Barred'; break; + case 'D' : msg += 'Blocked'; break; + default : msg += ' with an unknown code: ' + g.data.bad_patrons[barcode]; break; + } + var r = g.error.yns_alert(msg,'Barcode Warning','Ok','Clear',null,'Check here to confirm this message'); + if (r == 1) { + setTimeout( + function() { + ev.target.value = ''; + ev.target.focus(); + },0 + ); + } + } + } catch(E) { + alert(E); + } +} + function handle_keypress(ev) { if ( (! ev.keyCode) || (ev.keyCode != 13) ) return; switch(ev.target) { - case $('p_barcode') : $('i_barcode').focus(); break; + case $('p_barcode') : setTimeout( function() { $('i_barcode').focus(); },0 ); break; case $('i_barcode') : append_to_list('barcode'); break; default: break; } diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu.js b/Open-ILS/xul/staff_client/chrome/content/main/menu.js index 051e988e77..e7b9a5c4a7 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu.js @@ -305,6 +305,9 @@ main.menu.prototype = { JSAN.use('util.file'); var file = new util.file('offline_patron_list'); file.write_content('truncate',x.responseText); file.close(); + file = new util.file('offline_patron_list.date'); + file.write_content('truncate',new Date()); + file.close(); alert('Download completed'); } else { alert('There was a problem with the download. The server returned a status ' + x.status + ' : ' + x.statusText); -- 2.43.2