X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=examples%2Fselfcheck.js;h=18b93f0e3f4a0bed883bdf86426d4d17662f56cb;hb=603ac103d3f7489d55a7aeb7a60815dc2715f4eb;hp=9436d799252dd9ddc7e73a76e917790d2167df8a;hpb=abaaec833076bde6e6e517e8b88ae9c1b098e9c0;p=Biblio-RFID.git diff --git a/examples/selfcheck.js b/examples/selfcheck.js index 9436d79..18b93f0 100644 --- a/examples/selfcheck.js +++ b/examples/selfcheck.js @@ -16,6 +16,17 @@ if(!window.console) { var state; var scan_timeout; var pending_jsonp = 0; +var only_reader = ''; + +// 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 ) { @@ -26,11 +37,13 @@ function change_page(new_state) { $('.checkin').show(); circulation_type = 'checkin'; borrower_cardnumber = 0; // fake + only_reader = '/only/3M'; } else if ( new_state == 'checkout' ) { new_state = 'circulation'; // page has different name $('.checkout').show(); $('.checkin').hide(); circulation_type = 'checkout'; + only_reader = '/only/3M'; } state = new_state; @@ -49,6 +62,7 @@ function change_page(new_state) { book_barcodes = {}; $('ul#books').html(''); // clear book list $('#books_count').html( 0 ); + only_reader = ''; scan_tags(); } @@ -61,9 +75,16 @@ function change_page(new_state) { 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 + } } } @@ -82,6 +103,8 @@ function got_visible_tags(data,textStatus) { link = 'catalogue/search.pl?q='; } else if ( content.length == 12 && content.substr(0,2) == 20 ) { link = 'members/member.pl?member='; + } else if ( tag.tag_type == 'SmartX' ) { + link = 'members/member.pl?member='; } else { html += 'UNKNOWN TAG '+content; } @@ -94,7 +117,7 @@ function got_visible_tags(data,textStatus) { } console.debug( 'calling', state, content ); - window[state]( content, tag.sid ); // call function with barcode + window[state]( content, tag ); // call function with barcode } }); @@ -119,9 +142,24 @@ function scan_tags() { if ( pending_jsonp ) { console.debug('scan_tags disabled ', pending_jsonp, ' requests waiting'); } else { - console.info('scan_tags'); + console.info('scan_tags', only_reader); pending_jsonp++; - $.getJSON("/scan?callback=?", got_visible_tags); + $.getJSON("/scan"+only_reader+"?callback=?", got_visible_tags).fail( function(data) { + console.error('scan error pending jsonp', pending_jsonp); + pending_jsonp--; + }); + } + + 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(){ @@ -150,10 +188,10 @@ var borrower_cardnumber; var circulation_type; var book_barcodes = {}; -function start( cardnumber ) { +function start( cardnumber, tag ) { - if ( cardnumber.length != 12 || cardnumber.substr(0,2) != "20" ) { - console.error(cardnumber, ' is not borrower card'); + if ( tag.tag_type != 'SmartX' && ( cardnumber.length != 12 || cardnumber.substr(0,2) != "20" ) ) { + console.error(cardnumber, 'is not borrower card', tag); return; } @@ -183,7 +221,7 @@ function borrower_info() { // nop } -function circulation( barcode, sid ) { +function circulation( barcode, tag ) { if ( barcode && barcode.length == 10 && barcode.substr(0,3) == 130 @@ -191,12 +229,21 @@ function circulation( barcode, sid ) { ) { // book, not seen yet book_barcodes[ barcode ] = 1; pending_jsonp++; - $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+sid , function( data ) { + $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+tag.sid , function( data ) { console.info( circulation_type, data ); - $('ul#books').append('
  • ' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' ' + data['AF'] + '' : '' ) + '
  • '); + + var color = 'red'; + var error = 'Transakcija neuspjeÅ¡na. Odnesite knjige na pult!'; + if ( data['fixed'].substr(2,1) == 1 ) { + color='green'; + error = ''; + } + + $('ul#books').append('
  • ' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' ' + data['AF'] + ' ' + error : '' ) + '
  • '); $('#books_count').html( $('ul#books > li').length ); console.debug( book_barcodes ); pending_jsonp--; + start_timeout(); // reset timeout }).fail( function() { change_page('error'); pending_jsonp--;