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