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++) {
44 if (arguments[i] != 'hash' && arguments[i] != 'list') this.error.sdump('D_DATA_STASH','stashing ' + arguments[i] + ' : ' + this[arguments[i]] + (typeof this[arguments[i]] == 'object' ? ' = ' + js2JSON(this[arguments[i]]) : '') + '\n');
45 } catch(F) { alert(F); }
46 data_cache.wrappedJSObject.OpenILS.prototype.data[arguments[i]] = this[arguments[i]];
49 this.error.sdump('D_ERROR','Error in OpenILS.data.stash(): ' + js2JSON(E) );
53 '_debug_stash' : function() {
55 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
56 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
57 var data_cache=new OpenILS( );
58 for (var i in data_cache.wrappedJSObject.OpenILS.prototype.data) {
59 dump('_debug_stash ' + i + '\n');
62 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
68 'pgt' : [ api.FM_PGT_RETRIEVE.app, api.FM_PGT_RETRIEVE.method, [], true ],
69 'cit' : [ api.FM_CIT_RETRIEVE.app, api.FM_CIT_RETRIEVE.method, [], true ],
70 'citm' : [ api.FM_CITM_RETRIEVE.app, api.FM_CITM_RETRIEVE.method, [], true ],
72 'cst' : [ api.FM_CST_RETRIEVE.app, api.FM_CST_RETRIEVE.method, [], true ],
74 'acpl' : [ api.FM_ACPL_RETRIEVE.app, api.FM_ACPL_RETRIEVE.method, [], true ],
75 'ccs' : [ api.FM_CCS_RETRIEVE.app, api.FM_CCS_RETRIEVE.method, [], true ],
76 'aou' : [ api.FM_AOU_RETRIEVE.app, api.FM_AOU_RETRIEVE.method, [], true ],
77 'aout' : [ api.FM_AOUT_RETRIEVE.app, api.FM_AOUT_RETRIEVE.method, [], true ],
78 'crahp' : [ api.FM_CRAHP_RETRIEVE.app, api.FM_CRAHP_RETRIEVE.method, [], true ],
81 'stash_retrieve' : function() {
83 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
84 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
85 var data_cache=new OpenILS( );
86 var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
88 this.error.sdump('D_DATA_RETRIEVE','Retrieving ' + i + ' : ' + dc[i] + '\n');
91 if (typeof this.on_complete == 'function') {
96 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
100 'print_list_defaults' : function() {
102 //if (typeof obj.print_list_templates == 'undefined') {
104 obj.print_list_types = [
108 'offline_inhouse_use',
115 obj.print_list_templates = {
118 'header' : 'The following items have been examined:<hr/><ol>',
119 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode%\r\n',
120 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
124 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou have the following items:<hr/><ol>',
125 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
126 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
130 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou checked out the following items:<hr/><ol>',
131 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
132 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
134 'offline_checkout' : {
135 'type' : 'offline_checkout',
136 'header' : 'Patron %patron_barcode%<br/>\r\nYou checked out the following items:<hr/><ol>',
137 'line_item' : '<li>Barcode: %barcode%<br/>\r\nDue: %due_date%\r\n',
138 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
142 'header' : 'You checked in the following items:<hr/><ol>',
143 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Call Number: %call_number%\r\n',
144 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
148 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>A receipt of your transaction:<hr/> <table width="100%"> <tr> <td>Original Balance:</td> <td align="right">$%original_balance%</td> </tr> <tr> <td>Payment Method:</td> <td align="right">%payment_type%</td> </tr> <tr> <td>Payment Received:</td> <td align="right">$%payment_received%</td> </tr> <tr> <td>Payment Applied:</td> <td align="right">$%payment_applied%</td> </tr> <tr> <td>Change Given:</td> <td align="right">$%change_given%</td> </tr> <tr> <td>Credit Given:</td> <td align="right">$%credit_given%</td> </tr> <tr> <td>New Balance:</td> <td align="right">$%new_balance%</td> </tr> </table> <p> Note: %note% </p> <p> Specific bills: <blockquote>',
149 'line_item' : 'Bill #%bill_id% Received: $%payment%<br />',
150 'footer' : '</blockquote> </p> <hr />%PINES_CODE% %TODAY_TRIM%<br/> <br/> ',
152 'bills_historical' : {
154 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>You had the following bills:<hr/><ol>',
155 'line_item' : '<dt><b>Bill #%id%</b></dt> <dd> <table> <tr valign="top"><td>Date:</td><td>%xact_start%</td></tr> <tr valign="top"><td>Type:</td><td>%xact_type%</td></tr> <tr valign="top"><td>Last Billing:</td><td>%last_billing_type%<br/>%last_billing_note%</td></tr> <tr valign="top"><td>Total Billed:</td><td>$%total_owed%</td></tr> <tr valign="top"><td>Last Payment:</td><td>%last_payment_type%<br/>%last_payment_note%</td></tr> <tr valign="top"><td>Total Paid:</td><td>$%total_paid%</td></tr> <tr valign="top"><td><b>Balance:</b></td><td><b>$%balance_owed%</b></td></tr> </table><br/>',
156 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
160 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>You have the following bills:<hr/><ol>',
161 'line_item' : '<dt><b>Bill #%id%</b></dt> <dd> <table> <tr valign="top"><td>Date:</td><td>%xact_start%</td></tr> <tr valign="top"><td>Type:</td><td>%xact_type%</td></tr> <tr valign="top"><td>Last Billing:</td><td>%last_billing_type%<br/>%last_billing_note%</td></tr> <tr valign="top"><td>Total Billed:</td><td>$%total_owed%</td></tr> <tr valign="top"><td>Last Payment:</td><td>%last_payment_type%<br/>%last_payment_note%</td></tr> <tr valign="top"><td>Total Paid:</td><td>$%total_paid%</td></tr> <tr valign="top"><td><b>Balance:</b></td><td><b>$%balance_owed%</b></td></tr> </table><br/>',
162 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
164 'offline_checkin' : {
165 'type' : 'offline_checkin',
166 'header' : 'You checked in the following items:<hr/><ol>',
167 'line_item' : '<li>Barcode: %barcode%\r\n',
168 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
171 'type' : 'offline_renew',
172 'header' : 'You renewed the following items:<hr/><ol>',
173 'line_item' : '<li>Barcode: %barcode%\r\n',
174 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
176 'offline_inhouse_use' : {
177 'type' : 'offline_inhouse_use',
178 'header' : 'You marked the following in-house items used:<hr/><ol>',
179 'line_item' : '<li>Barcode: %barcode%\r\nUses: %count%',
180 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
184 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou have the following titles on hold:<hr/><ol>',
185 'line_item' : '<li>%title%\r\n',
186 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
190 obj.stash( 'print_list_templates', 'print_list_types' );
194 'network_retrieve' : function() {
195 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
199 JSAN.use('util.file'); var file = new util.file('print_list_templates');
200 obj.print_list_defaults();
201 if (file._file.exists()) {
203 var x = file.get_object();
206 obj.print_list_templates[i] = x[i];
208 obj.stash('print_list_templates');
216 JSAN.use('util.file');
217 JSAN.use('util.functional');
218 JSAN.use('util.fm_utils');
220 function gen_fm_retrieval_func(classname,data) {
221 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
223 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
226 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
228 if (obj.list[classname].constructor.name == 'Array') {
229 obj.hash[classname] =
230 util.functional.convert_object_list_to_hash(
236 obj.error.sdump('D_ERROR',E + '\n');
242 var level = obj.error.sdump_levels.D_SES_RESULT;
243 if (classname == 'aou' || classname == 'my_aou')
244 obj.error.sdump_levels.D_SES_RESULT = false;
245 var robj = obj.network.request( app, method, params);
246 if (!robj || robj.ilsevent) {
247 obj.error.standard_unexpected_error_alert('The staff client failed to retrieve expected data from this call, "' + method + '"',robj);
250 obj.list[classname] = robj;
251 obj.error.sdump_levels.D_SES_RESULT = level;
253 // if cacheable, store an offline copy
254 /* FIXME -- we're going to revisit caching and do it differently
256 var file = new util.file( classname );
257 file.set_object( obj.list[classname] );
262 // if cacheable, try offline
264 /* FIXME -- we're going to revisit caching and do it differently
266 var file = new util.file( classname );
267 obj.list[classname] = file.get_object(); file.close();
285 var f = gen_fm_retrieval_func(
288 api.FM_AU_RETRIEVE_VIA_SESSION.app,
289 api.FM_AU_RETRIEVE_VIA_SESSION.method,
297 var error = 'Error: ' + js2JSON(E);
298 obj.error.sdump('D_ERROR',error);
301 obj.list.au = [ obj.list.au ];
307 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
308 var f = gen_fm_retrieval_func(
311 api.FM_ASV_RETRIEVE_REQUIRED.app,
312 api.FM_ASV_RETRIEVE_REQUIRED.method,
318 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
321 var error = 'Error: ' + js2JSON(E);
322 obj.error.sdump('D_ERROR',error);
330 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
331 var f = gen_fm_retrieval_func(
334 api.FM_ASV_RETRIEVE.app,
335 api.FM_ASV_RETRIEVE.method,
341 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
344 var error = 'Error: ' + js2JSON(E);
345 obj.error.sdump('D_ERROR',error);
351 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
353 for (var i in this._fm_objects) {
354 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
357 // The previous org_tree call returned a tree, not a list or hash.
360 obj.tree.aou = obj.list.aou;
361 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
362 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
366 // Do this after we get the user object
371 gen_fm_retrieval_func('my_aou',
373 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
374 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
375 [ obj.session.key, obj.list.au[0].ws_ou() ], /* use ws_ou and not home_ou */
386 gen_fm_retrieval_func( 'my_actsc',
388 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
389 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
390 [ obj.session.key, obj.list.au[0].ws_ou() ],
401 gen_fm_retrieval_func( 'my_asc',
403 api.FM_ASC_RETRIEVE_VIA_AOU.app,
404 api.FM_ASC_RETRIEVE_VIA_AOU.method,
405 [ obj.session.key, obj.list.au[0].ws_ou() ],
415 var f = gen_fm_retrieval_func(
418 api.FM_CNCT_RETRIEVE.app,
419 api.FM_CNCT_RETRIEVE.method,
420 [ obj.list.au[0].ws_ou() ],
427 var error = 'Error: ' + js2JSON(E);
428 obj.error.sdump('D_ERROR',error);
435 if (typeof this.on_complete == 'function') {
437 this.chain.push( this.on_complete );
439 JSAN.use('util.exec'); this.exec = new util.exec();
440 this.exec.on_error = function(E) {
442 if (typeof obj.on_error == 'function') {
445 alert('oops: ' + E );
448 return false; /* break chain */
451 this.exec.chain( this.chain );
456 dump('exiting OpenILS/data.js\n');