From d0f81ebc1c545a3f52c73f04f7b20b3adf8e3513 Mon Sep 17 00:00:00 2001 From: dbs Date: Thu, 26 Mar 2009 17:42:46 +0000 Subject: [PATCH] Backport r12482 from trunk: phasefx fix for staff client holdings maintenance defaulting to the correct org_unit in a deep hierarchy git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_4@12690 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../xul/staff_client/chrome/content/util/exec.js | 14 ++++ .../xul/staff_client/server/cat/copy_browser.js | 89 ++++++++-------------- .../xul/staff_client/server/cat/copy_browser.xul | 1 + 3 files changed, 45 insertions(+), 59 deletions(-) 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 324db773eb..702d1ba18a 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 28f17f4326..b0a9a51209 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 ) { @@ -963,6 +964,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) { @@ -1001,15 +1004,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 ); @@ -1017,12 +1018,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); @@ -1036,16 +1036,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 ); @@ -1053,13 +1051,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); } @@ -1068,7 +1065,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( @@ -1081,15 +1077,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); @@ -1097,13 +1092,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); } @@ -1114,9 +1108,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; @@ -1127,33 +1119,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 ) @@ -1163,8 +1151,6 @@ cat.copy_browser.prototype = { } ); - exec.chain( funcs ); - } catch(E) { alert(E); } @@ -1189,15 +1175,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); @@ -1206,13 +1191,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); } @@ -1222,15 +1205,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) @@ -1241,7 +1223,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); @@ -1250,13 +1232,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) { @@ -1342,7 +1322,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() ); } ); } } @@ -1395,7 +1375,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) { @@ -1522,9 +1502,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( @@ -1536,7 +1515,7 @@ cat.copy_browser.prototype = { } ); if (!row.my.acp) { - funcs.push( + obj.funcs.push( function() { row.my.acp = obj.network.request( @@ -1553,7 +1532,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') { @@ -1563,14 +1542,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 34ca6d4a94..80fd075418 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: