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 'lookup' : function(key,value) {
55 var obj = this; var found;
56 if (obj.hash[key] && obj.hash[key][value]) return obj.hash[key][value];
59 found = obj.network.simple_request('FM_ACPL_RETRIEVE_VIA_ID',[ value ]);
61 default: return undefined; break;
63 if (typeof found.ilsevent != 'undefined') throw(found);
64 if (!obj.hash[key]) obj.hash[key] = {};
65 obj.hash[key][value] = found; obj.list[key].push( found ); obj.stash('hash','list');
68 this.error.sdump('D_ERROR','Error in OpenILS.data.lookup('+key+','+value+'): ' + js2JSON(E) );
73 '_debug_stash' : function() {
75 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
76 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
77 var data_cache=new OpenILS( );
78 for (var i in data_cache.wrappedJSObject.OpenILS.prototype.data) {
79 dump('_debug_stash ' + i + '\n');
82 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
88 'pgt' : [ api.FM_PGT_RETRIEVE.app, api.FM_PGT_RETRIEVE.method, [], true ],
89 'cit' : [ api.FM_CIT_RETRIEVE.app, api.FM_CIT_RETRIEVE.method, [], true ],
90 'citm' : [ api.FM_CITM_RETRIEVE.app, api.FM_CITM_RETRIEVE.method, [], true ],
92 'cst' : [ api.FM_CST_RETRIEVE.app, api.FM_CST_RETRIEVE.method, [], true ],
95 'acpl' : [ api.FM_ACPL_RETRIEVE.app, api.FM_ACPL_RETRIEVE.method, [], true ],
97 'ccs' : [ api.FM_CCS_RETRIEVE.app, api.FM_CCS_RETRIEVE.method, [], true ],
98 'aou' : [ api.FM_AOU_RETRIEVE.app, api.FM_AOU_RETRIEVE.method, [], true ],
99 'aout' : [ api.FM_AOUT_RETRIEVE.app, api.FM_AOUT_RETRIEVE.method, [], true ],
100 'crahp' : [ api.FM_CRAHP_RETRIEVE.app, api.FM_CRAHP_RETRIEVE.method, [], true ],
103 'stash_retrieve' : function() {
105 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
106 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
107 var data_cache=new OpenILS( );
108 var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
110 this.error.sdump('D_DATA_RETRIEVE','Retrieving ' + i + ' : ' + dc[i] + '\n');
113 if (typeof this.on_complete == 'function') {
118 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
122 'print_list_defaults' : function() {
124 //if (typeof obj.print_list_templates == 'undefined') {
126 obj.print_list_types = [
130 'offline_inhouse_use',
137 obj.print_list_templates = {
140 'header' : 'The following items have been examined:<hr/><ol>',
141 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode%\r\n',
142 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
146 'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou have the following items:<hr/><ol>',
147 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
148 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME%<br/>\r\n<br/>\r\n',
152 'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou checked out the following items:<hr/><ol>',
153 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
154 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME%<br/>\r\n<br/>\r\n',
156 'offline_checkout' : {
157 'type' : 'offline_checkout',
158 'header' : 'Patron %patron_barcode%<br/>\r\nYou checked out the following items:<hr/><ol>',
159 'line_item' : '<li>Barcode: %barcode%<br/>\r\nDue: %due_date%\r\n',
160 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
164 'header' : 'You checked in the following items:<hr/><ol>',
165 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Call Number: %call_number%\r\n',
166 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
170 'header' : 'Welcome 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>Billings Voided:</td> <td align="right">%voided_balance%</td> </tr> <tr> <td>Change Given:</td> <td align="right">$%change_given%</td> </tr> <tr> <td>New Balance:</td> <td align="right">$%new_balance%</td> </tr> </table> <p> Note: %note% </p> <p> Specific bills: <blockquote>',
171 'line_item' : 'Bill #%bill_id% %last_billing_type% Received: $%payment%<br />%barcode% %title%<br /><br />',
172 'footer' : '</blockquote> </p> <hr />%PINES_CODE% %TODAY_TRIM%<br/> <br/> ',
174 'bills_historical' : {
176 'header' : 'Welcome to %LIBRARY%!<br/>You had the following bills:<hr/><ol>',
177 '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/>',
178 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
182 'header' : 'Welcome to %LIBRARY%!<br/>You have the following bills:<hr/><ol>',
183 '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/>',
184 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
186 'offline_checkin' : {
187 'type' : 'offline_checkin',
188 'header' : 'You checked in the following items:<hr/><ol>',
189 'line_item' : '<li>Barcode: %barcode%\r\n',
190 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
193 'type' : 'offline_renew',
194 'header' : 'You renewed the following items:<hr/><ol>',
195 'line_item' : '<li>Barcode: %barcode%\r\n',
196 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
198 'offline_inhouse_use' : {
199 'type' : 'offline_inhouse_use',
200 'header' : 'You marked the following in-house items used:<hr/><ol>',
201 'line_item' : '<li>Barcode: %barcode%\r\nUses: %count%',
202 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
206 'header' : 'You marked the following in-house items used:<hr/><ol>',
207 'line_item' : '<li>Barcode: %barcode%\r\nUses: %uses%\r\n<br />%alert_message%',
208 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
212 'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou have the following titles on hold:<hr/><ol>',
213 'line_item' : '<li>%title%\r\n',
214 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME%<br/>\r\n<br/>\r\n',
218 obj.stash( 'print_list_templates', 'print_list_types' );
222 'network_retrieve' : function() {
223 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
227 JSAN.use('util.file'); var file = new util.file('print_list_templates');
228 obj.print_list_defaults();
229 if (file._file.exists()) {
231 var x = file.get_object();
234 obj.print_list_templates[i] = x[i];
236 obj.stash('print_list_templates');
244 JSAN.use('util.file'); var file = new util.file('global_font_adjust');
245 if (file._file.exists()) {
247 var x = file.get_object();
249 obj.global_font_adjust = x;
250 obj.stash('global_font_adjust');
258 JSAN.use('util.functional');
259 JSAN.use('util.fm_utils');
261 function gen_fm_retrieval_func(classname,data) {
262 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
264 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
267 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
269 if (obj.list[classname].constructor.name == 'Array') {
270 obj.hash[classname] =
271 util.functional.convert_object_list_to_hash(
277 obj.error.sdump('D_ERROR',E + '\n');
283 var level = obj.error.sdump_levels.D_SES_RESULT;
284 if (classname == 'aou' || classname == 'my_aou')
285 obj.error.sdump_levels.D_SES_RESULT = false;
286 var robj = obj.network.request( app, method, params);
287 if (!robj || robj.ilsevent) {
288 obj.error.standard_unexpected_error_alert('The staff client failed to retrieve expected data from this call, "' + method + '"',robj);
291 obj.list[classname] = robj;
292 obj.error.sdump_levels.D_SES_RESULT = level;
294 // if cacheable, store an offline copy
295 /* FIXME -- we're going to revisit caching and do it differently
297 var file = new util.file( classname );
298 file.set_object( obj.list[classname] );
303 // if cacheable, try offline
305 /* FIXME -- we're going to revisit caching and do it differently
307 var file = new util.file( classname );
308 obj.list[classname] = file.get_object(); file.close();
327 var robj = obj.network.simple_request('CIRC_MODIFIER_LIST',[]);
328 if (typeof robj.ilsevent != 'undefined') throw(robj);
329 obj.list.circ_modifier = robj;
331 var error = 'Error: ' + js2JSON(E);
332 obj.error.sdump('D_ERROR',error);
341 var robj = obj.network.simple_request('BILLING_TYPE_LIST',[]);
342 if (typeof robj.ilsevent != 'undefined') throw(robj);
343 obj.list.billing_type = robj;
345 var error = 'Error: ' + js2JSON(E);
346 obj.error.sdump('D_ERROR',error);
355 var f = gen_fm_retrieval_func(
358 api.FM_CNAL_RETRIEVE.app,
359 api.FM_CNAL_RETRIEVE.method,
367 var error = 'Error: ' + js2JSON(E);
368 obj.error.sdump('D_ERROR',error);
376 var f = gen_fm_retrieval_func(
379 api.FM_AU_RETRIEVE_VIA_SESSION.app,
380 api.FM_AU_RETRIEVE_VIA_SESSION.method,
388 var error = 'Error: ' + js2JSON(E);
389 obj.error.sdump('D_ERROR',error);
392 obj.list.au = [ obj.list.au ];
398 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
399 var f = gen_fm_retrieval_func(
402 api.FM_ASV_RETRIEVE_REQUIRED.app,
403 api.FM_ASV_RETRIEVE_REQUIRED.method,
409 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
412 var error = 'Error: ' + js2JSON(E);
413 obj.error.sdump('D_ERROR',error);
421 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
422 var f = gen_fm_retrieval_func(
425 api.FM_ASV_RETRIEVE.app,
426 api.FM_ASV_RETRIEVE.method,
432 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
435 var error = 'Error: ' + js2JSON(E);
436 obj.error.sdump('D_ERROR',error);
442 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
444 for (var i in this._fm_objects) {
445 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
448 // The previous org_tree call returned a tree, not a list or hash.
451 obj.tree.aou = obj.list.aou;
452 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
453 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
457 // The previous pgt call returned a tree, not a list or hash.
460 obj.tree.pgt = obj.list.pgt;
461 obj.list.pgt = util.fm_utils.flatten_ou_branch( obj.tree.pgt );
462 obj.hash.pgt = util.functional.convert_object_list_to_hash( obj.list.pgt );
466 // Do this after we get the user object
471 gen_fm_retrieval_func('my_aou',
473 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
474 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
475 [ obj.session.key, obj.list.au[0].ws_ou() ], /* use ws_ou and not home_ou */
486 gen_fm_retrieval_func( 'my_actsc',
488 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
489 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
490 [ obj.session.key, obj.list.au[0].ws_ou() ],
501 gen_fm_retrieval_func( 'my_asc',
503 api.FM_ASC_RETRIEVE_VIA_AOU.app,
504 api.FM_ASC_RETRIEVE_VIA_AOU.method,
505 [ obj.session.key, obj.list.au[0].ws_ou() ],
515 var f = gen_fm_retrieval_func(
518 api.FM_CNCT_RETRIEVE.app,
519 api.FM_CNCT_RETRIEVE.method,
520 [ obj.list.au[0].ws_ou() ],
527 var error = 'Error: ' + js2JSON(E);
528 obj.error.sdump('D_ERROR',error);
536 var f = gen_fm_retrieval_func(
539 api.FM_ACPL_RETRIEVE.app,
540 api.FM_ACPL_RETRIEVE.method,
541 [ obj.list.au[0].ws_ou() ],
548 var error = 'Error: ' + js2JSON(E);
549 obj.error.sdump('D_ERROR',error);
557 if (typeof this.on_complete == 'function') {
559 this.chain.push( this.on_complete );
561 JSAN.use('util.exec'); this.exec = new util.exec();
562 this.exec.on_error = function(E) {
564 if (typeof obj.on_error == 'function') {
567 alert('oops: ' + E );
570 return false; /* break chain */
573 this.exec.chain( this.chain );
578 dump('exiting OpenILS/data.js\n');