3 var end_timeout = 3000; // ms from end page to start page
4 var error_timeout = 5000; // ms from error page to start page
5 var tag_rescan = 200; // ms rescan tags every 0.2s
9 window.console = new function() {
10 this.info = function(str) {};
11 this.error = function(str) {};
12 this.debug = function(str) {};
18 var pending_jsonp = 0;
20 function change_page(new_state) {
21 if ( state != new_state ) {
23 if ( new_state == 'checkin' ) {
24 new_state = 'circulation'; // page has different name
25 $('.checkout').hide();
27 circulation_type = 'checkin';
28 borrower_cardnumber = 0; // fake
29 } else if ( new_state == 'checkout' ) {
30 new_state = 'circulation'; // page has different name
31 $('.checkout').show();
33 circulation_type = 'checkout';
38 $('.page').each( function(i,el) {
39 if ( el.id != new_state ) {
45 console.info('change_page', state);
47 if ( state == 'start' ) {
48 circulation_type = 'checkout';
50 $('ul#books').html(''); // clear book list
51 $('#books_count').html( 0 );
55 if ( state == 'end' ) {
56 window.setTimeout(function(){
57 //change_page('start');
58 location.reload(); // force js VM to GC?
62 if ( state == 'error' ) {
63 window.setTimeout(function(){
64 //change_page('start');
71 function got_visible_tags(data,textStatus) {
72 var html = 'No tags in range';
74 html = '<ul class="tags">';
75 $.each(data.tags, function(i,tag) {
76 console.debug( i, tag );
77 html += '<li><tt class="' + tag.security + '">' + tag.sid;
78 var content = tag.content || tag.borrower.cardnumber;
82 if ( content.length = 10 && content.substr(0,3) == 130 ) { // book
83 link = 'catalogue/search.pl?q=';
84 } else if ( content.length == 12 && content.substr(0,2) == 20 ) {
85 link = 'members/member.pl?member=';
87 html += '<b>UNKNOWN TAG</b> '+content;
91 html += ' <a href="http://koha.example.com:8080/cgi-bin/koha/'
93 + '" title="lookup in Koha" target="koha-lookup">' + content + '</a>';
97 console.debug( 'calling', state, content );
98 window[state]( content, tag.sid ); // call function with barcode
106 var arrows = Array( 8592, 8598, 8593, 8599, 8594, 8600, 8595, 8601 );
108 html = '<div class=status>'
110 + ' &#' + arrows[ data.time % arrows.length ] + ';'
114 $('#tags').html( html ); // FIXME leaks memory?
119 function scan_tags() {
120 if ( pending_jsonp ) {
121 console.debug('scan_tags disabled ', pending_jsonp, ' requests waiting');
123 console.info('scan_tags');
125 $.getJSON("/scan?callback=?", got_visible_tags);
128 scan_timeout = window.setTimeout(function(){
130 },tag_rescan); // re-scan every 200ms
133 $(document).ready(function() {
134 $('div#tags').click( function() {
138 change_page('start');
141 function fill_in( where, value ) {
142 $('.'+where).each(function(i, el) {
148 /* Selfcheck state actions */
150 var borrower_cardnumber;
151 var circulation_type;
152 var book_barcodes = {};
154 function start( cardnumber ) {
156 if ( cardnumber.length != 12 || cardnumber.substr(0,2) != "20" ) {
157 console.error(cardnumber, ' is not borrower card');
161 borrower_cardnumber = cardnumber; // for circulation
163 fill_in( 'borrower_number', cardnumber );
166 $.getJSON('/sip2/patron_info/'+cardnumber)
167 .done( function( data ) {
168 console.info('patron', data);
169 fill_in( 'borrower_name', data['AE'] );
170 fill_in( 'borrower_email', data['BE'] );
171 fill_in( 'hold_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 0 * 4 ), 4 ) ) * 1;
172 fill_in( 'overdue_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 1 * 4 ), 4 ) ) * 1;
173 fill_in( 'charged_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 2 * 4 ), 4 ) ) * 1;
174 fill_in( 'fine_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 3 * 4 ), 4 ) ) * 1;
176 change_page('borrower_info');
177 }).fail( function(data) {
179 change_page('error');
183 function borrower_info() {
187 function circulation( barcode, sid ) {
189 && barcode.length == 10
190 && barcode.substr(0,3) == 130
191 && book_barcodes[barcode] != 1
192 ) { // book, not seen yet
193 book_barcodes[ barcode ] = 1;
195 $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+sid , function( data ) {
196 console.info( circulation_type, data );
199 if ( data['fixed'].substr(2,1) == 1 ) color='green';
201 $('ul#books').append('<li style="color:'+color+'">' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' <b>' + data['AF'] + '</b>' : '' ) + '</li>');
202 $('#books_count').html( $('ul#books > li').length );
203 console.debug( book_barcodes );
205 }).fail( function() {
206 change_page('error');