refresh in place function for tree rows, adjustment to code that was expecting nodes...
authorpines <pines@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 4 Jun 2007 17:32:16 +0000 (17:32 +0000)
committerpines <pines@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 4 Jun 2007 17:32:16 +0000 (17:32 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@7402 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/util/list.js
Open-ILS/xul/staff_client/server/cat/copy_browser.js
Open-ILS/xul/staff_client/server/circ/copy_status.js
Open-ILS/xul/staff_client/server/patron/bills.js

index acc40f9..4271a41 100644 (file)
@@ -297,13 +297,13 @@ util.list.prototype = {
                var rnode;
                var obj = this;
                switch (this.node.nodeName) {
-                       case 'tree' : rnode = this._append_to_tree(params); break;
-                       case 'listbox' : rnode = this._append_to_listbox(params); break;
+                       case 'tree' : rparams = this._append_to_tree(params); break;
+                       case 'listbox' : rparams = this._append_to_listbox(params); break;
                        default: throw('NYI: Need .append() for ' + this.node.nodeName); break;
                }
-               if (rnode && params.attributes) {
+               if (rparams && params.attributes) {
                        for (var i in params.attributes) {
-                               rnode.setAttribute(i,params.attributes[i]);
+                               rparams.my_node.setAttribute(i,params.attributes[i]);
                        }
                }
                this.row_count.total++;
@@ -312,8 +312,24 @@ util.list.prototype = {
                                setTimeout( function() { obj.on_all_fleshed(); }, 0 );
                        }
                }
-               return rnode;
+               return rparams;
        },
+       
+       'refresh_row' : function (params) {
+               var rnode;
+               var obj = this;
+               switch (this.node.nodeName) {
+                       case 'tree' : rparams = this._refresh_row_in_tree(params); break;
+                       default: throw('NYI: Need .refresh_row() for ' + this.node.nodeName); break;
+               }
+               if (rparams && params.attributes) {
+                       for (var i in params.attributes) {
+                               rparams.my_node.setAttribute(i,params.attributes[i]);
+                       }
+               }
+               return rparams;
+       },
+
 
        '_append_to_tree' : function (params) {
 
@@ -474,7 +490,157 @@ util.list.prototype = {
 
                                if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
                                        // Remove oldest row
-                                       //if (typeof params.to_bottom != 'undefined') {
+                                       //if (typeof params.to_bottom != 'undefined') 
+                                       if (typeof params.to_top == 'undefined') {
+                                               treechildren_node.removeChild( treechildren_node.firstChild );
+                                       } else {
+                                               treechildren_node.removeChild( treechildren_node.lastChild );
+                                       }
+                               }
+                       } catch(E) {
+                       }
+
+               setTimeout( function() { obj.auto_retrieve(); }, 0 );
+
+               params.my_node = treeitem;
+               return params;
+       },
+
+       '_refresh_row_in_tree' : function (params) {
+
+               var obj = this;
+
+               if (typeof params.row == 'undefined') throw('util.list.refresh_row: Object must contain a row');
+               if (typeof params.my_node == 'undefined') throw('util.list.refresh_row: Object must contain a my_node');
+               if (params.my_node.nodeName != 'treeitem') throw('util.list.refresh_rwo: my_node must be a treeitem');
+
+               var s = ('util.list.refresh_row: params = ' + (params) + '\n');
+
+               var treeitem = params.my_node;
+               treeitem.setAttribute('retrieve_id',params.retrieve_id);
+               if (typeof params.to_bottom != 'undefined') {
+                       if (typeof params.no_auto_select == 'undefined') {
+                               if (!obj.auto_select_pending) {
+                                       obj.auto_select_pending = true;
+                                       setTimeout(function() {
+                                               dump('auto-selecting\n');
+                                               var idx = Number(obj.node.view.rowCount)-1;
+                                               try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_ALERT','tree auto select: ' + E + '\n'); }
+                                               try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_ALERT','tree auto select, on_select: ' + E + '\n'); }
+                                               obj.auto_select_pending = false;
+                                               try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_ALERT','tree auto select, flesh: ' + E + '\n'); }
+                                       }, 1000);
+                               }
+                       }
+               }
+               var delete_me = [];
+               for (var i in treeitem.childNodes) if (treeitem.childNodes[i].nodeName == 'treerow') delete_me.push(treeitem.childNodes[i]);
+               for (var i = 0; i < delete_me.length; i++) treeitem.removeChild(delete_me[i]);
+               var treerow = document.createElement('treerow');
+               treeitem.appendChild( treerow );
+               treerow.setAttribute('retrieve_id',params.retrieve_id);
+
+               s += ('tree = ' + this.node + '\n');
+               s += ('treeitem = ' + treeitem + '  treerow = ' + treerow + '\n');
+
+               if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
+
+                       obj.put_retrieving_label(treerow);
+                       treerow.addEventListener(
+                               'flesh',
+                               function() {
+
+                                       if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
+
+                                       treerow.setAttribute('retrieved','true');
+
+                                       //dump('fleshing = ' + params.retrieve_id + '\n');
+
+                                       function inc_fleshed() {
+                                               if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
+                                               treerow.setAttribute('fleshed','true');
+                                               obj.row_count.fleshed++;
+                                               if (obj.row_count.fleshed == obj.row_count.total) {
+                                                       if (typeof obj.on_all_fleshed == 'function') {
+                                                               setTimeout( function() { obj.on_all_fleshed(); }, 0 );
+                                                       }
+                                               }
+                                       }
+
+                                       params.row_node = treeitem;
+                                       params.on_retrieve = function(p) {
+                                               try {
+                                                       p.row = params.row;
+                                                       obj._map_row_to_treecell(p,treerow);
+                                                       inc_fleshed();
+                                                       var idx = obj.node.contentView.getIndexOfItem( params.row_node );
+                                                       dump('idx = ' + idx + '\n');
+                                                       // if current row is selected, send another select event to re-sync data that the client code fetches on selects
+                                                       if ( obj.node.view.selection.isSelected( idx ) ) {
+                                                               dump('dispatching select event for on_retrieve for idx = ' + idx + '\n');
+                                                               util.widgets.dispatch('select',params.row_node);
+                                                       }
+                                               } catch(E) {
+                                                       alert('fixme2: ' + E);
+                                               }
+                                       }
+
+                                       if (typeof params.retrieve_row == 'function') {
+
+                                               params.retrieve_row( params );
+
+                                       } else if (typeof obj.retrieve_row == 'function') {
+
+                                                       obj.retrieve_row( params );
+
+                                       } else {
+                                       
+                                                       inc_fleshed();
+                                       }
+                               },
+                               false
+                       );
+                       /*
+                       setTimeout(
+                               function() {
+                                       util.widgets.dispatch('flesh',treerow);
+                               }, 0
+                       );
+                       */
+               } else {
+                       obj.put_retrieving_label(treerow);
+                       treerow.addEventListener(
+                               'flesh',
+                               function() {
+                                       //dump('fleshing anon\n');
+                                       if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
+                                       obj._map_row_to_treecell(params,treerow);
+                                       treerow.setAttribute('retrieved','true');
+                                       treerow.setAttribute('fleshed','true');
+                                       obj.row_count.fleshed++;
+                                       if (obj.row_count.fleshed == obj.row_count.total) {
+                                               if (typeof obj.on_all_fleshed == 'function') {
+                                                       setTimeout( function() { obj.on_all_fleshed(); }, 0 );
+                                               }
+                                       }
+                               },
+                               false
+                       );
+                       /*
+                       setTimeout(
+                               function() {
+                                       util.widgets.dispatch('flesh',treerow);
+                               }, 0
+                       );
+                       */
+               }
+               this.error.sdump('D_LIST',s);
+
+                       try {
+
+                               if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
+                                       // Remove oldest row
+                                       //if (typeof params.to_bottom != 'undefined') 
                                        if (typeof params.to_top == 'undefined') {
                                                treechildren_node.removeChild( treechildren_node.firstChild );
                                        } else {
@@ -486,7 +652,7 @@ util.list.prototype = {
 
                setTimeout( function() { obj.auto_retrieve(); }, 0 );
 
-               return treeitem;
+               return params;
        },
 
        'put_retrieving_label' : function(treerow) {
@@ -667,7 +833,8 @@ util.list.prototype = {
                }
 
                this.error.sdump('D_LIST',s);
-               return listitem;
+               params.my_node = listitem;
+               return params;
 
        },
 
index d82e1e1..cefd92e 100644 (file)
@@ -1249,7 +1249,8 @@ cat.copy_browser.prototype = {
                        if (parent_org) {
                                data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
                        }
-                       var node = obj.list.append(data);
+                       var nparams = obj.list.append(data);
+                       var node = nparams.my_node;
                        if (params) {
                                for (var i in params) {
                                        node.setAttribute(i,params[i]);
@@ -1316,7 +1317,8 @@ cat.copy_browser.prototype = {
                                'to_bottom' : true,
                                'no_auto_select' : true,
                        };
-                       var node = obj.list.append(data);
+                       var nparams = obj.list.append(data);
+                       var node = nparams.my_node;
                        obj.map_tree[ 'acn_' + acn_tree.id() ] =  node;
                        if (params) {
                                for (var i in params) {
@@ -1367,7 +1369,8 @@ cat.copy_browser.prototype = {
                                'to_bottom' : true,
                                'no_auto_select' : true,
                        };
-                       var node = obj.list.append(data);
+                       var nparams = obj.list.append(data);
+                       var node = nparams.my_node;
                        obj.map_tree[ 'acp_' + acp_item.id() ] =  node;
                        if (params) {
                                for (var i in params) {
index 305d9a2..e2d0cca 100644 (file)
@@ -13,6 +13,7 @@ circ.copy_status = function (params) {
 
 circ.copy_status.prototype = {
        'selection_list' : [],
+       'list_barcode_map' : {},
 
        'init' : function( params ) {
 
@@ -122,7 +123,7 @@ circ.copy_status.prototype = {
                                                                for (var i = 0; i < obj.selection_list.length; i++) {
                                                                        var barcode = obj.selection_list[i].barcode;
                                                                        var checkin = circ.util.checkin_via_barcode( ses(), { 'barcode' : barcode } );
-                                                                       funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
+                                                                       funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) );
                                                                }
                                                                for (var i = 0; i < funcs.length; i++) { funcs[i](); }
                                                                alert('Action complete.');
@@ -141,7 +142,7 @@ circ.copy_status.prototype = {
                                                                        try { 
                                                                                var barcode = obj.selection_list[i].barcode;
                                                                                var new_bc = cat.util.replace_barcode( barcode );
-                                                                               funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(new_bc) );
+                                                                               funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(new_bc) );
                                                                        } catch(E) {
                                                                                obj.error.standard_unexpected_error_alert('Barcode ' + barcode + ' was not likely replaced.',E);
                                                                        }
@@ -161,7 +162,7 @@ circ.copy_status.prototype = {
                                                                obj.spawn_copy_editor();
                                                                for (var i = 0; i < obj.selection_list.length; i++) {
                                                                                var barcode = obj.selection_list[i].barcode;
-                                                                               funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
+                                                                               funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) );
                                                                }
                                                                for (var i = 0; i < funcs.length; i++) { funcs[i](); }
                                                        } catch(E) {
@@ -191,7 +192,7 @@ circ.copy_status.prototype = {
                                                        circ.util.abort_transits(obj.selection_list);
                                                        for (var i = 0; i < obj.selection_list.length; i++) {
                                                                var barcode = obj.selection_list[i].barcode;
-                                                               funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
+                                                               funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) );
                                                        }
                                                        for (var i = 0; i < funcs.length; i++) { funcs[i](); }
                                                        alert('Action complete.');
@@ -223,7 +224,7 @@ circ.copy_status.prototype = {
                                                                var barcode = obj.selection_list[i].barcode;
                                                                if (test == 't') {
                                                                        circ.util.renew_via_barcode( barcode );
-                                                                       funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
+                                                                       funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) );
                                                                } else {
                                                                        alert('Item with barcode ' + barcode + ' is not circulating.');
                                                                }
@@ -241,7 +242,7 @@ circ.copy_status.prototype = {
                                                        cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
                                                        for (var i = 0; i < obj.selection_list.length; i++) {
                                                                var barcode = obj.selection_list[i].barcode;
-                                                               funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
+                                                               funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) );
                                                        }
                                                        for (var i = 0; i < funcs.length; i++) { funcs[i](); }
                                                }
@@ -254,7 +255,7 @@ circ.copy_status.prototype = {
                                                        cat.util.mark_item_missing( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
                                                        for (var i = 0; i < obj.selection_list.length; i++) {
                                                                var barcode = obj.selection_list[i].barcode;
-                                                               funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
+                                                               funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) );
                                                        }
                                                        for (var i = 0; i < funcs.length; i++) { funcs[i](); }
                                                }
@@ -945,7 +946,7 @@ circ.copy_status.prototype = {
                }
        },
 
-       'copy_status' : function(barcode) {
+       'copy_status' : function(barcode,refresh) {
                var obj = this;
                try {
                        try { document.getElementById('last_scanned').setAttribute('value',''); } catch(E) {}
@@ -990,30 +991,44 @@ circ.copy_status.prototype = {
                                                var x = document.getElementById('trim_list');
                                                if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
                                        }
-                                       obj.list.append(
-                                               {
-                                                       'retrieve_id' : js2JSON( 
-                                                               { 
-                                                                       'renewable' : details.circ ? 't' : 'f', 
-                                                                       'copy_id' : details.copy.id(), 
-                                                                       'acn_id' : details.volume ? details.volume.id() : -1, 
-                                                                       'barcode' : barcode, 
-                                                                       'doc_id' : details.mvr ? details.mvr.doc_id() : null  
-                                                               } 
-                                                       ),
-                                                       'row' : {
-                                                               'my' : {
-                                                                       'mvr' : details.mvr,
-                                                                       'acp' : details.copy,
-                                                                       'acn' : details.volume,
-                                                                       'atc' : details.transit,
-                                                                       'circ' : details.circ,
-                                                                       'ahr' : details.hold,
-                                                               }
-                                                       },
-                                                       'to_top' : true,
+                                       var params = {
+                                               'retrieve_id' : js2JSON( 
+                                                       { 
+                                                               'renewable' : details.circ ? 't' : 'f', 
+                                                               'copy_id' : details.copy.id(), 
+                                                               'acn_id' : details.volume ? details.volume.id() : -1, 
+                                                               'barcode' : barcode, 
+                                                               'doc_id' : details.mvr ? details.mvr.doc_id() : null  
+                                                       } 
+                                               ),
+                                               'row' : {
+                                                       'my' : {
+                                                               'mvr' : details.mvr,
+                                                               'acp' : details.copy,
+                                                               'acn' : details.volume,
+                                                               'atc' : details.transit,
+                                                               'circ' : details.circ,
+                                                               'ahr' : details.hold,
+                                                       }
+                                               },
+                                               'to_top' : true,
+                                       };
+                                       if (!refresh) {
+                                               var nparams = obj.list.append(params);
+                                               if (!document.getElementById('trim_list').checked) {
+                                                       if (typeof obj.list_barcode_map[barcode] == 'undefined') obj.list_barcode_map[barcode] =[];
+                                                       obj.list_barcode_map[barcode].push(nparams);
+                                               }
+                                       } else {
+                                               if (!document.getElementById('trim_list').checked) {
+                                                       for (var i = 0; i < obj.list_barcode_map[barcode].length; i++) {
+                                                               params.my_node = obj.list_barcode_map[barcode][i].my_node;
+                                                               obj.list.refresh_row(params);
+                                                       }
+                                               } else {
+                                                       obj.list.append(params);
                                                }
-                                       );
+                                       }
                                } catch(E) {
                                        obj.error.standard_unexpected_error_alert('barcode = ' + barcode,E);
                                }
index 79157d9..8b8ef0d 100644 (file)
@@ -84,7 +84,7 @@ patron.bills.prototype = {
                                obj.current_payments = []; obj.list.clear();
                                //FIXME//.bills virtual field
                                for (var i = 0; i < obj.bills.length; i++) {
-                                       var rnode = obj.list.append( 
+                                       var rparams = obj.list.append( 
                                                { 'row' : 
                                                        { 'my' : 
                                                                { 'mobts' : obj.bills[i].transaction, 'circ' : obj.bills[i].circ, 'mvr' : obj.bills[i].record } 
@@ -92,6 +92,7 @@ patron.bills.prototype = {
                                                        'attributes' : { 'allowevents' : true } 
                                                } 
                                        );
+                                       var rnode = rparams.my_node;
                                        obj.bill_map[ obj.bills[i].transaction.id() ] = obj.bills[i];
                                        var cb = rnode.getElementsByTagName('checkbox')[0];
                                        var tb = rnode.getElementsByTagName('textbox')[0];