/[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 76 by dpavlin, Sat Mar 28 17:53:26 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_selected = {};  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);
         $('#test').html( a[1] );  
   
         var id = a[0];  
62    
63          console.debug( id, rfid_selected[id] === undefined );          if ( a[0] == 'info' ) {
64                    $('#info').html( a[1]+'<br><tt>'+a[2]+'</tt>' );
65          if ( id > 0 && rfid_selected[ id ] === undefined ) {          } else if ( a[0] == 'info-none-in-range' ) {
66                  if ( $('#'+id).length > 0 ) {                  $('.in_range').removeClass('in_range');
67                          console.error('element', id, 'allready exists');                  $('#info').html( 'No items in reader range<br><tt>'+a[1]+'</tt>');
68                  } else {          } else if ( a[0] == 'info-in-range' ) {
69                          $('#koha').append( '<div class="item" id="'+id+'">Loading item '+id+' from Koha</div>' )                  $('#info').html( 'Items in reader range: '+a[1]+'<br><tt>'+a[2]+'</tt>');
70                          console.debug('created element', id);                  $('.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                  $.get( '/koha/' + id, function(data) {                  console.debug(items, 'in range');
77                          $('#'+id).html( data );          } else if ( a[0] == 'read' ) {
78                    read_tag( a[1] );
79                          if ( rfid_selected[id] === undefined ) {          } else if ( a[0] == 'removed' ) {
80                                  var e = $('#clear_selection');                  remove_tag( a[1] );
81                                  e.attr( 'value', parseInt( e.attr('value') ) + 1 );          } else {
82                                  console.info('loaded item:', id, ' times:', rfid_selected[ id ], 'total selected:', e.attr('value'));                  console.error( 'unknown', cmd, id );
                         }  
   
                         rfid_selected[ id ] = data;  
                 });  
         } else if ( id < 0 ) {  
                 console.info("No RFID chips in range");  
83          }          }
84  };  };
85    
# Line 60  $(document).ready( function() { Line 109  $(document).ready( function() {
109          $('#clear_selection').click( function() {          $('#clear_selection').click( function() {
110                  $('#koha').html('No items selected');                  $('#koha').html('No items selected');
111                  $('#clear_selection').attr('value', '0');                  $('#clear_selection').attr('value', '0');
                 rfid_selected = {};  
112                  console.debug('clear selection');                  console.debug('clear selection');
113          });          });
114    

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

  ViewVC Help
Powered by ViewVC 1.1.26