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();
12 OpenILS.data.prototype = {
17 'init' : function (params) {
20 if (params && params.via == 'stash') {
21 this.stash_retrieve();
23 this.network_retrieve();
27 this.error.sdump('D_ERROR','Error in OpenILS.data.init('
28 +js2JSON(params)+'): ' + js2JSON(E) );
34 'stash' : function () {
36 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
37 var data_cache=new OpenILS( );
38 for (var i = 0; i < arguments.length; i++) {
39 this.error.sdump('D_DATA','stashing ' + arguments[i] + ' : ' + this[arguments[i]] + '\n');
40 data_cache.wrappedJSObject.OpenILS.prototype.data[arguments[i]] = this[arguments[i]];
43 this.error.sdump('D_ERROR','Error in OpenILS.data.stash(): ' + js2JSON(E) );
47 '_debug_stash' : function() {
49 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
50 var data_cache=new OpenILS( );
51 for (var i in data_cache.wrappedJSObject.OpenILS.prototype.data) {
52 dump('_debug_stash ' + i + '\n');
55 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
61 'pgt' : [ 'open-ils.actor', 'open-ils.actor.groups.retrieve', [], true ],
62 'cit' : [ 'open-ils.actor', 'open-ils.actor.user.ident_types.retrieve', [], true ],
63 'cst' : [ 'open-ils.actor', 'open-ils.actor.standings.retrieve', [], true ],
64 'acpl' : [ 'open-ils.search', 'open-ils.search.config.copy_location.retrieve.all', [], true ],
65 'ccs' : [ 'open-ils.search', 'open-ils.search.config.copy_status.retrieve.all', [], true ],
66 'aou' : [ 'open-ils.actor', 'open-ils.actor.org_tree.retrieve', [], true ],
67 'aout' : [ 'open-ils.actor', 'open-ils.actor.org_types.retrieve', [], true ]
70 'stash_retrieve' : function() {
71 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
72 var data_cache=new OpenILS( );
73 var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
75 this.error.sdump('D_DATA','Retrieving ' + i + ' : ' + dc[i] + '\n');
78 if (typeof this.on_complete == 'function') {
84 'network_retrieve' : function() {
87 JSAN.use('util.file');
88 JSAN.use('util.functional');
89 JSAN.use('util.fm_utils');
91 function gen_fm_retrieval_func(classname,data) {
92 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
97 if (obj.list[classname].constructor.name == 'Array') {
99 util.functional.convert_object_list_to_hash(
105 obj.error.sdump('D_ERROR',E + '\n');
111 obj.list[classname] = obj.network.request( app, method, params);
113 // if cacheable, store an offline copy
115 var file = new util.file( classname );
116 file.set_object( obj.list[classname] );
120 // if cacheable, try offline
123 var file = new util.file( classname );
124 obj.list[classname] = file.get_object();
140 var f = gen_fm_retrieval_func(
144 'open-ils.search.actor.user.session',
152 // Probably the one thing we should not cache, so what do we do?
153 obj.list.au = new au();
154 obj.list.au.home_lib( '1' );
159 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
161 for (var i in this._fm_objects) {
162 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
165 // The previous org_tree call returned a tree, not a list or hash.
168 obj.org_tree = obj.list.aou;
169 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.org_tree );
170 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
175 gen_fm_retrieval_func('my_aou',
178 'open-ils.actor.org_unit.full_path.retrieve',
185 // Do this after we get the user object
190 gen_fm_retrieval_func( 'my_actsc',
193 'open-ils.circ.stat_cat.actor.retrieve.all',
194 [ obj.session, obj.list.au.home_ou() ],
201 if (typeof this.on_complete == 'function') {
203 this.chain.push( this.on_complete );
205 JSAN.use('util.exec'); this.exec = new util.exec();
206 this.exec.on_error = function(E) {
208 if (typeof obj.on_error == 'function') {
211 alert('oops: ' + E );
215 this.exec.chain( this.chain );
220 dump('exiting OpenILS/data.js\n');