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 = {
20 'init' : function (params) {
23 if (params && params.via == 'stash') {
24 this.stash_retrieve();
26 this.network_retrieve();
30 this.error.sdump('D_ERROR','Error in OpenILS.data.init('
31 +js2JSON(params)+'): ' + js2JSON(E) );
37 'stash' : function () {
39 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
40 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
41 var data_cache=new OpenILS( );
42 for (var i = 0; i < arguments.length; i++) {
43 this.error.sdump('D_DATA','stashing ' + arguments[i] + ' : ' + this[arguments[i]] + '\n');
44 data_cache.wrappedJSObject.OpenILS.prototype.data[arguments[i]] = this[arguments[i]];
47 this.error.sdump('D_ERROR','Error in OpenILS.data.stash(): ' + js2JSON(E) );
51 '_debug_stash' : function() {
53 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
54 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
55 var data_cache=new OpenILS( );
56 for (var i in data_cache.wrappedJSObject.OpenILS.prototype.data) {
57 dump('_debug_stash ' + i + '\n');
60 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
66 'pgt' : [ api.FM_PGT_RETRIEVE.app, api.FM_PGT_RETRIEVE.method, [], true ],
67 'cit' : [ api.FM_CIT_RETRIEVE.app, api.FM_CIT_RETRIEVE.method, [], true ],
68 'cst' : [ api.FM_CST_RETRIEVE.app, api.FM_CST_RETRIEVE.method, [], true ],
69 'acpl' : [ api.FM_ACPL_RETRIEVE.app, api.FM_ACPL_RETRIEVE.method, [], true ],
70 'ccs' : [ api.FM_CCS_RETRIEVE.app, api.FM_CCS_RETRIEVE.method, [], true ],
71 'aou' : [ api.FM_AOU_RETRIEVE.app, api.FM_AOU_RETRIEVE.method, [], true ],
72 'aout' : [ api.FM_AOUT_RETRIEVE.app, api.FM_AOUT_RETRIEVE.method, [], true ]
75 'stash_retrieve' : function() {
77 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
78 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
79 var data_cache=new OpenILS( );
80 var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
82 this.error.sdump('D_DATA','Retrieving ' + i + ' : ' + dc[i] + '\n');
85 if (typeof this.on_complete == 'function') {
90 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
94 'print_list_defaults' : function() {
96 if (typeof obj.print_list_templates == 'undefined') {
97 obj.print_list_types = [
101 'offline_inhouse_use',
106 obj.print_list_templates = {
109 'header' : 'The following items have been examined:<hr/><ol>',
110 'line_item' : '<li>%title%\r\nBarcode: %barcode%\r\n',
111 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\n',
115 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following items:<hr/><ol>',
116 'line_item' : '<li>%title%\r\nBarcode: %barcode% Due: %due_date%\r\n',
117 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
121 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou checked out the following items:<hr/><ol>',
122 'line_item' : '<li>%title%\r\nBarcode: %barcode% Due: %due_date%\r\n',
123 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
125 'offline_checkout' : {
126 'type' : 'offline_checkout',
127 'header' : 'Patron %patron_barcode%\r\nYou checked out the following items:<hr/><ol>',
128 'line_item' : '<li>Barcode: %barcode%\r\nDue: %due_date%\r\n',
129 'footer' : '</ol><hr />%TODAY%',
133 'header' : 'You checked in the following items:<hr/><ol>',
134 'line_item' : '<li>%title%\r\nBarcode: %barcode% Call Number: %call_number%\r\n',
135 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\n',
137 'offline_checkin' : {
138 'type' : 'offline_checkin',
139 'header' : 'You checked in the following items:<hr/><ol>',
140 'line_item' : '<li>Barcode: %barcode%\r\n',
141 'footer' : '</ol><hr />%TODAY%',
144 'type' : 'offline_renew',
145 'header' : 'You renewed the following items:<hr/><ol>',
146 'line_item' : '<li>Barcode: %barcode%\r\n',
147 'footer' : '</ol><hr />%TODAY%',
149 'offline_inhouse_use' : {
150 'type' : 'offline_inhouse_use',
151 'header' : 'You marked the following in-house items used:<hr/><ol>',
152 'line_item' : '<li>Barcode: %barcode%\r\nUses: %count%',
153 'footer' : '</ol><hr />%TODAY%',
157 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following titles on hold:<hr/><ol>',
158 'line_item' : '<li>%title%\r\n',
159 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
163 obj.stash( 'print_list_templates', 'print_list_types' );
167 'network_retrieve' : function() {
168 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
172 JSAN.use('util.file'); var file = new util.file('print_list_templates');
173 obj.print_list_defaults();
174 if (file._file.exists()) {
176 var x = file.get_object();
178 obj.print_list_templates = x;
179 obj.stash('print_list_templates');
187 JSAN.use('util.file');
188 JSAN.use('util.functional');
189 JSAN.use('util.fm_utils');
191 function gen_fm_retrieval_func(classname,data) {
192 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
194 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
197 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
199 if (obj.list[classname].constructor.name == 'Array') {
200 obj.hash[classname] =
201 util.functional.convert_object_list_to_hash(
207 obj.error.sdump('D_ERROR',E + '\n');
213 var level = obj.error.sdump_levels.D_SES_RESULT;
214 if (classname == 'aou' || classname == 'my_aou')
215 obj.error.sdump_levels.D_SES_RESULT = false;
216 var robj = obj.network.request( app, method, params);
217 if (!robj || robj.ilsevent) {
218 obj.error.standard_unexpected_error_alert('The staff client failed to retrieve expected data from this call, "' + method + '"',robj);
221 obj.list[classname] = robj;
222 obj.error.sdump_levels.D_SES_RESULT = level;
224 // if cacheable, store an offline copy
225 /* FIXME -- we're going to revisit caching and do it differently
227 var file = new util.file( classname );
228 file.set_object( obj.list[classname] );
233 // if cacheable, try offline
235 /* FIXME -- we're going to revisit caching and do it differently
237 var file = new util.file( classname );
238 obj.list[classname] = file.get_object(); file.close();
256 var f = gen_fm_retrieval_func(
259 api.FM_AU_RETRIEVE_VIA_SESSION.app,
260 api.FM_AU_RETRIEVE_VIA_SESSION.method,
268 var error = 'Error: ' + js2JSON(E);
269 obj.error.sdump('D_ERROR',error);
272 obj.list.au = [ obj.list.au ];
278 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
279 var f = gen_fm_retrieval_func(
282 api.FM_ASV_RETRIEVE_REQUIRED.app,
283 api.FM_ASV_RETRIEVE_REQUIRED.method,
289 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
292 var error = 'Error: ' + js2JSON(E);
293 obj.error.sdump('D_ERROR',error);
301 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
302 var f = gen_fm_retrieval_func(
305 api.FM_ASV_RETRIEVE.app,
306 api.FM_ASV_RETRIEVE.method,
312 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
315 var error = 'Error: ' + js2JSON(E);
316 obj.error.sdump('D_ERROR',error);
322 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
324 for (var i in this._fm_objects) {
325 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
328 // The previous org_tree call returned a tree, not a list or hash.
331 obj.tree.aou = obj.list.aou;
332 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
333 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
337 // Do this after we get the user object
342 gen_fm_retrieval_func('my_aou',
344 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
345 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
346 [ obj.session.key, obj.list.au[0].ws_ou() ], /* use ws_ou and not home_ou */
357 gen_fm_retrieval_func( 'my_actsc',
359 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
360 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
361 [ obj.session.key, obj.list.au[0].ws_ou() ],
372 gen_fm_retrieval_func( 'my_asc',
374 api.FM_ASC_RETRIEVE_VIA_AOU.app,
375 api.FM_ASC_RETRIEVE_VIA_AOU.method,
376 [ obj.session.key, obj.list.au[0].ws_ou() ],
386 var f = gen_fm_retrieval_func(
389 api.FM_CNCT_RETRIEVE.app,
390 api.FM_CNCT_RETRIEVE.method,
391 [ obj.list.au[0].ws_ou() ],
398 var error = 'Error: ' + js2JSON(E);
399 obj.error.sdump('D_ERROR',error);
406 if (typeof this.on_complete == 'function') {
408 this.chain.push( this.on_complete );
410 JSAN.use('util.exec'); this.exec = new util.exec();
411 this.exec.on_error = function(E) {
413 if (typeof obj.on_error == 'function') {
416 alert('oops: ' + E );
419 return false; /* break chain */
422 this.exec.chain( this.chain );
427 dump('exiting OpenILS/data.js\n');