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 ],
75 'acpl' : [ api.FM_ACPL_RETRIEVE.app, api.FM_ACPL_RETRIEVE.method, [], true ],
77 'ccs' : [ api.FM_CCS_RETRIEVE.app, api.FM_CCS_RETRIEVE.method, [], true ],
78 'aou' : [ api.FM_AOU_RETRIEVE.app, api.FM_AOU_RETRIEVE.method, [], true ],
79 'aout' : [ api.FM_AOUT_RETRIEVE.app, api.FM_AOUT_RETRIEVE.method, [], true ],
80 'crahp' : [ api.FM_CRAHP_RETRIEVE.app, api.FM_CRAHP_RETRIEVE.method, [], true ],
83 'stash_retrieve' : function() {
85 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
86 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
87 var data_cache=new OpenILS( );
88 var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
90 this.error.sdump('D_DATA_RETRIEVE','Retrieving ' + i + ' : ' + dc[i] + '\n');
93 if (typeof this.on_complete == 'function') {
98 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
102 'print_list_defaults' : function() {
104 //if (typeof obj.print_list_templates == 'undefined') {
106 obj.print_list_types = [
110 'offline_inhouse_use',
117 obj.print_list_templates = {
120 'header' : 'The following items have been examined:<hr/><ol>',
121 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode%\r\n',
122 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
126 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou have the following items:<hr/><ol>',
127 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
128 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
132 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou checked out the following items:<hr/><ol>',
133 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
134 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
136 'offline_checkout' : {
137 'type' : 'offline_checkout',
138 'header' : 'Patron %patron_barcode%<br/>\r\nYou checked out the following items:<hr/><ol>',
139 'line_item' : '<li>Barcode: %barcode%<br/>\r\nDue: %due_date%\r\n',
140 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
144 'header' : 'You checked in the following items:<hr/><ol>',
145 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Call Number: %call_number%\r\n',
146 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
150 '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>',
151 'line_item' : 'Bill #%bill_id% Received: $%payment%<br />',
152 'footer' : '</blockquote> </p> <hr />%PINES_CODE% %TODAY_TRIM%<br/> <br/> ',
154 'bills_historical' : {
156 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>You had the following bills:<hr/><ol>',
157 '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/>',
158 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
162 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>You have the following bills:<hr/><ol>',
163 '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/>',
164 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
166 'offline_checkin' : {
167 'type' : 'offline_checkin',
168 'header' : 'You checked in the following items:<hr/><ol>',
169 'line_item' : '<li>Barcode: %barcode%\r\n',
170 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
173 'type' : 'offline_renew',
174 'header' : 'You renewed the following items:<hr/><ol>',
175 'line_item' : '<li>Barcode: %barcode%\r\n',
176 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
178 'offline_inhouse_use' : {
179 'type' : 'offline_inhouse_use',
180 'header' : 'You marked the following in-house items used:<hr/><ol>',
181 'line_item' : '<li>Barcode: %barcode%\r\nUses: %count%',
182 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
186 'header' : 'You marked the following in-house items used:<hr/><ol>',
187 'line_item' : '<li>Barcode: %barcode%\r\nUses: %uses%\r\n<br />%alert_message%',
188 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
192 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!<br/>\r\nYou have the following titles on hold:<hr/><ol>',
193 'line_item' : '<li>%title%\r\n',
194 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%<br/>\r\n<br/>\r\n',
198 obj.stash( 'print_list_templates', 'print_list_types' );
202 'network_retrieve' : function() {
203 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
207 JSAN.use('util.file'); var file = new util.file('print_list_templates');
208 obj.print_list_defaults();
209 if (file._file.exists()) {
211 var x = file.get_object();
214 obj.print_list_templates[i] = x[i];
216 obj.stash('print_list_templates');
224 JSAN.use('util.file');
225 JSAN.use('util.functional');
226 JSAN.use('util.fm_utils');
228 function gen_fm_retrieval_func(classname,data) {
229 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
231 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
234 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
236 if (obj.list[classname].constructor.name == 'Array') {
237 obj.hash[classname] =
238 util.functional.convert_object_list_to_hash(
244 obj.error.sdump('D_ERROR',E + '\n');
250 var level = obj.error.sdump_levels.D_SES_RESULT;
251 if (classname == 'aou' || classname == 'my_aou')
252 obj.error.sdump_levels.D_SES_RESULT = false;
253 var robj = obj.network.request( app, method, params);
254 if (!robj || robj.ilsevent) {
255 obj.error.standard_unexpected_error_alert('The staff client failed to retrieve expected data from this call, "' + method + '"',robj);
258 obj.list[classname] = robj;
259 obj.error.sdump_levels.D_SES_RESULT = level;
261 // if cacheable, store an offline copy
262 /* FIXME -- we're going to revisit caching and do it differently
264 var file = new util.file( classname );
265 file.set_object( obj.list[classname] );
270 // if cacheable, try offline
272 /* FIXME -- we're going to revisit caching and do it differently
274 var file = new util.file( classname );
275 obj.list[classname] = file.get_object(); file.close();
293 var f = gen_fm_retrieval_func(
296 api.FM_CNAL_RETRIEVE.app,
297 api.FM_CNAL_RETRIEVE.method,
305 var error = 'Error: ' + js2JSON(E);
306 obj.error.sdump('D_ERROR',error);
314 var f = gen_fm_retrieval_func(
317 api.FM_AU_RETRIEVE_VIA_SESSION.app,
318 api.FM_AU_RETRIEVE_VIA_SESSION.method,
326 var error = 'Error: ' + js2JSON(E);
327 obj.error.sdump('D_ERROR',error);
330 obj.list.au = [ obj.list.au ];
336 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
337 var f = gen_fm_retrieval_func(
340 api.FM_ASV_RETRIEVE_REQUIRED.app,
341 api.FM_ASV_RETRIEVE_REQUIRED.method,
347 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
350 var error = 'Error: ' + js2JSON(E);
351 obj.error.sdump('D_ERROR',error);
359 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
360 var f = gen_fm_retrieval_func(
363 api.FM_ASV_RETRIEVE.app,
364 api.FM_ASV_RETRIEVE.method,
370 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
373 var error = 'Error: ' + js2JSON(E);
374 obj.error.sdump('D_ERROR',error);
380 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
382 for (var i in this._fm_objects) {
383 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
386 // The previous org_tree call returned a tree, not a list or hash.
389 obj.tree.aou = obj.list.aou;
390 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
391 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
395 // The previous pgt call returned a tree, not a list or hash.
398 obj.tree.pgt = obj.list.pgt;
399 obj.list.pgt = util.fm_utils.flatten_ou_branch( obj.tree.pgt );
400 obj.hash.pgt = util.functional.convert_object_list_to_hash( obj.list.pgt );
404 // Do this after we get the user object
409 gen_fm_retrieval_func('my_aou',
411 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
412 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
413 [ obj.session.key, obj.list.au[0].ws_ou() ], /* use ws_ou and not home_ou */
424 gen_fm_retrieval_func( 'my_actsc',
426 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
427 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
428 [ obj.session.key, obj.list.au[0].ws_ou() ],
439 gen_fm_retrieval_func( 'my_asc',
441 api.FM_ASC_RETRIEVE_VIA_AOU.app,
442 api.FM_ASC_RETRIEVE_VIA_AOU.method,
443 [ obj.session.key, obj.list.au[0].ws_ou() ],
453 var f = gen_fm_retrieval_func(
456 api.FM_CNCT_RETRIEVE.app,
457 api.FM_CNCT_RETRIEVE.method,
458 [ obj.list.au[0].ws_ou() ],
465 var error = 'Error: ' + js2JSON(E);
466 obj.error.sdump('D_ERROR',error);
474 var f = gen_fm_retrieval_func(
477 api.FM_ACPL_RETRIEVE.app,
478 api.FM_ACPL_RETRIEVE.method,
479 [ obj.list.au[0].ws_ou() ],
486 var error = 'Error: ' + js2JSON(E);
487 obj.error.sdump('D_ERROR',error);
495 if (typeof this.on_complete == 'function') {
497 this.chain.push( this.on_complete );
499 JSAN.use('util.exec'); this.exec = new util.exec();
500 this.exec.on_error = function(E) {
502 if (typeof obj.on_error == 'function') {
505 alert('oops: ' + E );
508 return false; /* break chain */
511 this.exec.chain( this.chain );
516 dump('exiting OpenILS/data.js\n');