1 |
// Set this to something unique to this client |
// Set this to something unique to this client |
2 |
|
|
3 |
var rfid_visible = {}; |
var rfid_selected = {}; |
4 |
|
|
5 |
function process(data) { |
function process(data) { |
6 |
var a = data.split('|'); |
var a = data.split('|'); |
7 |
console.info('process', a); |
console.info('process', a); |
8 |
$('#test').html( a[1] ); |
$('#test').html( a[1] ); |
9 |
if ( a[0] > 0 && ! rfid_visible[ a[0] ] ) { |
|
10 |
$('#koha').append( '<div class="item" id="' + a[0] + '">Loading item '+a[0]+' from Koha</div>' ) |
var id = a[0]; |
11 |
$('#' + a[0]).load( '/koha/' + a[0] ); |
|
12 |
rfid_visible[ a[0] ]++; |
if ( id > 0 ) { |
13 |
} else if ( a[0] < 0 ) { |
var item = $('#item'+id); |
14 |
$('#koha').html( 'No RFID chips in range' ); |
if ( item.length > 0 ) { |
15 |
rfid_visible = {}; |
console.error('element', id, 'allready exists', item); |
16 |
|
} else { |
17 |
|
$('#koha').append( '<div class="item" id="item'+id+'">Loading item '+id+' from Koha</div>' ) |
18 |
|
console.debug('created element', id); |
19 |
|
|
20 |
|
$.get( '/koha/' + id, function(data) { |
21 |
|
item.html( data ); |
22 |
|
|
23 |
|
var e = $('#clear_selection'); |
24 |
|
e.attr( 'value', parseInt( e.attr('value') ) + 1 ); |
25 |
|
console.info('loaded item:', id, 'total selected:', e.attr('value')); |
26 |
|
|
27 |
|
rfid_selected[ id ] = data; |
28 |
|
$('#clear_selection').click( function() { |
29 |
|
rfid_selected[id] = undefined; |
30 |
|
item.remove(); |
31 |
|
}); |
32 |
|
}); |
33 |
|
} |
34 |
|
item.addClass('in_range'); |
35 |
|
} else if ( id < 0 ) { |
36 |
|
id = Math.abs( parseInt( id )); |
37 |
|
var item = $('#item'+id); |
38 |
|
if ( item.length > 0 ) { |
39 |
|
console.info('item', item, 'out of range'); |
40 |
|
item.removeClass('in_range'); |
41 |
|
} else { |
42 |
|
console.error('item', item, 'not found on page'); |
43 |
|
} |
44 |
} |
} |
45 |
}; |
}; |
46 |
|
|
66 |
// Start streaming! |
// Start streaming! |
67 |
Meteor.connect(); |
Meteor.connect(); |
68 |
|
|
69 |
|
// clear selection |
70 |
|
$('#clear_selection').click( function() { |
71 |
|
$('#koha').html('No items selected'); |
72 |
|
$('#clear_selection').attr('value', '0'); |
73 |
|
rfid_selected = {}; |
74 |
|
console.debug('clear selection'); |
75 |
|
}); |
76 |
|
|
77 |
}); |
}); |