/[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

Annotation of /trunk/public_html/koha.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86 - (hide annotations)
Fri Apr 10 17:57:40 2009 UTC (15 years ago) by dpavlin
File MIME type: application/javascript
File size: 3152 byte(s)
turn debug mode on and test other modes under Firefox 3.5
and none of them work really well...
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 dpavlin 83 var v = parseInt( e.attr('value') );
6     e.attr( 'value', v + by );
7     console.debug('selected', v);
8     return v;
9 dpavlin 81 }
10 dpavlin 72
11 dpavlin 81 function read_tag( id ) {
12     console.debug('read_tag',id);
13 dpavlin 73
14 dpavlin 81 var item = $('#item'+id);
15 dpavlin 76
16 dpavlin 81 if ( item.length > 0 ) {
17 dpavlin 85 console.warn('element', id, 'allready exists', item);
18 dpavlin 81 item.addClass('in_range');
19     } else {
20 dpavlin 83 var tabindex = update_selected(+1) + 1;
21 dpavlin 81
22 dpavlin 83 $('#koha').append( '<div class="item in_range loading" id="item'+id+'" tabindex='+tabindex+'>Loading item '+id+' from Koha</div>' )
23    
24 dpavlin 78 var item = $('#item'+id);
25 dpavlin 76
26 dpavlin 81 $.ajax({
27     url: '/koha/' + id,
28     success: function(html) {
29     console.info('success',id);
30     item.html( html );
31 dpavlin 78
32 dpavlin 81 item.removeClass('loading');
33 dpavlin 76
34 dpavlin 81 item.click( function() {
35     // remove selected item
36 dpavlin 84 item.fadeOut('slow', function() {
37 dpavlin 81 console.debug('remove',id);
38 dpavlin 84 item.remove();
39     var selected = update_selected( -1 );
40     console.info('selected', selected);
41 dpavlin 81 });
42 dpavlin 78 });
43 dpavlin 81 },
44     error: function (XMLHttpRequest, textStatus, errorThrown) {
45 dpavlin 85 console.error( textStatus );
46 dpavlin 81 item.replace('Error loading: ' + testStatus);
47     item.removeClass('loading');
48     }
49     });
50     }
51     }
52    
53     function remove_tag( id ) {
54     var item = $('#item'+id);
55     if ( item.length > 0 ) {
56     console.info('item', id, 'out of range');
57     item.removeClass('in_range');
58     } else {
59     console.error('item', id, 'not found on page');
60     }
61     }
62    
63     function process(data) {
64     var a = data.split('|');
65     console.info('process', a);
66    
67     if ( a[0] == 'info' ) {
68     $('#info').html( a[1]+'<br><tt>'+a[2]+'</tt>' );
69     } else if ( a[0] == 'info-none-in-range' ) {
70     $('.in_range').removeClass('in_range');
71     $('#info').html( 'No items in reader range<br><tt>'+a[1]+'</tt>');
72     } else if ( a[0] == 'info-in-range' ) {
73     $('#info').html( 'Items in reader range: '+a[1]+'<br><tt>'+a[2]+'</tt>');
74     $('.in_range').removeClass('in_range');
75     // FIXME: refresh in_range classes?
76     var items = a[1].split(' ');
77     for ( i in items ) {
78     $('#item'+items[i]).addClass('in_range');
79 dpavlin 78 }
80 dpavlin 81 console.debug(items, 'in range');
81     } else if ( a[0] == 'read' ) {
82     read_tag( a[1] );
83     } else if ( a[0] == 'removed' ) {
84     remove_tag( a[1] );
85     } else {
86 dpavlin 84 console.error( 'unknown', a );
87 dpavlin 70 }
88     };
89    
90     $(document).ready( function() {
91    
92     var channel = 'test';
93    
94     Meteor.hostid = '409897502705';
95    
96     // Our Meteor server is on the data. subdomain
97     Meteor.host = 'data.' + location.hostname;
98     Meteor.port = 4670;
99    
100     // Call the test() function when data arrives
101     Meteor.registerEventCallback("process", process );
102    
103     console.info('Meteor connect', channel, Meteor.status );
104    
105     // Join the demo channel and get last five events, then stream
106     Meteor.joinChannel( channel, 5 );
107     Meteor.mode = 'stream';
108 dpavlin 86 // Meteor.mode = 'iframe';
109     // Meteor.mode = 'longpoll';
110     // Meteor.mode = 'xhrinteractive';
111     // Meteor.mode = 'xhrinteractive';
112     Meteor.debugmode = 1;
113 dpavlin 70
114     // Start streaming!
115     Meteor.connect();
116    
117 dpavlin 73 // clear selection
118     $('#clear_selection').click( function() {
119     $('#koha').html('No items selected');
120     $('#clear_selection').attr('value', '0');
121     console.debug('clear selection');
122     });
123 dpavlin 70
124     });

  ViewVC Help
Powered by ViewVC 1.1.26