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 = {
19 'init' : function (params) {
22 if (params && params.via == 'stash') {
23 this.stash_retrieve();
25 this.network_retrieve();
29 this.error.sdump('D_ERROR','Error in OpenILS.data.init('
30 +js2JSON(params)+'): ' + js2JSON(E) );
36 'stash' : function () {
38 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
39 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
40 var data_cache=new OpenILS( );
41 for (var i = 0; i < arguments.length; i++) {
42 this.error.sdump('D_DATA','stashing ' + arguments[i] + ' : ' + this[arguments[i]] + '\n');
43 data_cache.wrappedJSObject.OpenILS.prototype.data[arguments[i]] = this[arguments[i]];
46 this.error.sdump('D_ERROR','Error in OpenILS.data.stash(): ' + js2JSON(E) );
50 '_debug_stash' : function() {
52 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
53 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
54 var data_cache=new OpenILS( );
55 for (var i in data_cache.wrappedJSObject.OpenILS.prototype.data) {
56 dump('_debug_stash ' + i + '\n');
59 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
65 'pgt' : [ api.FM_PGT_RETRIEVE.app, api.FM_PGT_RETRIEVE.method, [], true ],
66 'cit' : [ api.FM_CIT_RETRIEVE.app, api.FM_CIT_RETRIEVE.method, [], true ],
67 'cst' : [ api.FM_CST_RETRIEVE.app, api.FM_CST_RETRIEVE.method, [], true ],
68 'acpl' : [ api.FM_ACPL_RETRIEVE.app, api.FM_ACPL_RETRIEVE.method, [], true ],
69 'ccs' : [ api.FM_CCS_RETRIEVE.app, api.FM_CCS_RETRIEVE.method, [], true ],
70 'aou' : [ api.FM_AOU_RETRIEVE.app, api.FM_AOU_RETRIEVE.method, [], true ],
71 'aout' : [ api.FM_AOUT_RETRIEVE.app, api.FM_AOUT_RETRIEVE.method, [], true ]
74 'stash_retrieve' : function() {
76 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
77 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
78 var data_cache=new OpenILS( );
79 var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
81 this.error.sdump('D_DATA','Retrieving ' + i + ' : ' + dc[i] + '\n');
84 if (typeof this.on_complete == 'function') {
89 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
93 'network_retrieve' : function() {
96 JSAN.use('util.file');
97 JSAN.use('util.functional');
98 JSAN.use('util.fm_utils');
100 function gen_fm_retrieval_func(classname,data) {
101 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
106 if (obj.list[classname].constructor.name == 'Array') {
107 obj.hash[classname] =
108 util.functional.convert_object_list_to_hash(
114 obj.error.sdump('D_ERROR',E + '\n');
120 obj.list[classname] = obj.network.request( app, method, params);
122 // if cacheable, store an offline copy
124 var file = new util.file( classname );
125 file.set_object( obj.list[classname] );
129 // if cacheable, try offline
132 var file = new util.file( classname );
133 obj.list[classname] = file.get_object();
149 var f = gen_fm_retrieval_func(
152 api.FM_AU_RETRIEVE_VIA_SESSION.app,
153 api.FM_AU_RETRIEVE_VIA_SESSION.method,
161 var error = 'Error: ' + js2JSON(E);
162 obj.error.sdump('D_ERROR',error);
166 obj.list.au = [ obj.list.au ];
170 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
172 for (var i in this._fm_objects) {
173 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
176 // The previous org_tree call returned a tree, not a list or hash.
179 obj.org_tree = obj.list.aou;
180 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.org_tree );
181 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
186 gen_fm_retrieval_func('my_aou',
188 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
189 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
196 // Do this after we get the user object
201 gen_fm_retrieval_func( 'my_actsc',
203 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
204 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
205 [ obj.session, obj.list.au[0].home_ou() ],
212 if (typeof this.on_complete == 'function') {
214 this.chain.push( this.on_complete );
216 JSAN.use('util.exec'); this.exec = new util.exec();
217 this.exec.on_error = function(E) {
219 if (typeof obj.on_error == 'function') {
222 alert('oops: ' + E );
225 return false; /* break chain */
228 this.exec.chain( this.chain );
233 dump('exiting OpenILS/data.js\n');