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;
};
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 ]
}
}