1 dump('entering OpenILS/data.js\n');
3 if (typeof OpenILS == 'undefined') OpenILS = {};
4 OpenILS.data = function () {
6 JSAN.use('util.error'); this.error = new util.error();
7 JSAN.use('main.network'); this.network = new main.network();
11 JSAN.use('util.file');
12 JSAN.use('util.functional');
13 JSAN.use('util.fm_utils');
15 function gen_fm_retrieval_func(classname,data) {
16 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
21 if (obj.list[classname].constructor.name == 'Array') {
23 util.functional.convert_object_list_to_hash(
29 obj.error.sdump('D_ERROR',E + '\n');
35 obj.list[classname] = obj.network.request( app, method, params);
37 // if cacheable, store an offline copy
39 var file = new util.file( classname );
40 file.set_object( obj.list[classname] );
44 // if cacheable, try offline
47 var file = new util.file( classname );
48 obj.list[classname] = file.get_object();
64 var f = gen_fm_retrieval_func(
68 'open-ils.search.actor.user.session',
76 // Probably the one thing we should not cache, so what do we do?
77 obj.list.au = new au();
78 obj.list.au.home_lib( '1' );
83 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
85 for (var i in this._fm_objects) {
86 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
89 // The previous org_tree call returned a tree, not a list or hash.
92 obj.org_tree = obj.list.aou;
93 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.org_tree );
94 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
99 gen_fm_retrieval_func('my_aou',
102 'open-ils.actor.org_unit.full_path.retrieve',
109 // Do this after we get the user object
114 gen_fm_retrieval_func( 'my_actsc',
117 'open-ils.circ.stat_cat.actor.retrieve.all',
118 [ obj.session, obj.list.au.home_ou() ],
128 OpenILS.data.prototype = {
133 'init' : function (stash) {
138 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
139 var data_cache=new OpenILS( );
140 var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
142 this.error.sdump('D_DATA','Retrieving ' + i + ' : ' + dc[i] + '\n');
146 this.error.sdump('D_ERROR','Error in OpenILS.data.init(true): ' + js2JSON(E) );
149 if (typeof this.on_complete == 'function') {
155 if (typeof this.on_complete == 'function') {
157 this.chain.push( this.on_complete );
159 JSAN.use('util.exec'); this.exec = new util.exec();
160 this.exec.on_error = function(E) { alert('oops: ' + E ); }
162 this.exec.chain( this.chain );
166 'stash' : function () {
168 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
169 var data_cache=new OpenILS( );
170 for (var i = 0; i < arguments.length; i++) {
171 this.error.sdump('D_DATA','stashing ' + arguments[i] + ' : ' + this[arguments[i]] + '\n');
172 data_cache.wrappedJSObject.OpenILS.prototype.data[arguments[i]] = this[arguments[i]];
175 this.error.sdump('D_ERROR','Error in OpenILS.data.stash(): ' + js2JSON(E) );
179 '_debug_stash' : function() {
181 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
182 var data_cache=new OpenILS( );
183 for (var i in data_cache.wrappedJSObject.OpenILS.prototype.data) {
184 dump('_debug_stash ' + i + '\n');
187 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
193 'pgt' : [ 'open-ils.actor', 'open-ils.actor.groups.retrieve', [], true ],
194 'cit' : [ 'open-ils.actor', 'open-ils.actor.user.ident_types.retrieve', [], true ],
195 'cst' : [ 'open-ils.actor', 'open-ils.actor.standings.retrieve', [], true ],
196 'acpl' : [ 'open-ils.search', 'open-ils.search.config.copy_location.retrieve.all', [], true ],
197 'ccs' : [ 'open-ils.search', 'open-ils.search.config.copy_status.retrieve.all', [], true ],
198 'aou' : [ 'open-ils.actor', 'open-ils.actor.org_tree.retrieve', [], true ],
199 'aout' : [ 'open-ils.actor', 'open-ils.actor.org_types.retrieve', [], true ]
204 dump('exiting OpenILS/data.js\n');