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 ) {
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
+ }
}
}
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 += '<b>UNKNOWN TAG</b> '+content;
}
}
console.debug( 'calling', state, content );
- window[state]( content, tag.sid ); // call function with barcode
+ window[state]( content, tag ); // call function with barcode
}
});
$.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
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;
}
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) {
// nop
}
-function circulation( barcode, sid ) {
+function circulation( barcode, tag ) {
if ( barcode
&& barcode.length == 10
&& barcode.substr(0,3) == 130
) { // 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('<li>' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' <b>' + data['AF'] + '</b>' : '' ) + '</li>');
+
+ 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('<li style="color:'+color+'">' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' <b>' + data['AF'] + '</b> ' + error : '' ) + '</li>');
$('#books_count').html( $('ul#books > li').length );
console.debug( book_barcodes );
pending_jsonp--;
+ start_timeout(); // reset timeout
}).fail( function() {
change_page('error');
pending_jsonp--;