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(barcode,sid,val) {
31 console.debug('rfid_secure', barcode, sid, val);
32 if ( barcode_on_screen(barcode) )
33 $.getJSON( 'http://localhost:9000/secure.js?' + sid + '=' + val + ';callback=?' )
36 var rfid_reset_field = false;
38 function rfid_scan(data,textStatus) {
39 // console.debug( 'rfid_scan', data, textStatus );
41 var span = $('span#rfid');
43 if ( span.size() == 0 ) // insert last in language bar on bottom
44 span = $('ul#i18nMenu').append('<li><span id=rfid>RFID reader found<span>');
46 if ( span.size() == 0 ) // or before login on top
47 span = $('div#login').prepend('<span id=rfid>RFID reader found</span>');
49 span = $('span#rfid');
53 if ( data.tags.length === 1 ) {
55 // if ( span.text() != t.content ) {
56 if ( 1 ) { // force update of security
58 var url = document.location.toString();
59 var circulation = url.substr(-14,14) == 'circulation.pl';
60 var returns = url.substr(-10,10) == 'returns.pl';
62 if ( t.content.length == 0 ) { // empty tag
64 span.text( t.sid + ' empty' ).css('color', 'red' );
66 } else if ( t.content.substr(0,3) == '130' ) { // books
69 rfid_secure( t.content, t.sid, 'D7' );
71 rfid_secure( t.content, t.sid, 'DA' );
74 if ( t.security.toUpperCase() == 'DA' ) color = 'red';
75 if ( t.security.toUpperCase() == 'D7' ) color = 'green';
76 span.text( t.content ).css('color', color);
78 if ( ! barcode_on_screen( t.content ) ) {
79 rfid_reset_field = 'barcode';
80 var i = $('input[name=barcode]:last');
81 if ( i.val() != t.content )
83 .closest('form').submit();
87 span.text( t.content ).css('color', 'blue' );
89 if ( url.substr(-14,14) != 'circulation.pl' || $('form[name=mainform]').size() == 0 ) {
90 rfid_reset_field = 'findborrower';
91 $('input[name=findborrower]').val( t.content )
97 var error = data.tags.length + ' tags near reader: ';
98 $.each( data.tags, function(i,tag) { error += tag.content + ' '; } );
99 span.text( error ).css( 'color', 'red' );
103 span.text( 'no tags in range' ).css('color','gray');
104 if ( rfid_reset_field ) {
105 $('input[name='+rfid_reset_field+']').val( '' );
106 rfid_reset_field = false;
110 window.setTimeout( function() {
111 $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);
115 $(document).ready( function() {
116 $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);