/[meteor]/trunk/public_html/koha.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/public_html/koha.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 81 - (show annotations)
Sun Mar 29 01:29:13 2009 UTC (15 years ago) by dpavlin
File MIME type: application/javascript
File size: 2873 byte(s)
- implement new 3m-810.pl protocol
- new page design and div ids
1 // Set this to something unique to this client
2
3 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 read_tag( id ) {
10 console.debug('read_tag',id);
11
12 var item = $('#item'+id);
13
14 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 var item = $('#item'+id);
21
22 $.ajax({
23 url: '/koha/' + id,
24 success: function(html) {
25 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
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 // 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
115 });

  ViewVC Help
Powered by ViewVC 1.1.26