--- trunk/public_html/koha.js 2009/03/28 15:49:36 73 +++ trunk/public_html/koha.js 2009/03/28 20:53:45 78 @@ -6,18 +6,41 @@ var a = data.split('|'); console.info('process', a); $('#test').html( a[1] ); - if ( a[0] > 0 && ! rfid_selected[ a[0] ] ) { - $('#koha').append( '
Loading item '+a[0]+' from Koha
' ) - $.get( '/koha/' + a[0], function(data) { - $('#'+a[0]).html( data ); - - rfid_selected[ a[0] ]++; - var e = $('#clear_selection'); - e.attr( 'value', parseInt( e.attr('value') ) + 1 ); - console.info('loaded item', a[0], data, 'selected', e.attr('value')); - }); - } else if ( a[0] < 0 ) { - console.info("No RFID chips in range"); + + var id = a[0]; + + 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(); + }); + }); + } + item.addClass('in_range'); + } else if ( id < 0 ) { + id = Math.abs( parseInt( id )); + 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'); + } } };