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 html = '<ul class="tags">';
72 $.each(data.tags, function(i,tag) {
73 console.debug( i, tag );
74 html += '<li><tt class="' + tag.security + '">' + tag.sid;
75 var content = tag.content || tag.borrower.cardnumber;
79 if ( content.length = 10 && content.substr(0,3) == 130 ) { // book
80 link = 'catalogue/search.pl?q=';
81 } else if ( content.length == 12 && content.substr(0,2) == 20 ) {
82 link = 'members/member.pl?member=';
84 html += '<b>UNKNOWN TAG</b> '+content;
88 html += ' <a href="http://koha.example.com:8080/cgi-bin/koha/'
90 + '" title="lookup in Koha" target="koha-lookup">' + content + '</a>';
94 console.debug( 'calling', state, content );
95 window[state]( content, tag.sid ); // call function with barcode
103 var arrows = Array( 8592, 8598, 8593, 8599, 8594, 8600, 8595, 8601 );
105 html = '<div class=status>'
107 + ' &#' + arrows[ data.time % arrows.length ] + ';'
111 $('#tags').html( html ); // FIXME leaks memory?
116 function scan_tags() {
117 if ( pending_jsonp ) {
118 console.debug('scan_tags disabled ', pending_jsonp, ' requests waiting');
120 console.info('scan_tags');
122 $.getJSON("/scan?callback=?", got_visible_tags);
125 scan_timeout = window.setTimeout(function(){
127 },tag_rescan); // re-scan every 200ms
130 $(document).ready(function() {
131 $('div#tags').click( function() {
135 change_page('start');
138 function fill_in( where, value ) {
139 $('.'+where).each(function(i, el) {
145 /* Selfcheck state actions */
147 var borrower_cardnumber;
148 var circulation_type;
149 var book_barcodes = {};
151 function start( cardnumber ) {
153 if ( cardnumber.length != 12 || cardnumber.substr(0,2) != "20" ) {
154 console.error(cardnumber, ' is not borrower card');
158 borrower_cardnumber = cardnumber; // for circulation
160 fill_in( 'borrower_number', cardnumber );
163 $.getJSON('/sip2/patron_info/'+cardnumber)
164 .done( function( data ) {
165 console.info('patron', data);
166 fill_in( 'borrower_name', data['AE'] );
167 fill_in( 'borrower_email', data['BE'] );
168 fill_in( 'hold_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 0 * 4 ), 4 ) ) * 1;
169 fill_in( 'overdue_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 1 * 4 ), 4 ) ) * 1;
171 change_page('borrower_info');
172 }).fail( function(data) {
174 change_page('error');
178 function borrower_info() {
182 function circulation( barcode, sid ) {
184 && barcode.length == 10
185 && barcode.substr(0,3) == 130
186 && book_barcodes[barcode] != 1
187 ) { // book, not seen yet
188 book_barcodes[ barcode ] = 1;
190 $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+sid , function( data ) {
191 console.info( circulation_type, data );
192 $('ul#books').append('<li>' + ( data['AJ'] || barcode ) + ( data['AF'] ? ' <b>' + data['AF'] + '</b>' : '' ) + '</li>');
193 console.debug( book_barcodes );
195 }).fail( function() {
196 change_page('error');