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 'citm' : [ api.FM_CITM_RETRIEVE.app, api.FM_CITM_RETRIEVE.method, [], true ],
70 'cst' : [ api.FM_CST_RETRIEVE.app, api.FM_CST_RETRIEVE.method, [], true ],
72 'acpl' : [ api.FM_ACPL_RETRIEVE.app, api.FM_ACPL_RETRIEVE.method, [], true ],
73 'ccs' : [ api.FM_CCS_RETRIEVE.app, api.FM_CCS_RETRIEVE.method, [], true ],
74 'aou' : [ api.FM_AOU_RETRIEVE.app, api.FM_AOU_RETRIEVE.method, [], true ],
75 'aout' : [ api.FM_AOUT_RETRIEVE.app, api.FM_AOUT_RETRIEVE.method, [], true ],
76 'crahp' : [ api.FM_CRAHP_RETRIEVE.app, api.FM_CRAHP_RETRIEVE.method, [], true ],
79 'stash_retrieve' : function() {
81 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
82 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
83 var data_cache=new OpenILS( );
84 var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
86 this.error.sdump('D_DATA','Retrieving ' + i + ' : ' + dc[i] + '\n');
89 if (typeof this.on_complete == 'function') {
94 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
98 'print_list_defaults' : function() {
100 //if (typeof obj.print_list_templates == 'undefined') {
102 obj.print_list_types = [
106 'offline_inhouse_use',
113 obj.print_list_templates = {
116 'header' : 'The following items have been examined:<hr/><ol>',
117 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode%\r\n',
118 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
122 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou have the following items:<hr/><ol>',
123 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
124 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
128 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou checked out the following items:<hr/><ol>',
129 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
130 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
132 'offline_checkout' : {
133 'type' : 'offline_checkout',
134 'header' : 'Patron %patron_barcode%<br/>\r\nYou checked out the following items:<hr/><ol>',
135 'line_item' : '<li>Barcode: %barcode%<br/>\r\nDue: %due_date%\r\n',
136 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
140 'header' : 'You checked in the following items:<hr/><ol>',
141 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Call Number: %call_number%\r\n',
142 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
146 '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>',
147 'line_item' : 'Bill #%bill_id% Received: $%payment%<br />',
148 'footer' : '</blockquote> </p> <hr />%PINES_CODE% %TODAY_TRIM%<br/> <br/> ',
150 'bills_historical' : {
152 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>You had the following bills:<hr/><ol>',
153 '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/>',
154 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
158 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>You have the following bills:<hr/><ol>',
159 '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/>',
160 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
162 'offline_checkin' : {
163 'type' : 'offline_checkin',
164 'header' : 'You checked in the following items:<hr/><ol>',
165 'line_item' : '<li>Barcode: %barcode%\r\n',
166 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
169 'type' : 'offline_renew',
170 'header' : 'You renewed the following items:<hr/><ol>',
171 'line_item' : '<li>Barcode: %barcode%\r\n',
172 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
174 'offline_inhouse_use' : {
175 'type' : 'offline_inhouse_use',
176 'header' : 'You marked the following in-house items used:<hr/><ol>',
177 'line_item' : '<li>Barcode: %barcode%\r\nUses: %count%',
178 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
182 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou have the following titles on hold:<hr/><ol>',
183 'line_item' : '<li>%title%\r\n',
184 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
188 obj.stash( 'print_list_templates', 'print_list_types' );
192 'network_retrieve' : function() {
193 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
197 JSAN.use('util.file'); var file = new util.file('print_list_templates');
198 obj.print_list_defaults();
199 if (file._file.exists()) {
201 var x = file.get_object();
204 obj.print_list_templates[i] = x[i];
206 obj.stash('print_list_templates');
214 JSAN.use('util.file');
215 JSAN.use('util.functional');
216 JSAN.use('util.fm_utils');
218 function gen_fm_retrieval_func(classname,data) {
219 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
221 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
224 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
226 if (obj.list[classname].constructor.name == 'Array') {
227 obj.hash[classname] =
228 util.functional.convert_object_list_to_hash(
234 obj.error.sdump('D_ERROR',E + '\n');
240 var level = obj.error.sdump_levels.D_SES_RESULT;
241 if (classname == 'aou' || classname == 'my_aou')
242 obj.error.sdump_levels.D_SES_RESULT = false;
243 var robj = obj.network.request( app, method, params);
244 if (!robj || robj.ilsevent) {
245 obj.error.standard_unexpected_error_alert('The staff client failed to retrieve expected data from this call, "' + method + '"',robj);
248 obj.list[classname] = robj;
249 obj.error.sdump_levels.D_SES_RESULT = level;
251 // if cacheable, store an offline copy
252 /* FIXME -- we're going to revisit caching and do it differently
254 var file = new util.file( classname );
255 file.set_object( obj.list[classname] );
260 // if cacheable, try offline
262 /* FIXME -- we're going to revisit caching and do it differently
264 var file = new util.file( classname );
265 obj.list[classname] = file.get_object(); file.close();
283 var f = gen_fm_retrieval_func(
286 api.FM_AU_RETRIEVE_VIA_SESSION.app,
287 api.FM_AU_RETRIEVE_VIA_SESSION.method,
295 var error = 'Error: ' + js2JSON(E);
296 obj.error.sdump('D_ERROR',error);
299 obj.list.au = [ obj.list.au ];
305 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
306 var f = gen_fm_retrieval_func(
309 api.FM_ASV_RETRIEVE_REQUIRED.app,
310 api.FM_ASV_RETRIEVE_REQUIRED.method,
316 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
319 var error = 'Error: ' + js2JSON(E);
320 obj.error.sdump('D_ERROR',error);
328 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
329 var f = gen_fm_retrieval_func(
332 api.FM_ASV_RETRIEVE.app,
333 api.FM_ASV_RETRIEVE.method,
339 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
342 var error = 'Error: ' + js2JSON(E);
343 obj.error.sdump('D_ERROR',error);
349 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
351 for (var i in this._fm_objects) {
352 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
355 // The previous org_tree call returned a tree, not a list or hash.
358 obj.tree.aou = obj.list.aou;
359 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
360 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
364 // Do this after we get the user object
369 gen_fm_retrieval_func('my_aou',
371 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
372 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
373 [ obj.session.key, obj.list.au[0].ws_ou() ], /* use ws_ou and not home_ou */
384 gen_fm_retrieval_func( 'my_actsc',
386 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
387 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
388 [ obj.session.key, obj.list.au[0].ws_ou() ],
399 gen_fm_retrieval_func( 'my_asc',
401 api.FM_ASC_RETRIEVE_VIA_AOU.app,
402 api.FM_ASC_RETRIEVE_VIA_AOU.method,
403 [ obj.session.key, obj.list.au[0].ws_ou() ],
413 var f = gen_fm_retrieval_func(
416 api.FM_CNCT_RETRIEVE.app,
417 api.FM_CNCT_RETRIEVE.method,
418 [ obj.list.au[0].ws_ou() ],
425 var error = 'Error: ' + js2JSON(E);
426 obj.error.sdump('D_ERROR',error);
433 if (typeof this.on_complete == 'function') {
435 this.chain.push( this.on_complete );
437 JSAN.use('util.exec'); this.exec = new util.exec();
438 this.exec.on_error = function(E) {
440 if (typeof obj.on_error == 'function') {
443 alert('oops: ' + E );
446 return false; /* break chain */
449 this.exec.chain( this.chain );
454 dump('exiting OpenILS/data.js\n');