color book items according to circulation stataus
[Biblio-RFID.git] / examples / selfcheck.js
index c57987e..189bfa5 100644 (file)
@@ -48,18 +48,21 @@ 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);
                }
 
                if ( state == 'error' ) {
                        window.setTimeout(function(){
-                               change_page('start');
+                               //change_page('start');
+                               location.reload();
                        },error_timeout);
                }
        }
@@ -68,25 +71,17 @@ function change_page(new_state) {
 function got_visible_tags(data,textStatus) {
        var html = 'No tags in range';
        if ( data.tags ) {
-               scan_tags_active = false;
                html = '<ul class="tags">';
                $.each(data.tags, function(i,tag) {
                        console.debug( i, tag );
                        html += '<li><tt class="' + tag.security + '">' + 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 += '<b>UNKNOWN TAG</b> '+content;
@@ -106,7 +101,6 @@ function got_visible_tags(data,textStatus) {
                });
                html += '</ul>';
 
-               scan_tags_active = true;
        }
 
        var arrows = Array( 8592, 8598, 8593, 8599, 8594, 8600, 8595, 8601 );
@@ -117,7 +111,7 @@ function got_visible_tags(data,textStatus) {
                + '</div>'
                + html
                ;
-       $('#tags').html( html );
+       $('#tags').html( html ); // FIXME leaks memory?
 
        pending_jsonp--;
 };
@@ -164,23 +158,20 @@ 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 );
 
        pending_jsonp++;
-       $.getJSON('/sip2/patron_info/'+borrower_cardnumber)
+       $.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) {
@@ -203,7 +194,12 @@ function circulation( barcode, sid ) {
                pending_jsonp++;
                $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+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';
+                       if ( data['fixed'].substr(2,1) == 1 ) color='green';
+
+                       $('ul#books').append('<li style="color:'+color+'">' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' <b>' + data['AF'] + '</b>' : '' ) + '</li>');
+                       $('#books_count').html( $('ul#books > li').length );
                        console.debug( book_barcodes );
                        pending_jsonp--;
                }).fail( function() {
@@ -213,3 +209,6 @@ function circulation( barcode, sid ) {
        }
 }
 
+function end() {
+       // nop
+}