2 * RFID support for Koha
4 * Writtern by Dobrica Pavlinusic <dpavlin@rot13.org> under GPL v2 or later
6 * This provides example how to intergrate JSONP interface from
8 * scripts/RFID-JSONP-server.pl
10 * to provide overlay for tags in range and emulate form fill for Koha Library System
11 * which allows check-in and checkout-operations without touching html interface
13 * You will have to inject remote javascript in Koha intranetuserjs using:
15 // inject JavaScript RFID support
16 $.getScript('http://localhost:9000/examples/koha-rfid.js');
20 function barcode_on_screen(barcode) {
22 $('table tr td a:contains(130)').each( function(i,o) {
23 var possible = $(o).text();
24 console.debug(i,o,possible, barcode);
25 if ( possible == barcode ) found++;
30 function rfid_secure(t,val) {
31 if ( t.security.toUpperCase() == val.toUpperCase() ) return;
32 console.debug('rfid_secure', t.content, t.sid, val);
33 if ( barcode_on_screen(t.content) )
34 $.getJSON( 'http://localhost:9000/secure.js?' + t.sid + '=' + val + ';callback=?' )
37 var rfid_reset_field = false;
39 function rfid_scan(data,textStatus) {
40 var rfid_refresh = 1500; // ms
42 console.debug( 'rfid_scan', data, textStatus );
44 var span = $('span#rfid');
46 if ( span.size() == 0 ) // insert last in language bar on bottom
47 span = $('ul#i18nMenu').append('<li><span id=rfid>RFID reader found<span>');
49 if ( span.size() == 0 ) // or before login on top
50 span = $('div#login').prepend('<span id=rfid>RFID reader found</span>');
52 span = $('span#rfid');
56 if ( data.tags.length === 1 ) {
58 // if ( span.text() != t.content ) {
59 if ( 1 ) { // force update of security
61 var url = document.location.toString();
62 var circulation = url.substr(-14,14) == 'circulation.pl';
63 var returns = url.substr(-10,10) == 'returns.pl';
65 if ( t.content.length == 0 ) { // empty tag
67 span.text( t.sid + ' empty' ).css('color', 'red' );
69 } else if ( t.content.substr(0,3) == '130' ) { // books
71 if ( circulation ) rfid_secure( t, 'D7' );
72 if ( returns ) rfid_secure( t, 'DA' );
75 if ( t.security.toUpperCase() == 'DA' ) color = 'red';
76 if ( t.security.toUpperCase() == 'D7' ) color = 'green';
77 span.text( t.content ).css('color', color);
79 if ( ! barcode_on_screen( t.content ) ) {
80 rfid_reset_field = 'barcode';
81 var i = $('input[name=barcode]:last');
82 if ( i.val() != t.content ) {
85 .closest('form').submit();
90 span.text( t.content ).css('color', 'blue' );
92 if ( $('.patroninfo:contains('+t.content+')').length == 1 ) {
93 console.debug('not submitting', t.contains);
96 rfid_reset_field = 'findborrower';
97 $('input[name=findborrower]').val( t.content )
103 var error = data.tags.length + ' tags near reader: ';
104 $.each( data.tags, function(i,tag) { error += tag.content + ' '; } );
105 span.text( error ).css( 'color', 'red' );
109 span.text( 'no tags in range' ).css('color','gray');
110 if ( rfid_reset_field ) {
111 $('input[name='+rfid_reset_field+']').val( '' );
112 rfid_reset_field = false;
116 if (rfid_refresh > 1) {
117 window.setTimeout( function() {
118 $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);
121 console.debug('rfid_refresh disabled',rfid_refresh);
125 $(document).ready( function() {
126 $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);