From f62b1ae29032f6e9542d7753c5112ba1a5c24ecb Mon Sep 17 00:00:00 2001 From: phasefx Date: Mon, 3 Oct 2005 21:28:50 +0000 Subject: [PATCH] pulling/storing the data git-svn-id: svn://svn.open-ils.org/ILS/trunk@1890 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../chrome/content/evergreen/OpenILS/data.js | 132 +++++++++++------- 1 file changed, 83 insertions(+), 49 deletions(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/evergreen/OpenILS/data.js b/Open-ILS/xul/staff_client/chrome/content/evergreen/OpenILS/data.js index 1b57759808..161db0a732 100644 --- a/Open-ILS/xul/staff_client/chrome/content/evergreen/OpenILS/data.js +++ b/Open-ILS/xul/staff_client/chrome/content/evergreen/OpenILS/data.js @@ -7,62 +7,96 @@ OpenILS.data = function (mw,G) { var obj = this; - this.chain = []; - - this.chain.push( - function() { - try { - obj.au = obj.G.network.request( - 'open-ils.search', - 'open-ils.search.actor.user.session', - [ obj.G.auth.session.key ] - ); - } catch(E) { - // what should we do? - } - } - ); - - function a_get(obj,i) { return [i, obj[i]]; } // funkiness with loops and closures - JSAN.use('util.file'); + JSAN.use('util.functional'); + JSAN.use('util.fm_utils'); function gen_fm_retrieval_func(classname,data) { - var app = data[0]; var method = data[1]; var params = data[2]; + var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3]; return function () { try { obj.list[classname] = obj.G.network.request( app, method, params); - // store an offline copy - var file = new util.file( obj.mw, obj.G, classname ); - file.set_object( obj.list[classname] ); + try { + if (obj.list[classname].constructor.name == 'Array') { + obj.hash[classname] = + util.functional.convert_object_list_to_hash( + obj.list[classname] + ); + } + } catch(E) { + + obj.G.error.sdump('D_ERROR',E + '\n'); + } + // if cacheable, store an offline copy + if (cacheable) { + var file = new util.file( obj.mw, obj.G, classname ); + file.set_object( obj.list[classname] ); + } } catch(E) { - // try offline + // if cacheable, try offline + if (cacheable) { + } + throw(E); // for now } - //obj.hash[classname] = convert_object_list_to_hash( obj.list[classname] ); } } - obj.G.error.sdump('D_DEBUG','_cacheable_fm_objects = ' + js2JSON(this._cacheable_fm_objects) + '\n'); + this.chain = []; - for (var i in this._cacheable_fm_objects) { - this.chain.push( gen_fm_retrieval_func(i,this._cacheable_fm_objects[i]) ); - } + this.chain.push( + gen_fm_retrieval_func( + 'au', + [ + 'open-ils.search', + 'open-ils.search.actor.user.session', + [ obj.G.auth.session.key ], + false + ] + ) + ); - /* - var other_fm_objects = { - 'my_aou' : [ - 'open-ils.actor', - 'open-ils.actor.org_unit.full_path.retrieve', - [ obj.G.auth.session.key ] - ], - 'my_actsc' : [ - 'open-ils.circ', - 'open-ils.circ.stat_cat.actor.retrieve.all', - [ obj.G.auth.session.key, obj.au.home_ou.id() ] - ] + obj.G.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n'); + + for (var i in this._fm_objects) { + this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) ); } - */ + + // The previous org_tree call returned a tree, not a list or hash. + this.chain.push( + function () { + obj.org_tree = obj.list.aou; + obj.list.aou = util.fm_utils.flatten_ou_branch( obj.org_tree ); + obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou ); + } + ); + + this.chain.push( + gen_fm_retrieval_func('my_aou', + [ + 'open-ils.actor', + 'open-ils.actor.org_unit.full_path.retrieve', + [ obj.G.auth.session.key ], + true + ] + ) + ); + + // Do this after we get the user object + this.chain.push( + + function () { + + gen_fm_retrieval_func( 'my_actsc', + [ + 'open-ils.circ', + 'open-ils.circ.stat_cat.actor.retrieve.all', + [ obj.G.auth.session.key, obj.list.au.home_ou() ], + true + ] + )(); + } + ); return this; }; @@ -83,15 +117,15 @@ OpenILS.data.prototype = { util.exec.chain( this.chain ); }, - '_cacheable_fm_objects' : { + '_fm_objects' : { - 'pgt' : [ 'open-ils.actor', 'open-ils.actor.groups.retrieve', [] ], - 'cit' : [ 'open-ils.actor', 'open-ils.actor.user.ident_types.retrieve', [] ], - 'cst' : [ 'open-ils.actor', 'open-ils.actor.standings.retrieve', [] ], - 'acpl' : [ 'open-ils.search', 'open-ils.search.config.copy_location.retrieve.all', [] ], - 'ccs' : [ 'open-ils.search', 'open-ils.search.config.copy_status.retrieve.all', [] ], - 'aou' : [ 'open-ils.actor', 'open-ils.actor.org_tree.retrieve', [] ], - 'aout' : [ 'open-ils.actor', 'open-ils.actor.org_types.retrieve', [] ] + 'pgt' : [ 'open-ils.actor', 'open-ils.actor.groups.retrieve', [], true ], + 'cit' : [ 'open-ils.actor', 'open-ils.actor.user.ident_types.retrieve', [], true ], + 'cst' : [ 'open-ils.actor', 'open-ils.actor.standings.retrieve', [], true ], + 'acpl' : [ 'open-ils.search', 'open-ils.search.config.copy_location.retrieve.all', [], true ], + 'ccs' : [ 'open-ils.search', 'open-ils.search.config.copy_status.retrieve.all', [], true ], + 'aou' : [ 'open-ils.actor', 'open-ils.actor.org_tree.retrieve', [], true ], + 'aout' : [ 'open-ils.actor', 'open-ils.actor.org_types.retrieve', [], true ] } } -- 2.43.2