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
30 function start_timeout() {
32 tick = Math.round( tick_timeout * ( 1000 / tag_rescan ) );
35 function change_page(new_state) {
36 if ( state != new_state ) {
38 if ( new_state == 'checkin' ) {
39 new_state = 'circulation'; // page has different name
40 $('.checkout').hide();
42 circulation_type = 'checkin';
43 borrower_cardnumber = 0; // fake
44 only_reader = '/only/3M';
45 } else if ( new_state == 'checkout' ) {
46 new_state = 'circulation'; // page has different name
47 $('.checkout').show();
49 circulation_type = 'checkout';
50 only_reader = '/only/3M';
55 $('.page').each( function(i,el) {
56 if ( el.id != new_state ) {
62 console.info('change_page', state);
64 if ( state == 'start' ) {
65 circulation_type = 'checkout';
67 $('ul#books').html(''); // clear book list
68 $('#books_count').html( 0 );
69 only_reader = '/only/librfid';
73 if ( state == 'end' ) {
74 window.setTimeout(function(){
75 //change_page('start');
76 location.reload(); // force js VM to GC?
80 if ( state == 'error' ) {
82 window.setTimeout(function(){
83 //change_page('start');
88 if ( state == 'circulation' || state == 'borrower_info' ) {
91 tick = 0; // timeout disabled
96 function got_visible_tags(data,textStatus) {
97 var html = 'No tags in range';
99 html = '<ul class="tags">';
100 $.each(data.tags, function(i,tag) {
101 console.debug( i, tag );
102 html += '<li><tt class="' + tag.security + '">' + tag.sid;
103 var content = tag.content || tag.borrower.cardnumber;
107 if ( content.length = 10 && content.substr(0,3) == 130 ) { // book
108 link = 'catalogue/search.pl?q=';
109 } else if ( content.length == 12 && content.substr(0,2) == 20 ) {
110 link = 'members/member.pl?member=';
111 } else if ( tag.tag_type == 'SmartX' ) {
112 link = 'members/member.pl?member=';
114 html += '<b>UNKNOWN TAG</b> '+content;
118 html += ' <a href="http://koha.example.com:8080/cgi-bin/koha/'
120 + '" title="lookup in Koha" target="koha-lookup">' + content + '</a>';
124 console.debug( 'calling', state, content );
125 window[state]( content, tag ); // call function with barcode
133 var arrows = Array( 8592, 8598, 8593, 8599, 8594, 8600, 8595, 8601 );
135 html = '<div class=status>'
137 + ' &#' + arrows[ data.time % arrows.length ] + ';'
141 $('#tags').html( html ); // FIXME leaks memory?
146 var wait_counter = 0;
148 function scan_tags() {
149 if ( pending_jsonp ) {
151 console.debug('scan_tags disabled ', pending_jsonp, ' requests waiting counter', wait_counter);
152 if ( wait_counter > 3 ) $('#working').show();
154 console.info('scan_tags', only_reader);
156 $.getJSON("/scan"+only_reader+"?callback=?", got_visible_tags).fail( function(data) {
157 console.error('scan error pending jsonp', pending_jsonp);
161 $('#working').hide();
165 if ( tick < tick_warning * ( 1000 / tag_rescan ) ) {
166 $('#tick').html( Math.round( tick * tag_rescan / 1000 ) );
167 $('#timeout').show();
171 $('#timeout').hide();
176 scan_timeout = window.setTimeout(function(){
178 },tag_rescan); // re-scan every 200ms
181 $(document).ready(function() {
182 $('div#tags').click( function() {
186 change_page('start');
189 function fill_in( where, value ) {
190 $('.'+where).each(function(i, el) {
196 /* Selfcheck state actions */
198 var borrower_cardnumber;
199 var circulation_type;
200 var book_barcodes = {};
202 function start( cardnumber, tag ) {
204 if ( tag.tag_type != 'SmartX' && ( cardnumber.length != 12 || cardnumber.substr(0,2) != "20" ) ) {
205 console.error(cardnumber, 'is not borrower card', tag);
209 borrower_cardnumber = cardnumber; // for circulation
211 fill_in( 'borrower_number', cardnumber );
214 $.getJSON('/sip2/patron_info/'+cardnumber)
215 .done( function( data ) {
216 console.info('patron', data);
217 fill_in( 'borrower_name', data['AE'] );
218 fill_in( 'borrower_email', data['BE'] );
219 fill_in( 'hold_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 0 * 4 ), 4 ) * 1 );
220 //fill_in( 'overdue_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 1 * 4 ), 4 ) * 1 );
221 var overdue = data['fixed'].substr( 2 + 14 + 3 + 18 + ( 1 * 4 ), 4 ) * 1;
223 overdue = '<span style="color:red">'+overdue+'</span>';
226 fill_in( 'overdue_items', overdue );
227 fill_in( 'charged_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 2 * 4 ), 4 ) * 1 );
228 fill_in( 'fine_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 3 * 4 ), 4 ) * 1 );
232 change_page('borrower_info');
233 }).fail( function(data) {
235 change_page('error');
239 function borrower_info() {
243 function circulation( barcode, tag ) {
245 && barcode.length == 10
246 && barcode.substr(0,3) == 130
247 && book_barcodes[barcode] != 1
248 && tag.reader == '3M810'
249 ) { // book, not seen yet
250 book_barcodes[ barcode ] = 1;
252 $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+tag.sid , function( data ) {
253 console.info( circulation_type, data );
256 var error = 'Transakcija neuspjeĆĄna. Odnesite knjige na pult!';
257 if ( data['fixed'].substr(2,1) == 1 ) {
264 $('ul#books').append('<li>' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' <b style="color:'+color+'">' + data['AF'] + ' ' + error : '</b>' ) + '</li>');
265 $('#books_count').html( $('ul#books > li').length );
266 console.debug( book_barcodes );
268 start_timeout(); // reset timeout
269 }).fail( function() {
270 change_page('error');