changed color output, beep stub
[Biblio-RFID.git] / examples / selfcheck.js
index 3c825bb..2b65c99 100644 (file)
@@ -16,12 +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 beep() {
+       // FIXME
+}
+
 function start_timeout() {
        $('#timeout').hide();
        tick = Math.round( tick_timeout * ( 1000 / tag_rescan ) );
@@ -36,11 +41,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;
@@ -59,6 +66,7 @@ function change_page(new_state) {
                        book_barcodes = {};
                        $('ul#books').html(''); // clear book list
                        $('#books_count').html( 0 );
+                       only_reader = '/only/librfid';
                        scan_tags();
                }
 
@@ -70,6 +78,7 @@ function change_page(new_state) {
                }
 
                if ( state == 'error' ) {
+                       beep();
                        window.setTimeout(function(){
                                //change_page('start');
                                location.reload();
@@ -134,16 +143,22 @@ function got_visible_tags(data,textStatus) {
        pending_jsonp--;
 };
 
+var wait_counter = 0;
+
 function scan_tags() {
        if ( pending_jsonp ) {
-               console.debug('scan_tags disabled ', pending_jsonp, ' requests waiting');
+               wait_counter++;
+               console.debug('scan_tags disabled ', pending_jsonp, ' requests waiting counter', wait_counter);
+               if ( wait_counter > 3 ) $('#working').show();
        } else {
-               console.info('scan_tags');
+               console.info('scan_tags', only_reader);
                pending_jsonp++;
-               $.getJSON("/scan?callback=?", got_visible_tags).fail( function(data) {
-                       console.error('scan error');
+               $.getJSON("/scan"+only_reader+"?callback=?", got_visible_tags).fail( function(data) {
+                       console.error('scan error pending jsonp', pending_jsonp);
                        pending_jsonp--;
                });
+               wait_counter = 0;
+               $('#working').hide();
        }
 
        if ( tick > 0 ) {
@@ -201,10 +216,18 @@ function start( cardnumber, tag ) {
                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;
+               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 );
+               var overdue = data['fixed'].substr( 2 + 14 + 3 + 18 + ( 1 * 4 ), 4 ) * 1;
+               if ( overdue > 0 ) {
+                       overdue = '<span style="color:red">'+overdue+'</span>';
+                       beep();
+               }
+               fill_in( 'overdue_items', overdue );
+               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) {
@@ -222,6 +245,7 @@ function circulation( barcode, tag ) {
                        && barcode.length == 10
                        && barcode.substr(0,3) == 130
                        && book_barcodes[barcode] != 1
+                       && tag.reader == '3M810'
        ) { // book, not seen yet
                book_barcodes[ barcode ] = 1;
                pending_jsonp++;
@@ -233,9 +257,11 @@ function circulation( barcode, tag ) {
                        if ( data['fixed'].substr(2,1) == 1 ) {
                                color='green';
                                error = '';
+                       } else {
+                               beep();
                        }
 
-                       $('ul#books').append('<li style="color:'+color+'">' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' <b>' + data['AF'] + '</b> ' + error : '' ) + '</li>');
+                       $('ul#books').append('<li>' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' <b style="color:'+color+'">' + data['AF'] + ' ' + error : '</b>' ) + '</li>');
                        $('#books_count').html( $('ul#books > li').length );
                        console.debug( book_barcodes );
                        pending_jsonp--;