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 />%SHORTNAME% %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 />%SHORTNAME% %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 />%SHORTNAME% %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 />%SHORTNAME% %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 />%SHORTNAME% %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 />%SHORTNAME% %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 />%SHORTNAME% %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 />%SHORTNAME% %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 />%SHORTNAME% %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.file'); var file = new util.file('print_strategy');
294 if (file._file.exists()) {
296 var x = file.get_content();
298 obj.print_strategy = x;
299 obj.stash('print_strategy');
300 obj.data_progress('Print strategy retrieved from file. ');
308 JSAN.use('util.functional');
309 JSAN.use('util.fm_utils');
311 function gen_fm_retrieval_func(classname,data) {
312 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
314 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
317 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
319 if (obj.list[classname].constructor.name == 'Array') {
320 obj.hash[classname] =
321 util.functional.convert_object_list_to_hash(
327 obj.error.sdump('D_ERROR',E + '\n');
333 var level = obj.error.sdump_levels.D_SES_RESULT;
334 if (classname == 'aou' || classname == 'my_aou')
335 obj.error.sdump_levels.D_SES_RESULT = false;
336 var robj = obj.network.request( app, method, params);
337 if (!robj || robj.ilsevent) {
338 obj.error.standard_unexpected_error_alert('The staff client failed to retrieve expected data from this call, "' + method + '"',robj);
341 obj.list[classname] = robj;
342 obj.error.sdump_levels.D_SES_RESULT = level;
344 obj.data_progress('Retrieved list for ' + classname + ' objects. ');
345 // if cacheable, store an offline copy
346 /* FIXME -- we're going to revisit caching and do it differently
348 var file = new util.file( classname );
349 file.set_object( obj.list[classname] );
354 // if cacheable, try offline
356 /* FIXME -- we're going to revisit caching and do it differently
358 var file = new util.file( classname );
359 obj.list[classname] = file.get_object(); file.close();
378 var robj = obj.network.simple_request('CIRC_MODIFIER_LIST',[]);
379 if (typeof robj.ilsevent != 'undefined') throw(robj);
380 obj.list.circ_modifier = robj;
381 obj.data_progress('Retrieved circ modifier list. ');
383 var error = 'Error: ' + js2JSON(E);
384 obj.error.sdump('D_ERROR',error);
393 var robj = obj.network.simple_request('BILLING_TYPE_LIST',[]);
394 if (typeof robj.ilsevent != 'undefined') throw(robj);
395 obj.list.billing_type = robj;
396 obj.data_progress('Retrieved billing type list. ');
398 var error = 'Error: ' + js2JSON(E);
399 obj.error.sdump('D_ERROR',error);
408 var f = gen_fm_retrieval_func(
411 api.FM_CNAL_RETRIEVE.app,
412 api.FM_CNAL_RETRIEVE.method,
420 var error = 'Error: ' + js2JSON(E);
421 obj.error.sdump('D_ERROR',error);
429 var f = gen_fm_retrieval_func(
432 api.FM_AU_RETRIEVE_VIA_SESSION.app,
433 api.FM_AU_RETRIEVE_VIA_SESSION.method,
441 var error = 'Error: ' + js2JSON(E);
442 obj.error.sdump('D_ERROR',error);
445 obj.list.au = [ obj.list.au ];
451 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
452 var f = gen_fm_retrieval_func(
455 api.FM_ASV_RETRIEVE_REQUIRED.app,
456 api.FM_ASV_RETRIEVE_REQUIRED.method,
462 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
465 var error = 'Error: ' + js2JSON(E);
466 obj.error.sdump('D_ERROR',error);
474 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
475 var f = gen_fm_retrieval_func(
478 api.FM_ASV_RETRIEVE.app,
479 api.FM_ASV_RETRIEVE.method,
485 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
488 var error = 'Error: ' + js2JSON(E);
489 obj.error.sdump('D_ERROR',error);
495 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
497 for (var i in this._fm_objects) {
498 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
501 // The previous org_tree call returned a tree, not a list or hash.
504 obj.tree.aou = obj.list.aou;
505 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
506 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
510 // The previous pgt call returned a tree, not a list or hash.
513 obj.tree.pgt = obj.list.pgt;
514 obj.list.pgt = util.fm_utils.flatten_ou_branch( obj.tree.pgt );
515 obj.hash.pgt = util.functional.convert_object_list_to_hash( obj.list.pgt );
519 // Do this after we get the user object
524 gen_fm_retrieval_func('my_aou',
526 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
527 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
528 [ obj.session.key, obj.list.au[0].ws_ou() ], /* use ws_ou and not home_ou */
539 gen_fm_retrieval_func( 'my_actsc',
541 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
542 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
543 [ obj.session.key, obj.list.au[0].ws_ou() ],
554 gen_fm_retrieval_func( 'my_asc',
556 api.FM_ASC_RETRIEVE_VIA_AOU.app,
557 api.FM_ASC_RETRIEVE_VIA_AOU.method,
558 [ obj.session.key, obj.list.au[0].ws_ou() ],
568 var f = gen_fm_retrieval_func(
571 api.FM_CNCT_RETRIEVE.app,
572 api.FM_CNCT_RETRIEVE.method,
573 [ obj.list.au[0].ws_ou() ],
580 var error = 'Error: ' + js2JSON(E);
581 obj.error.sdump('D_ERROR',error);
589 var f = gen_fm_retrieval_func(
592 api.FM_ACPL_RETRIEVE.app,
593 api.FM_ACPL_RETRIEVE.method,
594 [ obj.list.au[0].ws_ou() ],
601 var error = 'Error: ' + js2JSON(E);
602 obj.error.sdump('D_ERROR',error);
610 if (typeof this.on_complete == 'function') {
612 this.chain.push( this.on_complete );
614 JSAN.use('util.exec'); this.exec = new util.exec();
615 this.exec.on_error = function(E) {
617 if (typeof obj.on_error == 'function') {
620 alert('oops: ' + E );
623 return false; /* break chain */
626 this.exec.chain( this.chain );
631 dump('exiting OpenILS/data.js\n');