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 if ( possible == barcode ) found++;
29 function rfid_secure(t,val) {
30 if ( t.security.toUpperCase() == val.toUpperCase() ) return;
31 console.debug('rfid_secure', t.content, t.sid, val);
32 if ( barcode_on_screen(t.content) )
33 $.getJSON( 'http://localhost:9000/secure.js?' + t.sid + '=' + val + ';callback=?' )
36 var rfid_reset_field = false;
38 function rfid_scan(data,textStatus) {
39 var rfid_refresh = 1500; // ms
41 console.debug( 'rfid_scan', data, textStatus );
43 var span = $('span#rfid');
45 if ( span.size() == 0 ) // insert last in language bar on bottom
46 span = $('ul#i18nMenu').append('<li><span id=rfid>RFID reader found<span>');
48 if ( span.size() == 0 ) // or before login on top
49 span = $('div#login').prepend('<span id=rfid>RFID reader found</span>');
51 span = $('span#rfid');
55 if ( data.tags.length === 1 ) {
57 // if ( span.text() != t.content ) {
58 if ( 1 ) { // force update of security
60 var script_name = document.location.pathname.split(/\//).pop();
61 var circulation = script_name == 'circulation.pl';
62 var returns = script_name == 'returns.pl';
64 if ( t.content.length == 0 ) { // empty tag
66 span.text( t.sid + ' empty' ).css('color', 'red' );
68 } else if ( t.content.substr(0,3) == '130' ) { // books
70 if ( circulation ) rfid_secure( t, 'D7' );
71 if ( returns ) rfid_secure( t, '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 ) {
84 .closest('form').submit();
89 span.text( t.content ).css('color', 'blue' );
91 if ( $('.patroninfo:contains('+t.content+')').length == 1 ) {
92 console.debug('not submitting', t.contains);
95 rfid_reset_field = 'findborrower';
96 $('input[name=findborrower]').val( t.content )
102 var error = data.tags.length + ' tags near reader: ';
103 $.each( data.tags, function(i,tag) { error += tag.content + ' '; } );
104 span.text( error ).css( 'color', 'red' );
108 span.text( 'no tags in range' ).css('color','gray');
109 if ( rfid_reset_field ) {
110 $('input[name='+rfid_reset_field+']').val( '' );
111 rfid_reset_field = false;
115 if (rfid_refresh > 1) {
116 window.setTimeout( function() {
117 $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);
120 console.debug('rfid_refresh disabled',rfid_refresh);
124 $(document).ready( function() {
125 $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);