3 var end_timeout = 3000; // ms from end page to start page
4 var error_timeout = 5000; // ms from error page to start page
8 window.console = new function() {
9 this.info = function(str) {};
10 this.error = function(str) {};
11 this.debug = function(str) {};
18 function change_page(new_state) {
19 if ( state != new_state ) {
21 if ( new_state == 'checkin' ) {
22 new_state = 'circulation'; // page has different name
23 $('.checkout').hide();
25 } else if ( new_state == 'checkout' ) {
26 new_state = 'circulation'; // page has different name
27 $('.checkout').show();
33 $('.page').each( function(i,el) {
34 if ( el.id != new_state ) {
40 console.info('change_page', state);
42 if ( state == 'start' ) {
45 if ( state == 'end' ) {
46 window.setTimeout(function(){
51 if ( state == 'error' ) {
52 window.setTimeout(function(){
59 function got_visible_tags(data,textStatus) {
60 var html = 'No tags in range';
62 html = '<ul class="tags">';
63 $.each(data.tags, function(i,tag) {
64 console.debug( i, tag );
65 html += '<li><tt class="' + tag.security + '">' + tag.sid;
66 var content = tag.content
67 if (typeof content === undefined && typeof tag.borrower !== undefined)
68 content = tag.borrower.cardnumber;
71 var is_borrower = false;
75 if ( content.length = 10 && content.substr(0,3) == 130 ) { // book
77 link = 'catalogue/search.pl?q=';
78 } else if ( content.length == 12 && content.substr(0,2) == 20 ) {
80 link = 'members/member.pl?member=';
82 html += '<b>UNKNOWN TAG</b> '+content;
86 html += ' <a href="http://koha.example.com:8080/cgi-bin/koha/'
88 + '" title="lookup in Koha" target="koha-lookup">' + content + '</a>';
92 console.debug( 'calling', state, content );
93 window[state]( content ); // call function with barcode
100 var arrows = Array( 8592, 8598, 8593, 8599, 8594, 8600, 8595, 8601 );
102 html = '<div class=status>'
104 + ' &#' + arrows[ data.time % arrows.length ] + ';'
108 $('#tags').html( html );
109 scan_timeout = window.setTimeout(function(){
111 },200); // re-scan every 200ms
114 function scan_tags() {
115 if ( $('input#pull-reader').attr('checked') ) {
116 console.info('scan_tags');
117 $.getJSON("/scan?callback=?", got_visible_tags);
121 function start_scan() {
122 $('input#pull-reader').attr('checked', true);
126 function stop_scan() {
127 $('input#pull-reader').attr('checked', '');
130 $(document).ready(function() {
131 $('input#pull-reader').click( function() {
135 $('div#tags').click( function() {
136 $('input#pull-reader').attr('checked', false);
139 change_page('start');
142 function fill_in( where, value ) {
143 $('.'+where).each(function(i, el) {
149 /* Selfcheck state actions */
151 var borrower_cardnumber;
152 var circulation_type;
153 var book_barcodes = {};
155 function start( cardnumber ) {
157 if ( cardnumber.length != 12 || cardnumber.substr(0,2) != "20" ) {
158 console.error(cardnumber, ' is not borrower card');
162 borrower_cardnumber = cardnumber;
163 circulation_type = 'checkout';
166 change_page('borrower_check');
169 function borrower_check() {
173 fill_in( 'borrower_number', borrower_cardnumber );
175 $.getJSON('/sip2/patron_info/'+borrower_cardnumber)
176 .done( function( data ) {
177 console.info('patron', data);
178 fill_in( 'borrower_name', data['AE'] );
179 fill_in( 'borrower_email', data['BE'] );
180 fill_in( 'hold_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 0 * 4 ), 4 ) ) * 1;
181 fill_in( 'overdue_items', data['fixed'].substr( 2 + 14 + 3 + 18 + ( 1 * 4 ), 4 ) ) * 1;
182 change_page('borrower_info');
183 }).fail( function(data) {
184 change_page('error');
188 function borrower_info() {
192 function circulation( barcode ) {
194 && barcode.length == 10
195 && barcode.substr(0,3) == 130
196 && typeof book_barcodes[barcode] !== undefined
197 ) { // book, not seen yet
198 $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode , function( data ) {
199 console.info( circulation_type, data );
200 $('ul#books').append('<li>' + data['AJ'] + ' <small>' + data['AF'] + '</small></li>');
201 book_barcodes[ barcode ] = 1;
202 console.debug( book_barcodes );
203 }).fail( function() {
204 change_page('error');