X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=examples%2Fselfcheck.js;h=9436d799252dd9ddc7e73a76e917790d2167df8a;hb=abaaec833076bde6e6e517e8b88ae9c1b098e9c0;hp=ac9ea195f5dff985719b6e5c2cd9d850924cd788;hpb=5f2e55f0a56d3ea9dd7f360445e17c2c523933d0;p=Biblio-RFID.git diff --git a/examples/selfcheck.js b/examples/selfcheck.js index ac9ea19..9436d79 100644 --- a/examples/selfcheck.js +++ b/examples/selfcheck.js @@ -15,6 +15,7 @@ if(!window.console) { var state; var scan_timeout; +var pending_jsonp = 0; function change_page(new_state) { if ( state != new_state ) { @@ -47,12 +48,14 @@ function change_page(new_state) { circulation_type = 'checkout'; book_barcodes = {}; $('ul#books').html(''); // clear book list + $('#books_count').html( 0 ); scan_tags(); } if ( state == 'end' ) { window.setTimeout(function(){ - change_page('start'); + //change_page('start'); + location.reload(); // force js VM to GC? },end_timeout); } @@ -71,20 +74,13 @@ function got_visible_tags(data,textStatus) { $.each(data.tags, function(i,tag) { console.debug( i, tag ); html += '
  • ' + tag.sid; - var content = tag.content - if (typeof content === undefined && typeof tag.borrower !== undefined) - content = tag.borrower.cardnumber; - - var is_book = false; - var is_borrower = false; + var content = tag.content || tag.borrower.cardnumber; if ( content ) { var link; if ( content.length = 10 && content.substr(0,3) == 130 ) { // book - is_book = true; link = 'catalogue/search.pl?q='; } else if ( content.length == 12 && content.substr(0,2) == 20 ) { - is_borrower = true; link = 'members/member.pl?member='; } else { html += 'UNKNOWN TAG '+content; @@ -103,6 +99,7 @@ function got_visible_tags(data,textStatus) { } }); html += ''; + } var arrows = Array( 8592, 8598, 8593, 8599, 8594, 8600, 8595, 8601 ); @@ -113,15 +110,23 @@ function got_visible_tags(data,textStatus) { + '' + html ; - $('#tags').html( html ); - scan_timeout = window.setTimeout(function(){ - scan_tags(); - },tag_rescan); // re-scan every 200ms + $('#tags').html( html ); // FIXME leaks memory? + + pending_jsonp--; }; function scan_tags() { - console.info('scan_tags'); - $.getJSON("/scan?callback=?", got_visible_tags); + if ( pending_jsonp ) { + console.debug('scan_tags disabled ', pending_jsonp, ' requests waiting'); + } else { + console.info('scan_tags'); + pending_jsonp++; + $.getJSON("/scan?callback=?", got_visible_tags); + } + + scan_timeout = window.setTimeout(function(){ + scan_tags(); + },tag_rescan); // re-scan every 200ms } $(document).ready(function() { @@ -152,24 +157,24 @@ function start( cardnumber ) { return; } - borrower_cardnumber = cardnumber; - - change_page('borrower_check'); -} - -function borrower_check() { + borrower_cardnumber = cardnumber; // for circulation - fill_in( 'borrower_number', borrower_cardnumber ); + fill_in( 'borrower_number', cardnumber ); - $.getJSON('/sip2/patron_info/'+borrower_cardnumber) + pending_jsonp++; + $.getJSON('/sip2/patron_info/'+cardnumber) .done( function( data ) { console.info('patron', data); fill_in( 'borrower_name', data['AE'] ); 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) { + pending_jsonp--; change_page('error'); }); } @@ -184,14 +189,21 @@ function circulation( barcode, sid ) { && barcode.substr(0,3) == 130 && book_barcodes[barcode] != 1 ) { // book, not seen yet + book_barcodes[ barcode ] = 1; + 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'] + '
  • '); - book_barcodes[ barcode ] = 1; + $('ul#books').append('
  • ' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' ' + data['AF'] + '' : '' ) + '
  • '); + $('#books_count').html( $('ul#books > li').length ); console.debug( book_barcodes ); + pending_jsonp--; }).fail( function() { change_page('error'); + pending_jsonp--; }); } } +function end() { + // nop +}