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;
21 // timeout warning dialog
22 var tick_timeout = 25; // s
23 var tick_warning = 10; // s
26 function start_timeout() {
28 tick = Math.round( tick_timeout * ( 1000 / tag_rescan ) );
31 function change_page(new_state) {
32 if ( state != new_state ) {
34 if ( new_state == 'checkin' ) {
35 new_state = 'circulation'; // page has different name
36 $('.checkout').hide();
38 circulation_type = 'checkin';
39 borrower_cardnumber = 0; // fake
40 only_reader = '/only/3M';
41 } else if ( new_state == 'checkout' ) {
42 new_state = 'circulation'; // page has different name
43 $('.checkout').show();
45 circulation_type = 'checkout';
46 only_reader = '/only/3M';
51 $('.page').each( function(i,el) {
52 if ( el.id != new_state ) {
58 console.info('change_page', state);
60 if ( state == 'start' ) {
61 circulation_type = 'checkout';
63 $('ul#books').html(''); // clear book list
64 $('#books_count').html( 0 );
69 if ( state == 'end' ) {
70 window.setTimeout(function(){
71 //change_page('start');
72 location.reload(); // force js VM to GC?
76 if ( state == 'error' ) {
77 window.setTimeout(function(){
78 //change_page('start');
83 if ( state == 'circulation' || state == 'borrower_info' ) {
86 tick = 0; // timeout disabled
91 function got_visible_tags(data,textStatus) {
92 var html = 'No tags in range';
94 html = '<ul class="tags">';
95 $.each(data.tags, function(i,tag) {
96 console.debug( i, tag );
97 html += '<li><tt class="' + tag.security + '">' + tag.sid;
98 var content = tag.content || tag.borrower.cardnumber;
102 if ( content.length = 10 && content.substr(0,3) == 130 ) { // book
103 link = 'catalogue/search.pl?q=';
104 } else if ( content.length == 12 && content.substr(0,2) == 20 ) {
105 link = 'members/member.pl?member=';
106 } else if ( tag.tag_type == 'SmartX' ) {
107 link = 'members/member.pl?member=';
109 html += '<b>UNKNOWN TAG</b> '+content;
113 html += ' <a href="http://koha.example.com:8080/cgi-bin/koha/'
115 + '" title="lookup in Koha" target="koha-lookup">' + content + '</a>';
119 console.debug( 'calling', state, content );
120 window[state]( content, tag ); // call function with barcode
128 var arrows = Array( 8592, 8598, 8593, 8599, 8594, 8600, 8595, 8601 );
130 html = '<div class=status>'
132 + ' &#' + arrows[ data.time % arrows.length ] + ';'
136 $('#tags').html( html ); // FIXME leaks memory?
141 var wait_counter = 0;
143 function scan_tags() {
144 if ( pending_jsonp ) {
146 console.debug('scan_tags disabled ', pending_jsonp, ' requests waiting counter', wait_counter);
147 if ( wait_counter > 3 ) $('#working').show();
149 console.info('scan_tags', only_reader);
151 $.getJSON("/scan"+only_reader+"?callback=?", got_visible_tags).fail( function(data) {
152 console.error('scan error pending jsonp', pending_jsonp);
156 $('#working').hide();
160 if ( tick < tick_warning * ( 1000 / tag_rescan ) ) {
161 $('#tick').html( Math.round( tick * tag_rescan / 1000 ) );
162 $('#timeout').show();
166 $('#timeout').hide();
171 scan_timeout = window.setTimeout(function(){
173 },tag_rescan); // re-scan every 200ms
176 $(document).ready(function() {
177 $('div#tags').click( function() {
181 change_page('start');
184 function fill_in( where, value ) {
185 $('.'+where).each(function(i, el) {
191 /* Selfcheck state actions */
193 var borrower_cardnumber;
194 var circulation_type;
195 var book_barcodes = {};
197 function start( cardnumber, tag ) {
199 if ( tag.tag_type != 'SmartX' && ( cardnumber.length != 12 || cardnumber.substr(0,2) != "20" ) ) {
200 console.error(cardnumber, 'is not borrower card', tag);
204 borrower_cardnumber = cardnumber; // for circulation
206 fill_in( 'borrower_number', cardnumber );
209 $.getJSON('/sip2/patron_info/'+cardnumber)
210 .done( function( data ) {
211 console.info('patron', data);
212 fill_in( 'borrower_name', data['AE'] );
213 fill_in( 'borrower_email', data['BE'] );
214 fill_in( 'hold_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 0 * 4 ), 4 ) ) * 1;
215 fill_in( 'overdue_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 1 * 4 ), 4 ) ) * 1;
216 fill_in( 'charged_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 2 * 4 ), 4 ) ) * 1;
217 fill_in( 'fine_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 3 * 4 ), 4 ) ) * 1;
219 change_page('borrower_info');
220 }).fail( function(data) {
222 change_page('error');
226 function borrower_info() {
230 function circulation( barcode, tag ) {
232 && barcode.length == 10
233 && barcode.substr(0,3) == 130
234 && book_barcodes[barcode] != 1
235 ) { // book, not seen yet
236 book_barcodes[ barcode ] = 1;
238 $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+tag.sid , function( data ) {
239 console.info( circulation_type, data );
242 var error = 'Transakcija neuspjeĆĄna. Odnesite knjige na pult!';
243 if ( data['fixed'].substr(2,1) == 1 ) {
248 $('ul#books').append('<li style="color:'+color+'">' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' <b>' + data['AF'] + '</b> ' + error : '' ) + '</li>');
249 $('#books_count').html( $('ul#books > li').length );
250 console.debug( book_barcodes );
252 start_timeout(); // reset timeout
253 }).fail( function() {
254 change_page('error');