--- trunk/public_html/koha.js 2009/03/28 20:53:45 78
+++ trunk/public_html/koha.js 2009/03/29 01:29:13 81
@@ -1,46 +1,85 @@
// Set this to something unique to this client
-var rfid_selected = {};
+function update_selected( by ) {
+ var e = $('#clear_selection');
+ e.attr( 'value', parseInt( e.attr('value') ) + by );
+ console.debug('selected', e.attr('value'));
+}
-function process(data) {
- var a = data.split('|');
- console.info('process', a);
- $('#test').html( a[1] );
+function read_tag( id ) {
+ console.debug('read_tag',id);
- var id = a[0];
+ var item = $('#item'+id);
- if ( id > 0 ) {
- var item = $('#item'+id);
- if ( item.length > 0 ) {
- console.error('element', id, 'allready exists', item);
- } else {
- $('#koha').append( '
Loading item '+id+' from Koha
' )
- 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();
- });
- });
- }
+ if ( item.length > 0 ) {
+ console.error('element', id, 'allready exists', item);
item.addClass('in_range');
- } else if ( id < 0 ) {
- id = Math.abs( parseInt( id ));
+ } else {
+ $('#koha').append( 'Loading item '+id+' from Koha
' )
+
var item = $('#item'+id);
- if ( item.length > 0 ) {
- console.info('item', item, 'out of range');
- item.removeClass('in_range');
- } else {
- console.error('item', item, 'not found on page');
+
+ $.ajax({
+ url: '/koha/' + id,
+ success: function(html) {
+ console.info('success',id);
+ item.html( html );
+
+ item.removeClass('loading');
+
+ update_selected(+1);
+
+ item.click( function() {
+ // remove selected item
+ this.fadeOut('slow', function() {
+ console.debug('remove',id);
+ update_selection( -1 );
+ this.remove();
+ });
+ });
+ },
+ error: function (XMLHttpRequest, textStatus, errorThrown) {
+ item.replace('Error loading: ' + testStatus);
+ item.removeClass('loading');
+ }
+ });
+ }
+}
+
+function remove_tag( id ) {
+ var item = $('#item'+id);
+ if ( item.length > 0 ) {
+ console.info('item', id, 'out of range');
+ item.removeClass('in_range');
+ } else {
+ console.error('item', id, 'not found on page');
+ }
+}
+
+function process(data) {
+ var a = data.split('|');
+ console.info('process', a);
+
+ if ( a[0] == 'info' ) {
+ $('#info').html( a[1]+'
'+a[2]+'' );
+ } else if ( a[0] == 'info-none-in-range' ) {
+ $('.in_range').removeClass('in_range');
+ $('#info').html( 'No items in reader range
'+a[1]+'');
+ } else if ( a[0] == 'info-in-range' ) {
+ $('#info').html( 'Items in reader range: '+a[1]+'
'+a[2]+'');
+ $('.in_range').removeClass('in_range');
+ // FIXME: refresh in_range classes?
+ var items = a[1].split(' ');
+ for ( i in items ) {
+ $('#item'+items[i]).addClass('in_range');
}
+ console.debug(items, 'in range');
+ } else if ( a[0] == 'read' ) {
+ read_tag( a[1] );
+ } else if ( a[0] == 'removed' ) {
+ remove_tag( a[1] );
+ } else {
+ console.error( 'unknown', cmd, id );
}
};
@@ -70,7 +109,6 @@
$('#clear_selection').click( function() {
$('#koha').html('No items selected');
$('#clear_selection').attr('value', '0');
- rfid_selected = {};
console.debug('clear selection');
});