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 var rfid_refresh = 1500; // ms
31 function rfid_secure_json(t,val, success) {
32 if ( t.security.toUpperCase() == val.toUpperCase() ) return;
33 rfid_refresh = 0; // disable rfid pull until secure call returns
34 console.log('rfid_secure_json', t, val);
35 $.getJSON( 'http://localhost:9000/secure.js?' + t.sid + '=' + val + ';callback=?', success );
38 function rfid_secure_check(t,val) {
39 if ( barcode_on_screen(t.content) ) {
40 rfid_secure_json(t, val);
45 var rfid_reset_field = false;
47 function rfid_scan(data,textStatus) {
49 console.debug( 'rfid_scan', data, textStatus );
51 var span = $('span#rfid');
53 if ( span.size() == 0 ) // insert last in language bar on bottom
54 span = $('ul#i18nMenu').append('<li><span id=rfid>RFID reader found<span>');
56 if ( span.size() == 0 ) // or before login on top
57 span = $('div#login').prepend('<span id=rfid>RFID reader found</span>');
59 span = $('span#rfid');
63 if ( data.tags.length === 1 ) {
65 // if ( span.text() != t.content ) {
66 if ( 1 ) { // force update of security
68 var script_name = document.location.pathname.split(/\//).pop();
69 var tab_active = $("#header_search .ui-tabs-panel:not(.ui-tabs-hide)").prop('id');
70 var circulation = script_name == 'circulation.pl';
71 var returns = script_name == 'returns.pl' || tab_active == 'checkin_search';
73 if ( t.content.length == 0 ) { // empty tag
75 span.text( t.sid + ' empty' ).css('color', 'red' );
77 } else if ( t.content.substr(0,3) == '130' ) { // books
80 if ( t.security.toUpperCase() == 'DA' ) color = 'red';
81 if ( t.security.toUpperCase() == 'D7' ) color = 'green';
82 span.text( t.content ).css('color', color);
84 if ( ! barcode_on_screen( t.content ) || returns ) {
85 rfid_reset_field = 'barcode';
87 // return must be first to catch change of tab to check-in
88 var afi_secure = returns ? 'DA' : 'D7';
89 var form_selector = returns ? 'first' : 'last';
90 if ( returns || circulation ) {
91 var i = $('input[name=barcode]:'+form_selector);
92 if ( i.val() != t.content ) {
93 rfid_secure_json( t, afi_secure, function(data) {
94 console.log('secure', afi_secure, data);
95 i.val( t.content ).closest('form').submit();
99 console.error('not in circulation or returns');
104 span.text( t.content ).css('color', 'blue' );
106 if ( $('.patroninfo:contains('+t.content+')').length == 1 ) {
107 console.debug('not submitting', t.contains);
109 rfid_refresh = 0; // stop rfid scan while submitting form
110 rfid_reset_field = 'findborrower';
111 $('input[name=findborrower]').val( t.content )
117 var error = data.tags.length + ' tags near reader: ';
118 $.each( data.tags, function(i,tag) { error += tag.content + ' '; } );
119 span.text( error ).css( 'color', 'red' );
123 span.text( 'no tags in range' ).css('color','gray');
124 if ( rfid_reset_field ) {
125 $('input[name='+rfid_reset_field+']').val( '' );
126 rfid_reset_field = false;
130 if (rfid_refresh > 1) {
131 window.setTimeout( function() {
132 $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);
135 console.debug('rfid_refresh disabled',rfid_refresh);
139 $(document).ready( function() {
140 $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);