4 window.console = new function() {
5 this.info = function(str) {};
6 this.error = function(str) {};
7 this.debug = function(str) {};
14 function change_page(new_state) {
15 if ( state != new_state ) {
17 if ( new_state == 'checkin' ) {
18 new_state = 'circulation'; // page has different name
19 $('.checkout').hide();
21 } else if ( new_state == 'checkout' ) {
22 new_state = 'circulation'; // page has different name
23 $('.checkout').show();
29 $('.page').each( function(i,el) {
30 if ( el.id != new_state ) {
36 console.info('change_page', state);
38 if ( state == 'start' ) {
41 if ( state == 'error' ) {
42 // FIXME: implement timeout and go back to start
47 function got_visible_tags(data,textStatus) {
48 var html = 'No tags in range';
50 html = '<ul class="tags">';
51 $.each(data.tags, function(i,tag) {
52 console.debug( i, tag );
53 html += '<li><tt class="' + tag.security + '">' + tag.sid;
54 var content = tag.content
55 if (typeof content === undefined && typeof tag.borrower !== undefined)
56 content = tag.borrower.cardnumber;
59 var is_borrower = false;
63 if ( content.length = 10 && content.substr(0,3) == 130 ) { // book
65 link = 'catalogue/search.pl?q=';
66 } else if ( content.length == 12 && content.substr(0,2) == 20 ) {
68 link = 'members/member.pl?member=';
70 html += '<b>UNKNOWN TAG</b> '+content;
74 html += ' <a href="http://koha.example.com:8080/cgi-bin/koha/'
76 + '" title="lookup in Koha" target="koha-lookup">' + content + '</a>';
80 console.debug( 'calling', state, content );
81 window[state]( content ); // call function with barcode
88 var arrows = Array( 8592, 8598, 8593, 8599, 8594, 8600, 8595, 8601 );
90 html = '<div class=status>'
92 + ' &#' + arrows[ data.time % arrows.length ] + ';'
96 $('#tags').html( html );
97 scan_timeout = window.setTimeout(function(){
99 },200); // re-scan every 200ms
102 function scan_tags() {
103 if ( $('input#pull-reader').attr('checked') ) {
104 console.info('scan_tags');
105 $.getJSON("/scan?callback=?", got_visible_tags);
109 function start_scan() {
110 $('input#pull-reader').attr('checked', true);
114 function stop_scan() {
115 $('input#pull-reader').attr('checked', '');
118 $(document).ready(function() {
119 $('input#pull-reader').click( function() {
123 $('div#tags').click( function() {
124 $('input#pull-reader').attr('checked', false);
127 change_page('start');
130 function fill_in( where, value ) {
131 $('.'+where).each(function(i, el) {
137 /* Selfcheck state actions */
139 var borrower_cardnumber;
140 var circulation_type;
143 function start( cardnumber ) {
145 if ( cardnumber.length != 12 || cardnumber.substr(0,2) != "20" ) {
146 console.error(cardnumber, ' is not borrower card');
150 borrower_cardnumber = cardnumber;
151 circulation_type = 'checkout';
154 change_page('borrower_check');
157 function borrower_check() {
161 fill_in( 'borrower_number', borrower_cardnumber );
163 $.getJSON('/sip2/patron_info/'+borrower_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;
170 change_page('borrower_info');
171 }).fail( function(data) {
172 change_page('error');
176 function borrower_info() {
180 function circulation( barcode ) {
182 && barcode.length == 10
183 && barcode.substr(0,3) == 130
184 && ! book_barcodes[barcode]
185 ) { // book, not seen yet
186 $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode , function( data ) {
187 console.info( circulation_type, data );
188 $('ul#books').append('<li>' + data['AJ'] + ' <small>' + data['AF'] + '</small></li>');
189 book_barcodes[ barcode ] = 1;
190 console.debug( book_barcodes );
191 }).fail( function() {
192 change_page('error');