1 |
// Set this to something unique to this client |
2 |
|
3 |
var rfid_selected = {}; |
4 |
|
5 |
function process(data) { |
6 |
var a = data.split('|'); |
7 |
console.info('process', a); |
8 |
$('#test').html( a[1] ); |
9 |
if ( a[0] > 0 && ! rfid_selected[ a[0] ] ) { |
10 |
$('#koha').append( '<div class="item" id="' + a[0] + '">Loading item '+a[0]+' from Koha</div>' ) |
11 |
$.get( '/koha/' + a[0], function(data) { |
12 |
$('#'+a[0]).html( data ); |
13 |
|
14 |
rfid_selected[ a[0] ]++; |
15 |
var e = $('#clear_selection'); |
16 |
e.attr( 'value', parseInt( e.attr('value') ) + 1 ); |
17 |
console.info('loaded item', a[0], data, 'selected', e.attr('value')); |
18 |
}); |
19 |
} else if ( a[0] < 0 ) { |
20 |
console.info("No RFID chips in range"); |
21 |
} |
22 |
}; |
23 |
|
24 |
$(document).ready( function() { |
25 |
|
26 |
var channel = 'test'; |
27 |
|
28 |
Meteor.hostid = '409897502705'; |
29 |
|
30 |
// Our Meteor server is on the data. subdomain |
31 |
Meteor.host = 'data.' + location.hostname; |
32 |
Meteor.port = 4670; |
33 |
|
34 |
// Call the test() function when data arrives |
35 |
Meteor.registerEventCallback("process", process ); |
36 |
|
37 |
console.info('Meteor connect', channel, Meteor.status ); |
38 |
|
39 |
// Join the demo channel and get last five events, then stream |
40 |
Meteor.joinChannel( channel, 5 ); |
41 |
Meteor.mode = 'stream'; |
42 |
|
43 |
// Start streaming! |
44 |
Meteor.connect(); |
45 |
|
46 |
// clear selection |
47 |
$('#clear_selection').click( function() { |
48 |
$('#koha').html('No items selected'); |
49 |
$('#clear_selection').attr('value', '0'); |
50 |
rfid_selected = {}; |
51 |
console.debug('clear selection'); |
52 |
}); |
53 |
|
54 |
}); |