X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=examples%2Fselfcheck.js;h=ec6ee5251d938804b88fe074d05951165dec11bc;hb=3935574aa2bfcef6e6f54b5eaacfb0fa9c4f93e9;hp=4955e54f30b3e627339663e7be984f73071a40a6;hpb=a32bdef661b26489f2b6db3622700846c61f4018;p=Biblio-RFID.git diff --git a/examples/selfcheck.js b/examples/selfcheck.js index 4955e54..ec6ee52 100644 --- a/examples/selfcheck.js +++ b/examples/selfcheck.js @@ -17,6 +17,16 @@ var state; var scan_timeout; var pending_jsonp = 0; +// timeout warning dialog +var tick_timeout = 25; // s +var tick_warning = 10; // s +var tick = 0; + +function start_timeout() { + $('#timeout').hide(); + tick = Math.round( tick_timeout * ( 1000 / tag_rescan ) ); +} + function change_page(new_state) { if ( state != new_state ) { @@ -54,15 +64,23 @@ function change_page(new_state) { if ( state == 'end' ) { window.setTimeout(function(){ - change_page('start'); + //change_page('start'); + location.reload(); // force js VM to GC? },end_timeout); } if ( state == 'error' ) { window.setTimeout(function(){ - change_page('start'); + //change_page('start'); + location.reload(); },error_timeout); } + + if ( state == 'circulation' || state == 'borrower_info' ) { + start_timeout(); + } else { + tick = 0; // timeout disabled + } } } @@ -123,6 +141,18 @@ function scan_tags() { $.getJSON("/scan?callback=?", got_visible_tags); } + if ( tick > 0 ) { + if ( tick < tick_warning * ( 1000 / tag_rescan ) ) { + $('#tick').html( Math.round( tick * tag_rescan / 1000 ) ); + $('#timeout').show(); + } + tick--; + if ( tick == 0 ) { + $('#timeout').hide(); + change_page('end'); + } + } + scan_timeout = window.setTimeout(function(){ scan_tags(); },tag_rescan); // re-scan every 200ms @@ -168,6 +198,8 @@ function start( cardnumber ) { fill_in( 'borrower_email', data['BE'] ); fill_in( 'hold_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 0 * 4 ), 4 ) ) * 1; fill_in( 'overdue_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 1 * 4 ), 4 ) ) * 1; + fill_in( 'charged_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 2 * 4 ), 4 ) ) * 1; + fill_in( 'fine_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 3 * 4 ), 4 ) ) * 1; pending_jsonp--; change_page('borrower_info'); }).fail( function(data) { @@ -190,10 +222,15 @@ function circulation( barcode, sid ) { pending_jsonp++; $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+sid , function( data ) { console.info( circulation_type, data ); - $('ul#books').append('
  • ' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' ' + data['AF'] + '' : '' ) + '
  • '); + + var color = 'red'; + if ( data['fixed'].substr(2,1) == 1 ) color='green'; + + $('ul#books').append('
  • ' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' ' + data['AF'] + '' : '' ) + '
  • '); $('#books_count').html( $('ul#books > li').length ); console.debug( book_barcodes ); pending_jsonp--; + start_timeout(); // reset timeout }).fail( function() { change_page('error'); pending_jsonp--;