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
54 if ( state == 'end' ) {
55 window.setTimeout(function(){
60 if ( state == 'error' ) {
61 window.setTimeout(function(){
68 function got_visible_tags(data,textStatus) {
69 var html = 'No tags in range';
71 scan_tags_active = false;
72 html = '<ul class="tags">';
73 $.each(data.tags, function(i,tag) {
74 console.debug( i, tag );
75 html += '<li><tt class="' + tag.security + '">' + tag.sid;
76 var content = tag.content
77 if (typeof content === undefined && typeof tag.borrower !== undefined)
78 content = tag.borrower.cardnumber;
81 var is_borrower = false;
85 if ( content.length = 10 && content.substr(0,3) == 130 ) { // book
87 link = 'catalogue/search.pl?q=';
88 } else if ( content.length == 12 && content.substr(0,2) == 20 ) {
90 link = 'members/member.pl?member=';
92 html += '<b>UNKNOWN TAG</b> '+content;
96 html += ' <a href="http://koha.example.com:8080/cgi-bin/koha/'
98 + '" title="lookup in Koha" target="koha-lookup">' + content + '</a>';
102 console.debug( 'calling', state, content );
103 window[state]( content, tag.sid ); // call function with barcode
109 scan_tags_active = true;
112 var arrows = Array( 8592, 8598, 8593, 8599, 8594, 8600, 8595, 8601 );
114 html = '<div class=status>'
116 + ' &#' + arrows[ data.time % arrows.length ] + ';'
120 $('#tags').html( html );
125 function scan_tags() {
126 if ( pending_jsonp ) {
127 console.debug('scan_tags disabled ', pending_jsonp, ' requests waiting');
129 console.info('scan_tags');
131 $.getJSON("/scan?callback=?", got_visible_tags);
134 scan_timeout = window.setTimeout(function(){
136 },tag_rescan); // re-scan every 200ms
139 $(document).ready(function() {
140 $('div#tags').click( function() {
144 change_page('start');
147 function fill_in( where, value ) {
148 $('.'+where).each(function(i, el) {
154 /* Selfcheck state actions */
156 var borrower_cardnumber;
157 var circulation_type;
158 var book_barcodes = {};
160 function start( cardnumber ) {
162 if ( cardnumber.length != 12 || cardnumber.substr(0,2) != "20" ) {
163 console.error(cardnumber, ' is not borrower card');
167 borrower_cardnumber = cardnumber;
169 change_page('borrower_check');
172 function borrower_check() {
174 fill_in( 'borrower_number', borrower_cardnumber );
177 $.getJSON('/sip2/patron_info/'+borrower_cardnumber)
178 .done( function( data ) {
179 console.info('patron', data);
180 fill_in( 'borrower_name', data['AE'] );
181 fill_in( 'borrower_email', data['BE'] );
182 fill_in( 'hold_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 0 * 4 ), 4 ) ) * 1;
183 fill_in( 'overdue_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 1 * 4 ), 4 ) ) * 1;
185 change_page('borrower_info');
186 }).fail( function(data) {
188 change_page('error');
192 function borrower_info() {
196 function circulation( barcode, sid ) {
198 && barcode.length == 10
199 && barcode.substr(0,3) == 130
200 && book_barcodes[barcode] != 1
201 ) { // book, not seen yet
202 book_barcodes[ barcode ] = 1;
204 $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+sid , function( data ) {
205 console.info( circulation_type, data );
206 $('ul#books').append('<li>' + ( data['AJ'] || barcode ) + ' <small>' + data['AF'] + '</small></li>');
207 console.debug( book_barcodes );
209 }).fail( function() {
210 change_page('error');