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) {};
19 function change_page(new_state) {
20 if ( state != new_state ) {
22 if ( new_state == 'checkin' ) {
23 new_state = 'circulation'; // page has different name
24 $('.checkout').hide();
26 circulation_type = 'checkin';
27 borrower_cardnumber = 0; // fake
28 } else if ( new_state == 'checkout' ) {
29 new_state = 'circulation'; // page has different name
30 $('.checkout').show();
32 circulation_type = 'checkout';
37 $('.page').each( function(i,el) {
38 if ( el.id != new_state ) {
44 console.info('change_page', state);
46 if ( state == 'start' ) {
47 circulation_type = 'checkout';
49 $('ul#books').html(''); // clear book list
53 if ( state == 'end' ) {
54 window.setTimeout(function(){
59 if ( state == 'error' ) {
60 window.setTimeout(function(){
67 function got_visible_tags(data,textStatus) {
68 var html = 'No tags in range';
70 html = '<ul class="tags">';
71 $.each(data.tags, function(i,tag) {
72 console.debug( i, tag );
73 html += '<li><tt class="' + tag.security + '">' + tag.sid;
74 var content = tag.content
75 if (typeof content === undefined && typeof tag.borrower !== undefined)
76 content = tag.borrower.cardnumber;
79 var is_borrower = false;
83 if ( content.length = 10 && content.substr(0,3) == 130 ) { // book
85 link = 'catalogue/search.pl?q=';
86 } else if ( content.length == 12 && content.substr(0,2) == 20 ) {
88 link = 'members/member.pl?member=';
90 html += '<b>UNKNOWN TAG</b> '+content;
94 html += ' <a href="http://koha.example.com:8080/cgi-bin/koha/'
96 + '" title="lookup in Koha" target="koha-lookup">' + content + '</a>';
100 console.debug( 'calling', state, content );
101 window[state]( content, tag.sid ); // call function with barcode
108 var arrows = Array( 8592, 8598, 8593, 8599, 8594, 8600, 8595, 8601 );
110 html = '<div class=status>'
112 + ' &#' + arrows[ data.time % arrows.length ] + ';'
116 $('#tags').html( html );
117 scan_timeout = window.setTimeout(function(){
119 },tag_rescan); // re-scan every 200ms
122 function scan_tags() {
123 console.info('scan_tags');
124 $.getJSON("/scan?callback=?", got_visible_tags);
127 $(document).ready(function() {
128 $('div#tags').click( function() {
132 change_page('start');
135 function fill_in( where, value ) {
136 $('.'+where).each(function(i, el) {
142 /* Selfcheck state actions */
144 var borrower_cardnumber;
145 var circulation_type;
146 var book_barcodes = {};
148 function start( cardnumber ) {
150 if ( cardnumber.length != 12 || cardnumber.substr(0,2) != "20" ) {
151 console.error(cardnumber, ' is not borrower card');
155 borrower_cardnumber = cardnumber;
157 change_page('borrower_check');
160 function borrower_check() {
162 fill_in( 'borrower_number', borrower_cardnumber );
164 $.getJSON('/sip2/patron_info/'+borrower_cardnumber)
165 .done( function( data ) {
166 console.info('patron', data);
167 fill_in( 'borrower_name', data['AE'] );
168 fill_in( 'borrower_email', data['BE'] );
169 fill_in( 'hold_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 0 * 4 ), 4 ) ) * 1;
170 fill_in( 'overdue_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 1 * 4 ), 4 ) ) * 1;
171 change_page('borrower_info');
172 }).fail( function(data) {
173 change_page('error');
177 function borrower_info() {
181 function circulation( barcode, sid ) {
183 && barcode.length == 10
184 && barcode.substr(0,3) == 130
185 && book_barcodes[barcode] != 1
186 ) { // book, not seen yet
187 $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+sid , function( data ) {
188 console.info( circulation_type, data );
189 $('ul#books').append('<li>' + ( data['AJ'] || barcode ) + ' <small>' + data['AF'] + '</small></li>');
190 book_barcodes[ barcode ] = 1;
191 console.debug( book_barcodes );
192 }).fail( function() {
193 change_page('error');