--- trunk/public_html/koha.js 2009/03/28 03:45:31 70
+++ trunk/public_html/koha.js 2009/03/29 10:52:20 83
@@ -1,16 +1,87 @@
// Set this to something unique to this client
+function update_selected( by ) {
+ var e = $('#clear_selection');
+ var v = parseInt( e.attr('value') );
+ e.attr( 'value', v + by );
+ console.debug('selected', v);
+ return v;
+}
+
+function read_tag( id ) {
+ console.debug('read_tag',id);
+
+ var item = $('#item'+id);
+
+ if ( item.length > 0 ) {
+ console.error('element', id, 'allready exists', item);
+ item.addClass('in_range');
+ } else {
+ var tabindex = update_selected(+1) + 1;
+
+ $('#koha').append( '
Loading item '+id+' from Koha
' )
+
+ var item = $('#item'+id);
+
+ $.ajax({
+ url: '/koha/' + id,
+ success: function(html) {
+ console.info('success',id);
+ item.html( html );
+
+ item.removeClass('loading');
+
+ 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);
- $('#test').html( a[1] );
- if ( a[0] > 0 ) {
- $('#koha')
- .html( 'Loading item '+a[0]+' from Koha' )
- .load( '/koha/' + a[0] )
- ;
- } else if ( a[0] < 0 ) {
- $('#koha').html( '--' );
+
+ 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 );
}
};
@@ -36,5 +107,11 @@
// Start streaming!
Meteor.connect();
+ // clear selection
+ $('#clear_selection').click( function() {
+ $('#koha').html('No items selected');
+ $('#clear_selection').attr('value', '0');
+ console.debug('clear selection');
+ });
});