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('util.network'); this.network = new util.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 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
37 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
38 var data_cache=new OpenILS( );
39 for (var i = 0; i < arguments.length; i++) {
40 this.error.sdump('D_DATA','stashing ' + arguments[i] + ' : ' + this[arguments[i]] + '\n');
41 data_cache.wrappedJSObject.OpenILS.prototype.data[arguments[i]] = this[arguments[i]];
44 this.error.sdump('D_ERROR','Error in OpenILS.data.stash(): ' + js2JSON(E) );
48 '_debug_stash' : function() {
50 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
51 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
52 var data_cache=new OpenILS( );
53 for (var i in data_cache.wrappedJSObject.OpenILS.prototype.data) {
54 dump('_debug_stash ' + i + '\n');
57 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
63 'pgt' : [ api.fm_pgt_retrieve.app, api.fm_pgt_retrieve.method, [], true ],
64 'cit' : [ api.fm_cit_retrieve.app, api.fm_cit_retrieve.method, [], true ],
65 'cst' : [ api.fm_cst_retrieve.app, api.fm_cst_retrieve.method, [], true ],
66 'acpl' : [ api.fm_acpl_retrieve.app, api.fm_acpl_retrieve.method, [], true ],
67 'ccs' : [ api.fm_ccs_retrieve.app, api.fm_ccs_retrieve.method, [], true ],
68 'aou' : [ api.fm_aou_retrieve.app, api.fm_aou_retrieve.method, [], true ],
69 'aout' : [ api.fm_aout_retrieve.app, api.fm_aout_retrieve.method, [], true ]
72 'stash_retrieve' : function() {
74 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
75 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
76 var data_cache=new OpenILS( );
77 var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
79 this.error.sdump('D_DATA','Retrieving ' + i + ' : ' + dc[i] + '\n');
82 if (typeof this.on_complete == 'function') {
87 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
91 'network_retrieve' : function() {
94 JSAN.use('util.file');
95 JSAN.use('util.functional');
96 JSAN.use('util.fm_utils');
98 function gen_fm_retrieval_func(classname,data) {
99 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
104 if (obj.list[classname].constructor.name == 'Array') {
105 obj.hash[classname] =
106 util.functional.convert_object_list_to_hash(
112 obj.error.sdump('D_ERROR',E + '\n');
118 obj.list[classname] = obj.network.request( app, method, params);
120 // if cacheable, store an offline copy
122 var file = new util.file( classname );
123 file.set_object( obj.list[classname] );
127 // if cacheable, try offline
130 var file = new util.file( classname );
131 obj.list[classname] = file.get_object();
147 var f = gen_fm_retrieval_func(
150 api.fm_au_retrieve_via_session.app,
151 api.fm_au_retrieve_via_session.method,
159 // Probably the one thing we should not cache, so what do we do?
160 obj.list.au = new au();
161 obj.list.au.home_lib( '1' );
166 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
168 for (var i in this._fm_objects) {
169 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
172 // The previous org_tree call returned a tree, not a list or hash.
175 obj.org_tree = obj.list.aou;
176 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.org_tree );
177 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
182 gen_fm_retrieval_func('my_aou',
184 api.fm_aou_retrieve_related_via_session.app,
185 api.fm_aou_retrieve_related_via_session.method,
192 // Do this after we get the user object
197 gen_fm_retrieval_func( 'my_actsc',
199 api.fm_actsc_retrieve_via_aou.app,
200 api.fm_actsc_retrieve_via_aou.method,
201 [ obj.session, obj.list.au.home_ou() ],
208 if (typeof this.on_complete == 'function') {
210 this.chain.push( this.on_complete );
212 JSAN.use('util.exec'); this.exec = new util.exec();
213 this.exec.on_error = function(E) {
215 if (typeof obj.on_error == 'function') {
218 alert('oops: ' + E );
222 this.exec.chain( this.chain );
227 dump('exiting OpenILS/data.js\n');