1 |
dpavlin |
70 |
// Set this to something unique to this client |
2 |
|
|
|
3 |
dpavlin |
81 |
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 |
dpavlin |
72 |
|
9 |
dpavlin |
81 |
function read_tag( id ) { |
10 |
|
|
console.debug('read_tag',id); |
11 |
dpavlin |
73 |
|
12 |
dpavlin |
81 |
var item = $('#item'+id); |
13 |
dpavlin |
76 |
|
14 |
dpavlin |
81 |
if ( item.length > 0 ) { |
15 |
|
|
console.error('element', id, 'allready exists', item); |
16 |
|
|
item.addClass('in_range'); |
17 |
|
|
} else { |
18 |
|
|
$('#koha').append( '<div class="item in_range loading" id="item'+id+'">Loading item '+id+' from Koha</div>' ) |
19 |
|
|
|
20 |
dpavlin |
78 |
var item = $('#item'+id); |
21 |
dpavlin |
76 |
|
22 |
dpavlin |
81 |
$.ajax({ |
23 |
|
|
url: '/koha/' + id, |
24 |
|
|
success: function(html) { |
25 |
|
|
console.info('success',id); |
26 |
|
|
item.html( html ); |
27 |
dpavlin |
78 |
|
28 |
dpavlin |
81 |
item.removeClass('loading'); |
29 |
dpavlin |
76 |
|
30 |
dpavlin |
81 |
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 |
dpavlin |
78 |
}); |
40 |
dpavlin |
81 |
}, |
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 |
dpavlin |
78 |
} |
76 |
dpavlin |
81 |
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 |
dpavlin |
70 |
} |
84 |
|
|
}; |
85 |
|
|
|
86 |
|
|
$(document).ready( function() { |
87 |
|
|
|
88 |
|
|
var channel = 'test'; |
89 |
|
|
|
90 |
|
|
Meteor.hostid = '409897502705'; |
91 |
|
|
|
92 |
|
|
// Our Meteor server is on the data. subdomain |
93 |
|
|
Meteor.host = 'data.' + location.hostname; |
94 |
|
|
Meteor.port = 4670; |
95 |
|
|
|
96 |
|
|
// Call the test() function when data arrives |
97 |
|
|
Meteor.registerEventCallback("process", process ); |
98 |
|
|
|
99 |
|
|
console.info('Meteor connect', channel, Meteor.status ); |
100 |
|
|
|
101 |
|
|
// Join the demo channel and get last five events, then stream |
102 |
|
|
Meteor.joinChannel( channel, 5 ); |
103 |
|
|
Meteor.mode = 'stream'; |
104 |
|
|
|
105 |
|
|
// Start streaming! |
106 |
|
|
Meteor.connect(); |
107 |
|
|
|
108 |
dpavlin |
73 |
// clear selection |
109 |
|
|
$('#clear_selection').click( function() { |
110 |
|
|
$('#koha').html('No items selected'); |
111 |
|
|
$('#clear_selection').attr('value', '0'); |
112 |
|
|
console.debug('clear selection'); |
113 |
|
|
}); |
114 |
dpavlin |
70 |
|
115 |
|
|
}); |