1 |
|
2 |
// XXX dpavlin: RFID support for Koha |
3 |
|
4 |
function rfid_secure(barcode,sid,val) { |
5 |
console.debug('rfid_secure', barcode, sid, val); |
6 |
$('table tr td a:contains(130)').each( function(i,o) { |
7 |
var possible = $(o).text(); |
8 |
console.debug(i,o,possible, barcode); |
9 |
if ( possible == barcode ) { |
10 |
$.getJSON( 'http://localhost:9000/secure.js?' + sid + '=' + val + ';callback=?' ) |
11 |
} |
12 |
}); |
13 |
} |
14 |
|
15 |
var rfid_reset_field = false; |
16 |
|
17 |
function rfid_scan(data,textStatus) { |
18 |
// console.debug( 'rfid_scan', data, textStatus ); |
19 |
|
20 |
var span = $('span#rfid'); |
21 |
if ( span.size() == 0 ) { |
22 |
$('ul#i18nMenu').append('<li><span id=rfid>RFID reader found<span>'); |
23 |
span = $('span#rfid'); |
24 |
} |
25 |
|
26 |
if ( data.tags ) { |
27 |
if ( data.tags.length === 1 ) { |
28 |
var t = data.tags[0]; |
29 |
if ( span.text() != t.content ) { |
30 |
if ( t.content.substr(0,3) == '130' ) { |
31 |
var color = 'blue'; |
32 |
if ( t.security.toUpperCase() == 'DA' ) color = 'red'; |
33 |
if ( t.security.toUpperCase() == 'D7' ) color = 'green'; |
34 |
span.text( t.content ).css('color', color); |
35 |
$('input[name=barcode]').val( t.content ); |
36 |
rfid_reset_field = 'barcode'; |
37 |
|
38 |
var url = document.location.toString(); |
39 |
if ( url.substr(-14,14) == 'circulation.pl' ) |
40 |
rfid_secure( t.content, t.sid, 'D7' ); |
41 |
if ( url.substr(-10,10) == 'returns.pl' ) |
42 |
rfid_secure( t.content, t.sid, 'DA' ); |
43 |
|
44 |
} else { |
45 |
span.text( t.content ).css('color', 'blue' ); |
46 |
$('input[name=findborrower]').val( t.content ); |
47 |
rfid_reset_field = 'findborrower'; |
48 |
} |
49 |
} |
50 |
} else { |
51 |
var error = data.tags.length + ' tags near reader: '; |
52 |
$.each( data.tags, function(i,tag) { error += tag.content + ' '; } ); |
53 |
span.text( error ).css( 'color', 'red' ); |
54 |
} |
55 |
|
56 |
} else { |
57 |
span.text( 'no tags in range' ).css('color','gray'); |
58 |
if ( rfid_reset_field ) { |
59 |
$('input[name='+rfid_reset_field+']').val( '' ); |
60 |
rfid_reset_field = false; |
61 |
} |
62 |
} |
63 |
|
64 |
window.setTimeout( function() { |
65 |
$.getJSON("http://localhost:9000/scan?callback=?", rfid_scan); |
66 |
}, 1000 ); // 1000ms |
67 |
} |
68 |
|
69 |
$(document).ready( function() { |
70 |
$.getJSON("http://localhost:9000/scan?callback=?", rfid_scan); |
71 |
}); |