From 7925626ce18bf7e639eede77d329556ae2e5c4ee Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 17 Sep 2013 22:53:03 -0400 Subject: [PATCH] minor UI twiddles; startup async batch fetching tools Signed-off-by: Bill Erickson --- env.js | 75 +++++++++++++++++++++++++++++++++++++++++++++++--------- main.js | 18 +++++++++++++- org.js | 32 ++---------------------- patron.html | 3 ++- patron_search.js | 6 ++++- 5 files changed, 90 insertions(+), 44 deletions(-) diff --git a/env.js b/env.js index 2edd84b59..664674d66 100644 --- a/env.js +++ b/env.js @@ -1,10 +1,66 @@ -// load various bits of data we need via asnc call chain +// load various bits of data we need via an asnc batchs +// when all is loaded, call the final client-provided onload -function load_what_i_need(onload) { - var ses = new OpenSRF.ClientSession('open-ils.pcrud'); +function load_env(onload) { + // for now, load all registered classes + new BatchFetcher().load_all(onload); +} + +function BatchFetcher() { + var self = this; + this.loaders = {}; + this.pses = new OpenSRF.ClientSession('open-ils.pcrud'); + + this.onload_handler = function() { + if (--self.in_flight == 0) { + self.onload(); + } + }; + + this.load_all = function(onload) { + self.load( + Object.keys(self.loaders), + onload + ); + }; + + this.load = function(classes, onload) { + self.onload = onload; + self.in_flight = classes.length; + dojo.forEach(classes, function(cls) { + console.log('fetching class ' + cls); + self.loaders[cls](function() {self.onload_handler()}); + }); + }; + + this.loaders.aou = function() { + self.pses.request({ + async : true, + method : 'open-ils.pcrud.search.aou', + params : [ + cache.authtoken, + {parent_ou : null}, + { flesh : -1, + flesh_fields : {aou : ['children', 'ou_type']} + } + ], + oncomplete : function(r) { + cache.aou = { + tree : r.recv().content(), + map : {} + }; + function d(node) { + cache.aou.map[node.id()] = node; + dojo.forEach(node.children(), function(c) { d(c) }); + } + d(cache.aou.tree); + self.onload_handler(); + } + }).send(); + }; - function load_pgt(onl) { - ses.request({ + this.loaders.pgt = function() { + self.pses.request({ async : true, method : 'open-ils.pcrud.search.pgt.atomic', params : [ @@ -17,14 +73,11 @@ function load_what_i_need(onload) { dojo.forEach(grps, function(grp) { cache.pgt.map[grp.id()] = grp; }); - if (onl) onl(); + self.onload_handler(); } }).send(); - } + }; +} - load_org_tree( - function() { load_pgt(onload) } - ); -} diff --git a/main.js b/main.js index 32c6a78c0..f20bfc446 100644 --- a/main.js +++ b/main.js @@ -19,5 +19,21 @@ function init(onload) { } load_IDL(); - load_what_i_need(onload); + + // may have an authtoken that expired + var ses = new OpenSRF.ClientSession('open-ils.auth'); + ses.request({ + method : 'open-ils.auth.session.retrieve', + params : [cache.authtoken], + oncomplete : function(r) { + var user = r.recv(); + if (user && user.content() && user.content().classname) + return load_env(function() { + dojo.removeClass('container', 'hidden'); + dojo.addClass('progress', 'hidden'); + onload() + }); + dojo.removeClass('login', 'hidden'); + } + }).send(); } diff --git a/org.js b/org.js index 9f3822a1f..f0dd383e3 100644 --- a/org.js +++ b/org.js @@ -1,33 +1,5 @@ -// fetches the org unit tree. -// creates cache.aou.tree and cache.aou.map -function load_org_tree(onload) { - cache.aou = {}; - var ses = new OpenSRF.ClientSession('open-ils.pcrud'); - ses.request({ - async : true, - method : 'open-ils.pcrud.search.aou', - params : [ - cache.authtoken, - {parent_ou : null}, - { flesh : -1, - flesh_fields : {aou : ['children', 'ou_type']} - } - ], - - oncomplete : function(r) { - cache.aou.tree = r.recv().content(); - cache.aou.map = {}; - // map the tree into the map - function d(node) { - cache.aou.map[node.id()] = node; - dojo.forEach(node.children(), function(c) { d(c) }); - } - d(cache.aou.tree); - if (onload) - onload(); - } - }).send(); -} +// org units are central to everything. put some common +// org mangling code here function get_org_unit(node_or_id) { return diff --git a/patron.html b/patron.html index 6d7e9a892..dc36a46a9 100644 --- a/patron.html +++ b/patron.html @@ -27,7 +27,8 @@ Holds Messages -
+
+