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 // timeout warning dialog
21 var tick_timeout = 25; // s
22 var tick_warning = 10; // s
25 function start_timeout() {
27 tick = Math.round( tick_timeout * ( 1000 / tag_rescan ) );
30 function change_page(new_state) {
31 if ( state != new_state ) {
33 if ( new_state == 'checkin' ) {
34 new_state = 'circulation'; // page has different name
35 $('.checkout').hide();
37 circulation_type = 'checkin';
38 borrower_cardnumber = 0; // fake
39 } else if ( new_state == 'checkout' ) {
40 new_state = 'circulation'; // page has different name
41 $('.checkout').show();
43 circulation_type = 'checkout';
48 $('.page').each( function(i,el) {
49 if ( el.id != new_state ) {
55 console.info('change_page', state);
57 if ( state == 'start' ) {
58 circulation_type = 'checkout';
60 $('ul#books').html(''); // clear book list
61 $('#books_count').html( 0 );
65 if ( state == 'end' ) {
66 window.setTimeout(function(){
67 //change_page('start');
68 location.reload(); // force js VM to GC?
72 if ( state == 'error' ) {
73 window.setTimeout(function(){
74 //change_page('start');
79 if ( state == 'circulation' || state == 'borrower_info' ) {
82 tick = 0; // timeout disabled
87 function got_visible_tags(data,textStatus) {
88 var html = 'No tags in range';
90 html = '<ul class="tags">';
91 $.each(data.tags, function(i,tag) {
92 console.debug( i, tag );
93 html += '<li><tt class="' + tag.security + '">' + tag.sid;
94 var content = tag.content || tag.borrower.cardnumber;
98 if ( content.length = 10 && content.substr(0,3) == 130 ) { // book
99 link = 'catalogue/search.pl?q=';
100 } else if ( content.length == 12 && content.substr(0,2) == 20 ) {
101 link = 'members/member.pl?member=';
103 html += '<b>UNKNOWN TAG</b> '+content;
107 html += ' <a href="http://koha.example.com:8080/cgi-bin/koha/'
109 + '" title="lookup in Koha" target="koha-lookup">' + content + '</a>';
113 console.debug( 'calling', state, content );
114 window[state]( content, tag.sid ); // call function with barcode
122 var arrows = Array( 8592, 8598, 8593, 8599, 8594, 8600, 8595, 8601 );
124 html = '<div class=status>'
126 + ' &#' + arrows[ data.time % arrows.length ] + ';'
130 $('#tags').html( html ); // FIXME leaks memory?
135 function scan_tags() {
136 if ( pending_jsonp ) {
137 console.debug('scan_tags disabled ', pending_jsonp, ' requests waiting');
139 console.info('scan_tags');
141 $.getJSON("/scan?callback=?", got_visible_tags);
145 if ( tick < tick_warning * ( 1000 / tag_rescan ) ) {
146 $('#tick').html( Math.round( tick * tag_rescan / 1000 ) );
147 $('#timeout').show();
151 $('#timeout').hide();
156 scan_timeout = window.setTimeout(function(){
158 },tag_rescan); // re-scan every 200ms
161 $(document).ready(function() {
162 $('div#tags').click( function() {
166 change_page('start');
169 function fill_in( where, value ) {
170 $('.'+where).each(function(i, el) {
176 /* Selfcheck state actions */
178 var borrower_cardnumber;
179 var circulation_type;
180 var book_barcodes = {};
182 function start( cardnumber ) {
184 if ( cardnumber.length != 12 || cardnumber.substr(0,2) != "20" ) {
185 console.error(cardnumber, ' is not borrower card');
189 borrower_cardnumber = cardnumber; // for circulation
191 fill_in( 'borrower_number', cardnumber );
194 $.getJSON('/sip2/patron_info/'+cardnumber)
195 .done( function( data ) {
196 console.info('patron', data);
197 fill_in( 'borrower_name', data['AE'] );
198 fill_in( 'borrower_email', data['BE'] );
199 fill_in( 'hold_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 0 * 4 ), 4 ) ) * 1;
200 fill_in( 'overdue_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 1 * 4 ), 4 ) ) * 1;
201 fill_in( 'charged_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 2 * 4 ), 4 ) ) * 1;
202 fill_in( 'fine_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 3 * 4 ), 4 ) ) * 1;
204 change_page('borrower_info');
205 }).fail( function(data) {
207 change_page('error');
211 function borrower_info() {
215 function circulation( barcode, sid ) {
217 && barcode.length == 10
218 && barcode.substr(0,3) == 130
219 && book_barcodes[barcode] != 1
220 ) { // book, not seen yet
221 book_barcodes[ barcode ] = 1;
223 $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+sid , function( data ) {
224 console.info( circulation_type, data );
227 var error = 'Transakcija neuspjeĆĄna. Odnesite knjige na pult!';
228 if ( data['fixed'].substr(2,1) == 1 ) {
233 $('ul#books').append('<li style="color:'+color+'">' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' <b>' + data['AF'] + '</b> ' + error : '' ) + '</li>');
234 $('#books_count').html( $('ul#books > li').length );
235 console.debug( book_barcodes );
237 start_timeout(); // reset timeout
238 }).fail( function() {
239 change_page('error');