1 |
// Set this to something unique to this client |
// Set this to something unique to this client |
2 |
|
|
3 |
var rfid_selected = {}; |
function update_selected( by ) { |
4 |
|
var e = $('#clear_selection'); |
5 |
|
e.attr( 'value', parseInt( e.attr('value') ) + by ); |
6 |
|
console.debug('selected', e.attr('value')); |
7 |
|
} |
8 |
|
|
9 |
function process(data) { |
function read_tag( id ) { |
10 |
var a = data.split('|'); |
console.debug('read_tag',id); |
|
console.info('process', a); |
|
|
$('#test').html( a[1] ); |
|
11 |
|
|
12 |
var id = a[0]; |
var item = $('#item'+id); |
13 |
|
|
14 |
if ( id > 0 ) { |
if ( item.length > 0 ) { |
15 |
var item = $('#item'+id); |
console.error('element', id, 'allready exists', item); |
|
if ( item.length > 0 ) { |
|
|
console.error('element', id, 'allready exists', item); |
|
|
} else { |
|
|
$('#koha').append( '<div class="item" id="item'+id+'">Loading item '+id+' from Koha</div>' ) |
|
|
console.debug('created element', id); |
|
|
|
|
|
$.get( '/koha/' + id, function(data) { |
|
|
item.html( data ); |
|
|
|
|
|
var e = $('#clear_selection'); |
|
|
e.attr( 'value', parseInt( e.attr('value') ) + 1 ); |
|
|
console.info('loaded item:', id, 'total selected:', e.attr('value')); |
|
|
|
|
|
rfid_selected[ id ] = data; |
|
|
$('#clear_selection').click( function() { |
|
|
rfid_selected[id] = undefined; |
|
|
item.remove(); |
|
|
}); |
|
|
}); |
|
|
} |
|
16 |
item.addClass('in_range'); |
item.addClass('in_range'); |
17 |
} else if ( id < 0 ) { |
} else { |
18 |
id = Math.abs( parseInt( id )); |
$('#koha').append( '<div class="item in_range loading" id="item'+id+'">Loading item '+id+' from Koha</div>' ) |
19 |
|
|
20 |
var item = $('#item'+id); |
var item = $('#item'+id); |
21 |
if ( item.length > 0 ) { |
|
22 |
console.info('item', item, 'out of range'); |
$.ajax({ |
23 |
item.removeClass('in_range'); |
url: '/koha/' + id, |
24 |
} else { |
success: function(html) { |
25 |
console.error('item', item, 'not found on page'); |
console.info('success',id); |
26 |
|
item.html( html ); |
27 |
|
|
28 |
|
item.removeClass('loading'); |
29 |
|
|
30 |
|
update_selected(+1); |
31 |
|
|
32 |
|
item.click( function() { |
33 |
|
// remove selected item |
34 |
|
this.fadeOut('slow', function() { |
35 |
|
console.debug('remove',id); |
36 |
|
update_selection( -1 ); |
37 |
|
this.remove(); |
38 |
|
}); |
39 |
|
}); |
40 |
|
}, |
41 |
|
error: function (XMLHttpRequest, textStatus, errorThrown) { |
42 |
|
item.replace('Error loading: ' + testStatus); |
43 |
|
item.removeClass('loading'); |
44 |
|
} |
45 |
|
}); |
46 |
|
} |
47 |
|
} |
48 |
|
|
49 |
|
function remove_tag( id ) { |
50 |
|
var item = $('#item'+id); |
51 |
|
if ( item.length > 0 ) { |
52 |
|
console.info('item', id, 'out of range'); |
53 |
|
item.removeClass('in_range'); |
54 |
|
} else { |
55 |
|
console.error('item', id, 'not found on page'); |
56 |
|
} |
57 |
|
} |
58 |
|
|
59 |
|
function process(data) { |
60 |
|
var a = data.split('|'); |
61 |
|
console.info('process', a); |
62 |
|
|
63 |
|
if ( a[0] == 'info' ) { |
64 |
|
$('#info').html( a[1]+'<br><tt>'+a[2]+'</tt>' ); |
65 |
|
} else if ( a[0] == 'info-none-in-range' ) { |
66 |
|
$('.in_range').removeClass('in_range'); |
67 |
|
$('#info').html( 'No items in reader range<br><tt>'+a[1]+'</tt>'); |
68 |
|
} else if ( a[0] == 'info-in-range' ) { |
69 |
|
$('#info').html( 'Items in reader range: '+a[1]+'<br><tt>'+a[2]+'</tt>'); |
70 |
|
$('.in_range').removeClass('in_range'); |
71 |
|
// FIXME: refresh in_range classes? |
72 |
|
var items = a[1].split(' '); |
73 |
|
for ( i in items ) { |
74 |
|
$('#item'+items[i]).addClass('in_range'); |
75 |
} |
} |
76 |
|
console.debug(items, 'in range'); |
77 |
|
} else if ( a[0] == 'read' ) { |
78 |
|
read_tag( a[1] ); |
79 |
|
} else if ( a[0] == 'removed' ) { |
80 |
|
remove_tag( a[1] ); |
81 |
|
} else { |
82 |
|
console.error( 'unknown', cmd, id ); |
83 |
} |
} |
84 |
}; |
}; |
85 |
|
|
109 |
$('#clear_selection').click( function() { |
$('#clear_selection').click( function() { |
110 |
$('#koha').html('No items selected'); |
$('#koha').html('No items selected'); |
111 |
$('#clear_selection').attr('value', '0'); |
$('#clear_selection').attr('value', '0'); |
|
rfid_selected = {}; |
|
112 |
console.debug('clear selection'); |
console.debug('clear selection'); |
113 |
}); |
}); |
114 |
|
|