/[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 72 by dpavlin, Sat Mar 28 14:21:21 2009 UTC revision 81 by dpavlin, Sun Mar 29 01:29:13 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_visible = {};  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) {  function process(data) {
60          var a = data.split('|');          var a = data.split('|');
61          console.info('process', a);          console.info('process', a);
62          $('#test').html( a[1] );  
63          if ( a[0] > 0 && ! rfid_visible[ a[0] ] ) {          if ( a[0] == 'info' ) {
64                  $('#koha').append( '<div class="item" id="' + a[0] + '">Loading item '+a[0]+' from Koha</div>' )                  $('#info').html( a[1]+'<br><tt>'+a[2]+'</tt>' );
65                  $('#' + a[0]).load( '/koha/' + a[0] );          } else if ( a[0] == 'info-none-in-range' ) {
66                  rfid_visible[ a[0] ]++;                  $('.in_range').removeClass('in_range');
67          } else if ( a[0] < 0 ) {                  $('#info').html( 'No items in reader range<br><tt>'+a[1]+'</tt>');
68                  $('#koha').html( 'No RFID chips in range' );          } else if ( a[0] == 'info-in-range' ) {
69                  rfid_visible = {};                  $('#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    
# Line 38  $(document).ready( function() { Line 105  $(document).ready( function() {
105          // Start streaming!          // Start streaming!
106          Meteor.connect();          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  });  });

Legend:
Removed from v.72  
changed lines
  Added in v.81

  ViewVC Help
Powered by ViewVC 1.1.26