1 dump('entering OpenILS/data.js\n');
3 if (typeof OpenILS == 'undefined') OpenILS = {};
4 OpenILS.data = function (params) {
6 this.session = params.session;
8 JSAN.use('util.error'); this.error = new util.error();
9 JSAN.use('main.network'); this.network = new main.network();
13 JSAN.use('util.file');
14 JSAN.use('util.functional');
15 JSAN.use('util.fm_utils');
17 function gen_fm_retrieval_func(classname,data) {
18 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
23 if (obj.list[classname].constructor.name == 'Array') {
25 util.functional.convert_object_list_to_hash(
31 obj.error.sdump('D_ERROR',E + '\n');
37 obj.list[classname] = obj.network.request( app, method, params);
39 // if cacheable, store an offline copy
41 var file = new util.file( classname );
42 file.set_object( obj.list[classname] );
46 // if cacheable, try offline
49 var file = new util.file( classname );
50 obj.list[classname] = file.get_object();
66 var f = gen_fm_retrieval_func(
70 'open-ils.search.actor.user.session',
78 // Probably the one thing we should not cache, so what do we do?
79 obj.list.au = new au();
80 obj.list.au.home_lib( '1' );
85 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
87 for (var i in this._fm_objects) {
88 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
91 // The previous org_tree call returned a tree, not a list or hash.
94 obj.org_tree = obj.list.aou;
95 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.org_tree );
96 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
101 gen_fm_retrieval_func('my_aou',
104 'open-ils.actor.org_unit.full_path.retrieve',
111 // Do this after we get the user object
116 gen_fm_retrieval_func( 'my_actsc',
119 'open-ils.circ.stat_cat.actor.retrieve.all',
120 [ obj.session, obj.list.au.home_ou() ],
130 OpenILS.data.prototype = {
135 'init' : function (stash) {
140 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
141 var data_cache=new OpenILS( );
142 this.list = data_cache.wrappedJSObject.OpenILS.prototype.data.list;
143 this.hash = data_cache.wrappedJSObject.OpenILS.prototype.data.hash;
145 this.error.sdump('D_ERROR','Error in OpenILS.data.init(true): ' + js2JSON(E) );
148 if (typeof this.on_complete == 'function') {
154 if (typeof this.on_complete == 'function') {
156 this.chain.push( this.on_complete );
159 JSAN.use('util.exec');
160 util.exec.chain( this.chain );
164 'stash' : function () {
166 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
167 var data_cache=new OpenILS( );
168 data_cache.wrappedJSObject.OpenILS.prototype.data = {
173 this.error.sdump('D_ERROR','Error in OpenILS.data.stash(): ' + js2JSON(E) );
179 'pgt' : [ 'open-ils.actor', 'open-ils.actor.groups.retrieve', [], true ],
180 'cit' : [ 'open-ils.actor', 'open-ils.actor.user.ident_types.retrieve', [], true ],
181 'cst' : [ 'open-ils.actor', 'open-ils.actor.standings.retrieve', [], true ],
182 'acpl' : [ 'open-ils.search', 'open-ils.search.config.copy_location.retrieve.all', [], true ],
183 'ccs' : [ 'open-ils.search', 'open-ils.search.config.copy_status.retrieve.all', [], true ],
184 'aou' : [ 'open-ils.actor', 'open-ils.actor.org_tree.retrieve', [], true ],
185 'aout' : [ 'open-ils.actor', 'open-ils.actor.org_types.retrieve', [], true ]
190 dump('exiting OpenILS/data.js\n');