SmartX turn off warnings
[Biblio-RFID.git] / examples / selfcheck.js
index 218bf3a..a03d297 100644 (file)
@@ -84,7 +84,7 @@ function change_page(new_state) {
                        },end_timeout);
                }
 
-               if ( state == 'error' ) {
+               if ( state == 'error' || state == 'error-borrower' ) {
                        beep( 'error page' );
                        window.setTimeout(function(){
                                //change_page('start');
@@ -101,11 +101,21 @@ function change_page(new_state) {
 }
 
 function got_visible_tags(data,textStatus) {
+       console.log('got_visible_tags', data,textStatus);
+       wait_counter = 0;
+       $('#working').hide();
+
        var html = 'No tags in range';
        if ( data.tags ) {
                html = '<ul class="tags">';
                $.each(data.tags, function(i,tag) {
                        console.debug( i, tag );
+
+                 if ( tag.hasOwnProperty('error') ) {
+                               html += 'ERROR ' + tag.sid + ' ' + tag.error;
+                               change_page('error-borrower');
+                 } else {
+
                        html += '<li><tt class="' + tag.security + '">' + tag.sid;
                        var content = tag.content || tag.borrower.cardnumber;
 
@@ -132,6 +142,9 @@ function got_visible_tags(data,textStatus) {
                                window[state]( content, tag ); // call function with barcode
 
                        }
+
+                 } // not error
+
                });
                html += '</ul>';
 
@@ -155,17 +168,17 @@ var wait_counter = 0;
 function scan_tags() {
        if ( pending_jsonp ) {
                wait_counter++;
-               console.debug('scan_tags disabled ', pending_jsonp, ' requests waiting counter', wait_counter);
-               if ( wait_counter > 3 ) $('#working').show();
+               console.debug('scan_tags', 'tick', tick, 'pending_jsonp', pending_jsonp, ' wait_conter', wait_counter);
+               if ( wait_counter > 10 ) $('#working').show(); // tag_rescan = 200ms * 10 = 2s
        } else {
-               console.info('scan_tags', only_reader);
+               console.info('scan_tags', 'tock', tick, only_reader, 'wait_counter', wait_counter, 'tick', tick);
                pending_jsonp++;
                $.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();
                });
-               wait_counter = 0;
-               $('#working').hide();
        }
 
        if ( tick > 0 ) {