1 |
|
2 |
// XXX dpavlin: RFID support for Koha |
3 |
|
4 |
function barcode_on_screen(barcode) { |
5 |
var found = 0; |
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 ) found++; |
10 |
}) |
11 |
return found; |
12 |
} |
13 |
|
14 |
function rfid_secure(barcode,sid,val) { |
15 |
console.debug('rfid_secure', barcode, sid, val); |
16 |
if ( barcode_on_screen(barcode) ) |
17 |
$.getJSON( 'http://localhost:9000/secure.js?' + sid + '=' + val + ';callback=?' ) |
18 |
} |
19 |
|
20 |
var rfid_reset_field = false; |
21 |
|
22 |
function rfid_scan(data,textStatus) { |
23 |
// console.debug( 'rfid_scan', data, textStatus ); |
24 |
|
25 |
var span = $('span#rfid'); |
26 |
if ( span.size() == 0 ) { |
27 |
$('ul#i18nMenu').append('<li><span id=rfid>RFID reader found<span>'); |
28 |
span = $('span#rfid'); |
29 |
} |
30 |
|
31 |
if ( data.tags ) { |
32 |
if ( data.tags.length === 1 ) { |
33 |
var t = data.tags[0]; |
34 |
// if ( span.text() != t.content ) { |
35 |
if ( 1 ) { // force update of security |
36 |
|
37 |
var url = document.location.toString(); |
38 |
var circulation = url.substr(-14,14) == 'circulation.pl'; |
39 |
var returns = url.substr(-10,10) == 'returns.pl'; |
40 |
|
41 |
if ( t.content.substr(0,3) == '130' ) { |
42 |
|
43 |
if ( circulation ) |
44 |
rfid_secure( t.content, t.sid, 'D7' ); |
45 |
if ( returns ) |
46 |
rfid_secure( t.content, t.sid, 'DA' ); |
47 |
|
48 |
var color = 'blue'; |
49 |
if ( t.security.toUpperCase() == 'DA' ) color = 'red'; |
50 |
if ( t.security.toUpperCase() == 'D7' ) color = 'green'; |
51 |
span.text( t.content ).css('color', color); |
52 |
|
53 |
if ( ! barcode_on_screen( t.content ) ) { |
54 |
rfid_reset_field = 'barcode'; |
55 |
var i = $('input[name=barcode]:last'); |
56 |
if ( i.val() != t.content ) |
57 |
i.val( t.content ) |
58 |
.closest('form').submit(); |
59 |
} |
60 |
|
61 |
} else { |
62 |
span.text( t.content ).css('color', 'blue' ); |
63 |
|
64 |
if ( url.substr(-14,14) != 'circulation.pl' || $('form[name=mainform]').size() == 0 ) { |
65 |
rfid_reset_field = 'findborrower'; |
66 |
$('input[name=findborrower]').val( t.content ) |
67 |
.parent().submit(); |
68 |
} |
69 |
} |
70 |
} |
71 |
} else { |
72 |
var error = data.tags.length + ' tags near reader: '; |
73 |
$.each( data.tags, function(i,tag) { error += tag.content + ' '; } ); |
74 |
span.text( error ).css( 'color', 'red' ); |
75 |
} |
76 |
|
77 |
} else { |
78 |
span.text( 'no tags in range' ).css('color','gray'); |
79 |
if ( rfid_reset_field ) { |
80 |
$('input[name='+rfid_reset_field+']').val( '' ); |
81 |
rfid_reset_field = false; |
82 |
} |
83 |
} |
84 |
|
85 |
window.setTimeout( function() { |
86 |
$.getJSON("http://localhost:9000/scan?callback=?", rfid_scan); |
87 |
}, 1000 ); // 1000ms |
88 |
} |
89 |
|
90 |
$(document).ready( function() { |
91 |
$.getJSON("http://localhost:9000/scan?callback=?", rfid_scan); |
92 |
}); |