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 'data_progress' : function(msg) {
22 var x = document.getElementById('data_progress');
24 x.appendChild( document.createTextNode( msg ) );
27 this.error.sdump('D_ERROR',msg + '\n' + E);
31 'init' : function (params) {
34 if (params && params.via == 'stash') {
35 this.stash_retrieve();
37 this.network_retrieve();
41 this.error.sdump('D_ERROR','Error in OpenILS.data.init('
42 +js2JSON(params)+'): ' + js2JSON(E) );
48 'stash' : function () {
50 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
51 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
52 var data_cache=new OpenILS( );
53 for (var i = 0; i < arguments.length; i++) {
55 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');
56 } catch(F) { alert(F); }
57 data_cache.wrappedJSObject.OpenILS.prototype.data[arguments[i]] = this[arguments[i]];
60 this.error.sdump('D_ERROR','Error in OpenILS.data.stash(): ' + js2JSON(E) );
64 'lookup' : function(key,value) {
66 var obj = this; var found;
67 if (obj.hash[key] && obj.hash[key][value]) return obj.hash[key][value];
70 found = obj.network.simple_request('FM_ACPL_RETRIEVE_VIA_ID',[ value ]);
72 default: return undefined; break;
74 if (typeof found.ilsevent != 'undefined') throw(found);
75 if (!obj.hash[key]) obj.hash[key] = {};
76 obj.hash[key][value] = found; obj.list[key].push( found ); obj.stash('hash','list');
79 this.error.sdump('D_ERROR','Error in OpenILS.data.lookup('+key+','+value+'): ' + js2JSON(E) );
84 '_debug_stash' : function() {
86 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
87 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
88 var data_cache=new OpenILS( );
89 for (var i in data_cache.wrappedJSObject.OpenILS.prototype.data) {
90 dump('_debug_stash ' + i + '\n');
93 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
99 'pgt' : [ api.FM_PGT_RETRIEVE.app, api.FM_PGT_RETRIEVE.method, [], true ],
100 'cit' : [ api.FM_CIT_RETRIEVE.app, api.FM_CIT_RETRIEVE.method, [], true ],
101 'citm' : [ api.FM_CITM_RETRIEVE.app, api.FM_CITM_RETRIEVE.method, [], true ],
103 'cst' : [ api.FM_CST_RETRIEVE.app, api.FM_CST_RETRIEVE.method, [], true ],
106 'acpl' : [ api.FM_ACPL_RETRIEVE.app, api.FM_ACPL_RETRIEVE.method, [], true ],
108 'ccs' : [ api.FM_CCS_RETRIEVE.app, api.FM_CCS_RETRIEVE.method, [], true ],
109 'aou' : [ api.FM_AOU_RETRIEVE.app, api.FM_AOU_RETRIEVE.method, [], true ],
110 'aout' : [ api.FM_AOUT_RETRIEVE.app, api.FM_AOUT_RETRIEVE.method, [], true ],
111 'crahp' : [ api.FM_CRAHP_RETRIEVE.app, api.FM_CRAHP_RETRIEVE.method, [], true ],
114 'stash_retrieve' : function() {
116 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
117 const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
118 var data_cache=new OpenILS( );
119 var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
121 this.error.sdump('D_DATA_RETRIEVE','Retrieving ' + i + ' : ' + dc[i] + '\n');
124 if (typeof this.on_complete == 'function') {
129 this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
133 'print_list_defaults' : function() {
135 //if (typeof obj.print_list_templates == 'undefined') {
137 obj.print_list_types = [
141 'offline_inhouse_use',
148 obj.print_list_templates = {
151 'header' : 'The following items have been examined:<hr/><ol>',
152 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode%\r\n',
153 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
157 'header' : 'Transits:<hr/><ol>',
158 'line_item' : '<li>From: %transit_source% To: %transit_dest_lib%<br/>\r\nWhen: %transit_source_send_time%<br />\r\nBarcode: %transit_item_barcode% Title: %transit_item_title%<br/>\r\n',
159 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
163 'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou have the following items:<hr/><ol>',
164 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
165 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME%<br/>\r\n<br/>\r\n',
169 'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou checked out the following items:<hr/><ol>',
170 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
171 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME%<br/>\r\n<br/>\r\n',
173 'offline_checkout' : {
174 'type' : 'offline_checkout',
175 'header' : 'Patron %patron_barcode%<br/>\r\nYou checked out the following items:<hr/><ol>',
176 'line_item' : '<li>Barcode: %barcode%<br/>\r\nDue: %due_date%\r\n',
177 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
181 'header' : 'You checked in the following items:<hr/><ol>',
182 'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Call Number: %call_number%\r\n',
183 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
187 '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>',
188 'line_item' : 'Bill #%bill_id% %last_billing_type% Received: $%payment%<br />%barcode% %title%<br /><br />',
189 'footer' : '</blockquote> </p> <hr />%PINES_CODE% %TODAY_TRIM%<br/> <br/> ',
191 'bills_historical' : {
193 'header' : 'Welcome to %LIBRARY%!<br/>You had the following bills:<hr/><ol>',
194 '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/>',
195 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
199 'header' : 'Welcome to %LIBRARY%!<br/>You have the following bills:<hr/><ol>',
200 '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/>',
201 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\n<br/>\r\n',
203 'offline_checkin' : {
204 'type' : 'offline_checkin',
205 'header' : 'You checked in the following items:<hr/><ol>',
206 'line_item' : '<li>Barcode: %barcode%\r\n',
207 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
210 'type' : 'offline_renew',
211 'header' : 'You renewed the following items:<hr/><ol>',
212 'line_item' : '<li>Barcode: %barcode%\r\n',
213 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
215 'offline_inhouse_use' : {
216 'type' : 'offline_inhouse_use',
217 'header' : 'You marked the following in-house items used:<hr/><ol>',
218 'line_item' : '<li>Barcode: %barcode%\r\nUses: %count%',
219 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
223 'header' : 'You marked the following in-house items used:<hr/><ol>',
224 'line_item' : '<li>Barcode: %barcode%\r\nUses: %uses%\r\n<br />%alert_message%',
225 'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n',
229 'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou have the following titles on hold:<hr/><ol>',
230 'line_item' : '<li>%title%\r\n',
231 'footer' : '</ol><hr />%PINES_CODE% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME%<br/>\r\n<br/>\r\n',
235 obj.stash( 'print_list_templates', 'print_list_types' );
239 'network_retrieve' : function() {
240 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
244 JSAN.use('util.file'); var file = new util.file('print_list_templates');
245 obj.print_list_defaults();
246 obj.data_progress('Default print templates set. ');
247 if (file._file.exists()) {
249 var x = file.get_object();
252 obj.print_list_templates[i] = x[i];
254 obj.stash('print_list_templates');
255 obj.data_progress('Saved print templates retrieved from file. ');
263 JSAN.use('util.file'); var file = new util.file('global_font_adjust');
264 if (file._file.exists()) {
266 var x = file.get_object();
268 obj.global_font_adjust = x;
269 obj.stash('global_font_adjust');
270 obj.data_progress('Saved font settings retrieved from file. ');
278 JSAN.use('util.file'); var file = new util.file('no_sound');
279 if (file._file.exists()) {
281 var x = file.get_content();
284 obj.stash('no_sound');
285 obj.data_progress('Saved sound settings retrieved from file. ');
293 JSAN.use('util.functional');
294 JSAN.use('util.fm_utils');
296 function gen_fm_retrieval_func(classname,data) {
297 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
299 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
302 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
304 if (obj.list[classname].constructor.name == 'Array') {
305 obj.hash[classname] =
306 util.functional.convert_object_list_to_hash(
312 obj.error.sdump('D_ERROR',E + '\n');
318 var level = obj.error.sdump_levels.D_SES_RESULT;
319 if (classname == 'aou' || classname == 'my_aou')
320 obj.error.sdump_levels.D_SES_RESULT = false;
321 var robj = obj.network.request( app, method, params);
322 if (!robj || robj.ilsevent) {
323 obj.error.standard_unexpected_error_alert('The staff client failed to retrieve expected data from this call, "' + method + '"',robj);
326 obj.list[classname] = robj;
327 obj.error.sdump_levels.D_SES_RESULT = level;
329 obj.data_progress('Retrieved list for ' + classname + ' objects. ');
330 // if cacheable, store an offline copy
331 /* FIXME -- we're going to revisit caching and do it differently
333 var file = new util.file( classname );
334 file.set_object( obj.list[classname] );
339 // if cacheable, try offline
341 /* FIXME -- we're going to revisit caching and do it differently
343 var file = new util.file( classname );
344 obj.list[classname] = file.get_object(); file.close();
363 var robj = obj.network.simple_request('CIRC_MODIFIER_LIST',[]);
364 if (typeof robj.ilsevent != 'undefined') throw(robj);
365 obj.list.circ_modifier = robj;
366 obj.data_progress('Retrieved circ modifier list. ');
368 var error = 'Error: ' + js2JSON(E);
369 obj.error.sdump('D_ERROR',error);
378 var robj = obj.network.simple_request('BILLING_TYPE_LIST',[]);
379 if (typeof robj.ilsevent != 'undefined') throw(robj);
380 obj.list.billing_type = robj;
381 obj.data_progress('Retrieved billing type list. ');
383 var error = 'Error: ' + js2JSON(E);
384 obj.error.sdump('D_ERROR',error);
393 var f = gen_fm_retrieval_func(
396 api.FM_CNAL_RETRIEVE.app,
397 api.FM_CNAL_RETRIEVE.method,
405 var error = 'Error: ' + js2JSON(E);
406 obj.error.sdump('D_ERROR',error);
414 var f = gen_fm_retrieval_func(
417 api.FM_AU_RETRIEVE_VIA_SESSION.app,
418 api.FM_AU_RETRIEVE_VIA_SESSION.method,
426 var error = 'Error: ' + js2JSON(E);
427 obj.error.sdump('D_ERROR',error);
430 obj.list.au = [ obj.list.au ];
436 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
437 var f = gen_fm_retrieval_func(
440 api.FM_ASV_RETRIEVE_REQUIRED.app,
441 api.FM_ASV_RETRIEVE_REQUIRED.method,
447 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
450 var error = 'Error: ' + js2JSON(E);
451 obj.error.sdump('D_ERROR',error);
459 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
460 var f = gen_fm_retrieval_func(
463 api.FM_ASV_RETRIEVE.app,
464 api.FM_ASV_RETRIEVE.method,
470 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
473 var error = 'Error: ' + js2JSON(E);
474 obj.error.sdump('D_ERROR',error);
480 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
482 for (var i in this._fm_objects) {
483 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
486 // The previous org_tree call returned a tree, not a list or hash.
489 obj.tree.aou = obj.list.aou;
490 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
491 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
495 // The previous pgt call returned a tree, not a list or hash.
498 obj.tree.pgt = obj.list.pgt;
499 obj.list.pgt = util.fm_utils.flatten_ou_branch( obj.tree.pgt );
500 obj.hash.pgt = util.functional.convert_object_list_to_hash( obj.list.pgt );
504 // Do this after we get the user object
509 gen_fm_retrieval_func('my_aou',
511 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
512 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
513 [ obj.session.key, obj.list.au[0].ws_ou() ], /* use ws_ou and not home_ou */
524 gen_fm_retrieval_func( 'my_actsc',
526 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
527 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
528 [ obj.session.key, obj.list.au[0].ws_ou() ],
539 gen_fm_retrieval_func( 'my_asc',
541 api.FM_ASC_RETRIEVE_VIA_AOU.app,
542 api.FM_ASC_RETRIEVE_VIA_AOU.method,
543 [ obj.session.key, obj.list.au[0].ws_ou() ],
553 var f = gen_fm_retrieval_func(
556 api.FM_CNCT_RETRIEVE.app,
557 api.FM_CNCT_RETRIEVE.method,
558 [ obj.list.au[0].ws_ou() ],
565 var error = 'Error: ' + js2JSON(E);
566 obj.error.sdump('D_ERROR',error);
574 var f = gen_fm_retrieval_func(
577 api.FM_ACPL_RETRIEVE.app,
578 api.FM_ACPL_RETRIEVE.method,
579 [ obj.list.au[0].ws_ou() ],
586 var error = 'Error: ' + js2JSON(E);
587 obj.error.sdump('D_ERROR',error);
595 if (typeof this.on_complete == 'function') {
597 this.chain.push( this.on_complete );
599 JSAN.use('util.exec'); this.exec = new util.exec();
600 this.exec.on_error = function(E) {
602 if (typeof obj.on_error == 'function') {
605 alert('oops: ' + E );
608 return false; /* break chain */
611 this.exec.chain( this.chain );
616 dump('exiting OpenILS/data.js\n');