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

Diff of /trunk/public_html/koha.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 78 by dpavlin, Sat Mar 28 20:53:45 2009 UTC revision 86 by dpavlin, Fri Apr 10 17:57:40 2009 UTC
# Line 1  Line 1 
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            var v = parseInt( e.attr('value') );
6            e.attr( 'value', v + by );
7            console.debug('selected', v);
8            return v;
9    }
10    
11  function process(data) {  function read_tag( id ) {
12          var a = data.split('|');          console.debug('read_tag',id);
         console.info('process', a);  
         $('#test').html( a[1] );  
13    
14          var id = a[0];          var item = $('#item'+id);
15    
16          if ( id > 0 ) {          if ( item.length > 0 ) {
17                  var item = $('#item'+id);                  console.warn('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();  
                                 });  
                         });  
                 }  
18                  item.addClass('in_range');                  item.addClass('in_range');
19          } else if ( id < 0 ) {          } else {
20                  id = Math.abs( parseInt( id ));                  var tabindex = update_selected(+1) + 1;
21    
22                    $('#koha').append( '<div class="item in_range loading" id="item'+id+'" tabindex='+tabindex+'>Loading item '+id+' from Koha</div>' )
23    
24                  var item = $('#item'+id);                  var item = $('#item'+id);
25                  if ( item.length > 0 ) {  
26                          console.info('item', item, 'out of range');                  $.ajax({
27                          item.removeClass('in_range');                          url: '/koha/' + id,
28                  } else {                          success: function(html) {
29                          console.error('item', item, 'not found on page');                                  console.info('success',id);
30                                    item.html( html );
31    
32                                    item.removeClass('loading');
33    
34                                    item.click( function() {
35                                            // remove selected item
36                                            item.fadeOut('slow', function() {
37                                                    console.debug('remove',id);
38                                                    item.remove();
39                                                    var selected = update_selected( -1 );
40                                                    console.info('selected', selected);
41                                            });
42                                    });
43                            },
44                            error: function (XMLHttpRequest, textStatus, errorThrown) {
45                                    console.error( textStatus );
46                                    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                  }                  }
80                    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                    console.error( 'unknown', a );
87          }          }
88  };  };
89    
# Line 62  $(document).ready( function() { Line 105  $(document).ready( function() {
105          // Join the demo channel and get last five events, then stream          // Join the demo channel and get last five events, then stream
106          Meteor.joinChannel( channel, 5 );          Meteor.joinChannel( channel, 5 );
107          Meteor.mode = 'stream';          Meteor.mode = 'stream';
108    //      Meteor.mode = 'iframe';
109    //      Meteor.mode = 'longpoll';
110    //      Meteor.mode = 'xhrinteractive';
111    //      Meteor.mode = 'xhrinteractive';
112            Meteor.debugmode = 1;
113    
114          // Start streaming!          // Start streaming!
115          Meteor.connect();          Meteor.connect();
# Line 70  $(document).ready( function() { Line 118  $(document).ready( function() {
118          $('#clear_selection').click( function() {          $('#clear_selection').click( function() {
119                  $('#koha').html('No items selected');                  $('#koha').html('No items selected');
120                  $('#clear_selection').attr('value', '0');                  $('#clear_selection').attr('value', '0');
                 rfid_selected = {};  
121                  console.debug('clear selection');                  console.debug('clear selection');
122          });          });
123    

Legend:
Removed from v.78  
changed lines
  Added in v.86

  ViewVC Help
Powered by ViewVC 1.1.26