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 ]
78 'stash_retrieve' : function() {
80 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
81 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
82 var data_cache=new OpenILS( );
83 var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
85 this.error.sdump('D_DATA','Retrieving ' + i + ' : ' + dc[i] + '\n');
88 if (typeof this.on_complete == 'function') {
93 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
97 'print_list_defaults' : function() {
99 //if (typeof obj.print_list_templates == 'undefined') {
101 obj.print_list_types = [
105 'offline_inhouse_use',
112 obj.print_list_templates = {
115 'header' : 'The following items have been examined:<hr/><ol>',
116 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode%\r\n',
117 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
121 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou have the following items:<hr/><ol>',
122 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
123 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
127 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou checked out the following items:<hr/><ol>',
128 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
129 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
131 'offline_checkout' : {
132 'type' : 'offline_checkout',
133 'header' : 'Patron %patron_barcode%<br/>\r\nYou checked out the following items:<hr/><ol>',
134 'line_item' : '<li>Barcode: %barcode%<br/>\r\nDue: %due_date%\r\n',
135 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
139 'header' : 'You checked in the following items:<hr/><ol>',
140 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Call Number: %call_number%\r\n',
141 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
145 '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>',
146 'line_item' : 'Bill #%bill_id% Received: $%payment%<br />',
147 'footer' : '</blockquote> </p> <hr />%PINES_CODE% %TODAY_TRIM%<br/> <br/> ',
149 'bills_historical' : {
151 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>You had the following bills:<hr/><ol>',
152 '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/>',
153 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
157 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>You have the following bills:<hr/><ol>',
158 '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/>',
159 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
161 'offline_checkin' : {
162 'type' : 'offline_checkin',
163 'header' : 'You checked in the following items:<hr/><ol>',
164 'line_item' : '<li>Barcode: %barcode%\r\n',
165 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
168 'type' : 'offline_renew',
169 'header' : 'You renewed the following items:<hr/><ol>',
170 'line_item' : '<li>Barcode: %barcode%\r\n',
171 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
173 'offline_inhouse_use' : {
174 'type' : 'offline_inhouse_use',
175 'header' : 'You marked the following in-house items used:<hr/><ol>',
176 'line_item' : '<li>Barcode: %barcode%\r\nUses: %count%',
177 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
181 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou have the following titles on hold:<hr/><ol>',
182 'line_item' : '<li>%title%\r\n',
183 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
187 obj.stash( 'print_list_templates', 'print_list_types' );
191 'network_retrieve' : function() {
192 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
196 JSAN.use('util.file'); var file = new util.file('print_list_templates');
197 obj.print_list_defaults();
198 if (file._file.exists()) {
200 var x = file.get_object();
203 obj.print_list_templates[i] = x[i];
205 obj.stash('print_list_templates');
213 JSAN.use('util.file');
214 JSAN.use('util.functional');
215 JSAN.use('util.fm_utils');
217 function gen_fm_retrieval_func(classname,data) {
218 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
220 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
223 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
225 if (obj.list[classname].constructor.name == 'Array') {
226 obj.hash[classname] =
227 util.functional.convert_object_list_to_hash(
233 obj.error.sdump('D_ERROR',E + '\n');
239 var level = obj.error.sdump_levels.D_SES_RESULT;
240 if (classname == 'aou' || classname == 'my_aou')
241 obj.error.sdump_levels.D_SES_RESULT = false;
242 var robj = obj.network.request( app, method, params);
243 if (!robj || robj.ilsevent) {
244 obj.error.standard_unexpected_error_alert('The staff client failed to retrieve expected data from this call, "' + method + '"',robj);
247 obj.list[classname] = robj;
248 obj.error.sdump_levels.D_SES_RESULT = level;
250 // if cacheable, store an offline copy
251 /* FIXME -- we're going to revisit caching and do it differently
253 var file = new util.file( classname );
254 file.set_object( obj.list[classname] );
259 // if cacheable, try offline
261 /* FIXME -- we're going to revisit caching and do it differently
263 var file = new util.file( classname );
264 obj.list[classname] = file.get_object(); file.close();
282 var f = gen_fm_retrieval_func(
285 api.FM_AU_RETRIEVE_VIA_SESSION.app,
286 api.FM_AU_RETRIEVE_VIA_SESSION.method,
294 var error = 'Error: ' + js2JSON(E);
295 obj.error.sdump('D_ERROR',error);
298 obj.list.au = [ obj.list.au ];
304 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
305 var f = gen_fm_retrieval_func(
308 api.FM_ASV_RETRIEVE_REQUIRED.app,
309 api.FM_ASV_RETRIEVE_REQUIRED.method,
315 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
318 var error = 'Error: ' + js2JSON(E);
319 obj.error.sdump('D_ERROR',error);
327 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
328 var f = gen_fm_retrieval_func(
331 api.FM_ASV_RETRIEVE.app,
332 api.FM_ASV_RETRIEVE.method,
338 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
341 var error = 'Error: ' + js2JSON(E);
342 obj.error.sdump('D_ERROR',error);
348 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
350 for (var i in this._fm_objects) {
351 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
354 // The previous org_tree call returned a tree, not a list or hash.
357 obj.tree.aou = obj.list.aou;
358 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
359 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
363 // Do this after we get the user object
368 gen_fm_retrieval_func('my_aou',
370 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
371 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
372 [ obj.session.key, obj.list.au[0].ws_ou() ], /* use ws_ou and not home_ou */
383 gen_fm_retrieval_func( 'my_actsc',
385 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
386 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
387 [ obj.session.key, obj.list.au[0].ws_ou() ],
398 gen_fm_retrieval_func( 'my_asc',
400 api.FM_ASC_RETRIEVE_VIA_AOU.app,
401 api.FM_ASC_RETRIEVE_VIA_AOU.method,
402 [ obj.session.key, obj.list.au[0].ws_ou() ],
412 var f = gen_fm_retrieval_func(
415 api.FM_CNCT_RETRIEVE.app,
416 api.FM_CNCT_RETRIEVE.method,
417 [ obj.list.au[0].ws_ou() ],
424 var error = 'Error: ' + js2JSON(E);
425 obj.error.sdump('D_ERROR',error);
432 if (typeof this.on_complete == 'function') {
434 this.chain.push( this.on_complete );
436 JSAN.use('util.exec'); this.exec = new util.exec();
437 this.exec.on_error = function(E) {
439 if (typeof obj.on_error == 'function') {
442 alert('oops: ' + E );
445 return false; /* break chain */
448 this.exec.chain( this.chain );
453 dump('exiting OpenILS/data.js\n');