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
14 function barcode_on_screen(barcode) {
16 $('table tr td a:contains(130)').each( function(i,o) {
17 var possible = $(o).text();
18 console.debug(i,o,possible, barcode);
19 if ( possible == barcode ) found++;
24 function rfid_secure(barcode,sid,val) {
25 console.debug('rfid_secure', barcode, sid, val);
26 if ( barcode_on_screen(barcode) )
27 $.getJSON( 'http://localhost:9000/secure.js?' + sid + '=' + val + ';callback=?' )
30 var rfid_reset_field = false;
32 function rfid_scan(data,textStatus) {
33 // console.debug( 'rfid_scan', data, textStatus );
35 var span = $('span#rfid');
36 if ( span.size() == 0 ) {
37 $('ul#i18nMenu').append('<li><span id=rfid>RFID reader found<span>');
38 span = $('span#rfid');
42 if ( data.tags.length === 1 ) {
44 // if ( span.text() != t.content ) {
45 if ( 1 ) { // force update of security
47 var url = document.location.toString();
48 var circulation = url.substr(-14,14) == 'circulation.pl';
49 var returns = url.substr(-10,10) == 'returns.pl';
51 if ( t.content.substr(0,3) == '130' ) {
54 rfid_secure( t.content, t.sid, 'D7' );
56 rfid_secure( t.content, t.sid, 'DA' );
59 if ( t.security.toUpperCase() == 'DA' ) color = 'red';
60 if ( t.security.toUpperCase() == 'D7' ) color = 'green';
61 span.text( t.content ).css('color', color);
63 if ( ! barcode_on_screen( t.content ) ) {
64 rfid_reset_field = 'barcode';
65 var i = $('input[name=barcode]:last');
66 if ( i.val() != t.content )
68 .closest('form').submit();
72 span.text( t.content ).css('color', 'blue' );
74 if ( url.substr(-14,14) != 'circulation.pl' || $('form[name=mainform]').size() == 0 ) {
75 rfid_reset_field = 'findborrower';
76 $('input[name=findborrower]').val( t.content )
82 var error = data.tags.length + ' tags near reader: ';
83 $.each( data.tags, function(i,tag) { error += tag.content + ' '; } );
84 span.text( error ).css( 'color', 'red' );
88 span.text( 'no tags in range' ).css('color','gray');
89 if ( rfid_reset_field ) {
90 $('input[name='+rfid_reset_field+']').val( '' );
91 rfid_reset_field = false;
95 window.setTimeout( function() {
96 $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);
100 $(document).ready( function() {
101 $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);