From: phasefx Date: Tue, 10 Mar 2009 04:52:52 +0000 (+0000) Subject: Fix Holdings Maintenance for >3-tier hierarchies. We force every parent org to be... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9e461a20fa68f849e12bc345e4dda0ffce62bba2;p=evergreen%2Ftadl.git Fix Holdings Maintenance for >3-tier hierarchies. We force every parent org to be rendered as open, but the most drastic change is the global function array that gets consumed by a setInterval. This was to fix some timing issues that came from multiple setTimeout function chains; notably, the SL1 stock library was rendering twice if Show Volumes was selected. git-svn-id: svn://svn.open-ils.org/ILS/trunk@12482 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/xul/staff_client/chrome/content/util/exec.js b/Open-ILS/xul/staff_client/chrome/content/util/exec.js index 2bed8293af..842a4183f4 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/exec.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/exec.js @@ -10,6 +10,20 @@ util.exec = function(chunk_size) { }; util.exec.prototype = { + // This will create a timer that polls the specified array and shifts off functions to execute + 'timer' : function(funcs,interval) { + var obj = this; + var intervalId = window.setInterval( + function() { + var i = obj.chunk_size; + while (funcs.length > 0 && i > 0) { + funcs.shift()(); + } + }, + interval + ); + window.addEventListener('unload',function() { window.clearInterval(intervalId); },false); + }, // This executes a series of functions, but tries to give other events/functions a chance to // execute between each one. 'chain' : function () { diff --git a/Open-ILS/xul/staff_client/server/cat/copy_browser.js b/Open-ILS/xul/staff_client/server/cat/copy_browser.js index 5280c65455..9e4155c6c1 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_browser.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_browser.js @@ -17,6 +17,7 @@ cat.copy_browser.prototype = { 'map_acn' : {}, 'map_acp' : {}, 'sel_list' : [], + 'funcs' : [], 'init' : function( params ) { @@ -962,6 +963,8 @@ cat.copy_browser.prototype = { obj.show_my_libs( ml.value ); + JSAN.use('util.exec'); var exec = new util.exec(20); exec.timer(obj.funcs,100); + obj.show_consortial_count(); } catch(E) { @@ -1000,15 +1003,13 @@ cat.copy_browser.prototype = { var p_org = obj.data.hash.aou[ org.parent_ou() ]; if (p_org) { - JSAN.use('util.exec'); var exec = new util.exec(); - var funcs = []; - funcs.push( function() { + obj.funcs.push( function() { document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); document.getElementById('lib_menu').setAttribute('disabled','true'); } ); for (var i = 0; i < p_org.children().length; i++) { - funcs.push( + obj.funcs.push( function(o) { return function() { obj.show_libs( o, false ); @@ -1016,12 +1017,11 @@ cat.copy_browser.prototype = { }( p_org.children()[i] ) ); } - funcs.push( function() { + obj.funcs.push( function() { document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); document.getElementById('lib_menu').setAttribute('disabled','false'); } ); - exec.chain( funcs ); } } catch(E) { alert(E); @@ -1035,16 +1035,14 @@ cat.copy_browser.prototype = { obj.show_libs( obj.data.tree.aou ); - JSAN.use('util.exec'); var exec = new util.exec(); - var funcs = []; - funcs.push( function() { + obj.funcs.push( function() { document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); document.getElementById('lib_menu').setAttribute('disabled','true'); } ); for (var i = 0; i < obj.data.tree.aou.children().length; i++) { - funcs.push( + obj.funcs.push( function(o) { return function() { obj.show_libs( o ); @@ -1052,13 +1050,12 @@ cat.copy_browser.prototype = { }( obj.data.tree.aou.children()[i] ) ); } - funcs.push( function() { + obj.funcs.push( function() { document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); document.getElementById('lib_menu').setAttribute('disabled','false'); } ); - exec.chain( funcs ); } catch(E) { alert(E); } @@ -1067,7 +1064,6 @@ cat.copy_browser.prototype = { 'show_libs_with_copies' : function() { var obj = this; try { - JSAN.use('util.exec'); var exec = new util.exec(); JSAN.use('util.functional'); var orgs = util.functional.map_list( @@ -1080,15 +1076,14 @@ cat.copy_browser.prototype = { return 0; } ); - var funcs = []; - funcs.push( function() { + obj.funcs.push( function() { document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); document.getElementById('lib_menu').setAttribute('disabled','true'); } ); for (var i = 0; i < orgs.length; i++) { - funcs.push( + obj.funcs.push( function(o) { return function() { obj.show_libs(o,false); @@ -1096,13 +1091,12 @@ cat.copy_browser.prototype = { }( orgs[i] ) ); } - funcs.push( function() { + obj.funcs.push( function() { document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); document.getElementById('lib_menu').setAttribute('disabled','false'); } ); - exec.chain( funcs ); } catch(E) { alert(E); } @@ -1113,9 +1107,7 @@ cat.copy_browser.prototype = { try { if (!start_aou) throw('show_libs: Need a start_aou'); JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'}); - JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec(); - - var funcs = []; + JSAN.use('util.functional'); var parents = []; var temp_aou = start_aou; @@ -1126,33 +1118,29 @@ cat.copy_browser.prototype = { parents.reverse(); for (var i = 0; i < parents.length; i++) { - funcs.push( + obj.funcs.push( function(o,p) { return function() { - if (show_open) { - obj.append_org(o,p,{'container':'true','open':'true'}); - } else { - obj.append_org(o,p,{'container':'true'}); - } + obj.append_org(o,p,{'container':'true','open':'true'}); }; }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ]) ); } - funcs.push( + obj.funcs.push( function(o,p) { return function() { obj.append_org(o,p); }; }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ]) ); - funcs.push( + obj.funcs.push( function() { if (start_aou.children()) { var x = obj.map_tree[ 'aou_' + start_aou.id() ]; x.setAttribute('container','true'); if (show_open) x.setAttribute('open','true'); for (var i = 0; i < start_aou.children().length; i++) { - funcs.push( + obj.funcs.push( function(o,p) { return function() { obj.append_org(o,p); }; }( start_aou.children()[i], start_aou ) @@ -1162,8 +1150,6 @@ cat.copy_browser.prototype = { } ); - exec.chain( funcs ); - } catch(E) { alert(E); } @@ -1188,15 +1174,14 @@ cat.copy_browser.prototype = { var obj = this; try { var acn_tree = obj.map_acp[ 'acn_' + acn_id ]; - var funcs = []; - funcs.push( function() { + obj.funcs.push( function() { document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); document.getElementById('lib_menu').setAttribute('disabled','true'); } ); if (acn_tree.copies()) { for (var i = 0; i < acn_tree.copies().length; i++) { - funcs.push( + obj.funcs.push( function(c,a) { return function() { obj.append_acp(c,a); @@ -1205,13 +1190,11 @@ cat.copy_browser.prototype = { ) } } - funcs.push( function() { + obj.funcs.push( function() { document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); document.getElementById('lib_menu').setAttribute('disabled','false'); } ); - JSAN.use('util.exec'); var exec = new util.exec(); - exec.chain( funcs ); } catch(E) { alert(E); } @@ -1221,15 +1204,14 @@ cat.copy_browser.prototype = { var obj = this; var org = obj.data.hash.aou[ org_id ]; if (obj.data.hash.aout[ org.ou_type() ].depth() == 0 && ! get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) return; - var funcs = []; - funcs.push( function() { + obj.funcs.push( function() { document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); document.getElementById('lib_menu').setAttribute('disabled','true'); } ); if (org.children()) { for (var i = 0; i < org.children().length; i++) { - funcs.push( + obj.funcs.push( function(o,p) { return function() { obj.append_org(o,p) @@ -1240,7 +1222,7 @@ cat.copy_browser.prototype = { } if (obj.map_acn[ 'aou_' + org_id ]) { for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) { - funcs.push( + obj.funcs.push( function(o,a) { return function() { obj.append_acn(o,a); @@ -1249,13 +1231,11 @@ cat.copy_browser.prototype = { ); } } - funcs.push( function() { + obj.funcs.push( function() { document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); document.getElementById('lib_menu').setAttribute('disabled','false'); } ); - JSAN.use('util.exec'); var exec = new util.exec(); - exec.chain( funcs ); }, 'append_org' : function (org,parent_org,params) { @@ -1341,7 +1321,7 @@ cat.copy_browser.prototype = { if (document.getElementById('show_acns').checked) { if (! ( obj.data.hash.aout[ org.ou_type() ].depth() == 0 && ! get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) )) { node.setAttribute('open','true'); - setTimeout( function() { obj.on_select_org( org.id() ); }, 0 ); + obj.funcs.push( function() { obj.on_select_org( org.id() ); } ); } } @@ -1394,7 +1374,7 @@ cat.copy_browser.prototype = { } if (document.getElementById('show_acps').checked) { node.setAttribute('open','true'); - setTimeout( function() { obj.on_select_acn( acn_tree.id() ); }, 0 ); + obj.funcs.push( function() { obj.on_select_acn( acn_tree.id() ); } ); } } catch(E) { @@ -1521,9 +1501,8 @@ cat.copy_browser.prototype = { var row = params.row; - var funcs = []; /* - if (!row.my.mvr) funcs.push( + if (!row.my.mvr) obj.funcs.push( function() { row.my.mvr = obj.network.request( @@ -1535,7 +1514,7 @@ cat.copy_browser.prototype = { } ); if (!row.my.acp) { - funcs.push( + obj.funcs.push( function() { row.my.acp = obj.network.request( @@ -1552,7 +1531,7 @@ cat.copy_browser.prototype = { params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() ); } */ - funcs.push( + obj.funcs.push( function() { if (typeof params.on_retrieve == 'function') { @@ -1562,14 +1541,6 @@ cat.copy_browser.prototype = { } ); - JSAN.use('util.exec'); var exec = new util.exec(); - exec.on_error = function(E) { - var err = 'items chain: ' + js2JSON(E); - obj.error.sdump('D_ERROR',err); - return true; /* keep going */ - } - exec.chain( funcs ); - return row; }, 'on_click' : function(ev) { diff --git a/Open-ILS/xul/staff_client/server/cat/copy_browser.xul b/Open-ILS/xul/staff_client/server/cat/copy_browser.xul index f09465edcf..5f358d86af 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_browser.xul +++ b/Open-ILS/xul/staff_client/server/cat/copy_browser.xul @@ -34,6 +34,7 @@ vim:noet:sw=4:ts=4: