]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js
Use new org-specific billing_type's with default prices, and remove the 'Billing...
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / OpenILS / data.js
1 dump('entering OpenILS/data.js\n');
2
3 if (typeof OpenILS == 'undefined') OpenILS = {};
4 OpenILS.data = function () {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8
9         return this;
10 }
11
12 OpenILS.data.prototype = {
13
14         'list' : {},
15         'hash' : {},
16         'tree' : {},
17
18         'temp' : '',
19
20         'data_progress' : function(msg) {
21                 try {
22                         var x = document.getElementById('data_progress');
23                         if (x) {
24                                 x.appendChild( document.createTextNode( msg ) );
25                         }
26                 } catch(E) {
27                         this.error.sdump('D_ERROR',msg + '\n' + E);
28                 }
29         },
30
31         'init' : function (params) {
32
33                 try {
34                         if (params && params.via == 'stash') {  
35                                 this.stash_retrieve();
36                         } else {
37                                 this.network_retrieve();
38                         }
39                 
40                 } catch(E) {
41                         this.error.sdump('D_ERROR','Error in OpenILS.data.init('
42                                 +js2JSON(params)+'): ' + js2JSON(E) );
43                 }
44
45
46         },
47
48         // This should be invoked only once per application, in a persistant window
49         'init_observer_functions' : function() {
50                 try {
51                         var obj = this;                         // OpenILS.data
52                         obj.observers = {};                     //
53                         obj.observers.id = 1;           // Unique id for each observer function added
54                         obj.observers.id2path = {}; // Lookup for full_path via observer id
55                         obj.observers.cache = {};       // Observer funcs go in here
56
57                         // For a given path, this executes all the registered observer funcs
58                         obj.observers.dispatch = function(full_path, old_value, new_value) {
59                                 obj.error.sdump('D_OBSERVERS', 'entering observers.dispatch\nfull_path = ' + full_path + '\nold_value = ' + js2JSON(old_value) + '\nnew_value = ' + js2JSON(new_value) + '\n');
60                                 try {
61                                         var path = full_path.split(/\./).pop();
62                                         for (var i in obj.observers.cache[full_path]) {
63                                                 try {
64                                                         var o = obj.observers.cache[full_path][i];
65                                                         if (typeof o.func == 'function') o.func(path, old_value, new_value);
66                                                 } catch(E) {
67                                                         obj.error.sdump('D_ERROR','Error in OpenILS.data.observers.dispatch(): ' + js2JSON(E) );
68                                                 }
69                                         }
70                                 } catch(E) {
71                                         obj.error.sdump('D_ERROR','Error in OpenILS.data.observers.dispatch(): ' + js2JSON(E) );
72                                 }
73                         }
74
75                         // This registers an observer function for a given path
76                         obj.observers.add = function(full_path, func) {
77                                 try {
78                                         obj.error.sdump('D_OBSERVERS', 'entering observers.add\nfull_path = ' + full_path + '\nfunc = ' + func + '\n');
79                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
80                                         const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
81                                         var data_cache=new OpenILS( );
82                                         var stash = data_cache.wrappedJSObject.OpenILS.prototype.data;
83
84                                         var id = obj.observers.id++;
85                                         if (typeof obj.observers.cache[ full_path ] == 'undefined') obj.observers.cache[ full_path ] = {};
86                                         obj.observers.cache[ full_path ][ id ] = { 'func' : func, 'time_added' : new Date() };
87                                         obj.observers.id2path[ id ] = [ full_path ];
88
89                                         var path_list = full_path.split(/\./);
90                                         var observed_prop = path_list.pop();
91
92                                         // Convert soft path to object reference.  Error if any but the last node is undefined
93                                         for (var i in path_list) stash = stash[ path_list[i] ];
94
95                                         /*
96
97                                         // experiment with storing only json in cache to avoid the [ ] -> { '0' : .., '1' : .. } bug
98
99                                         if (stash[observed_prop] && getKeys( obj.observers.cache[ full_path ] ).length == 0) {
100                                                 stash['_' + observed_prop] = js2JSON(stash[observed_prop]);
101                                         }
102
103                                         stash.__defineSetter__(observed_prop, function(x) { this['_'+observed_prop] = js2JSON(x); });
104                                         stash.__defineGetter__(observed_prop, function() { return JSON2js(this['_'+observed_prop]); });
105                                         */
106
107                                         stash.watch(
108                                                 observed_prop,
109                                                 function(p,old_value,new_value) {
110                                                         obj.observers.dispatch(full_path,old_value,new_value);
111                                                         return new_value;
112                                                 }
113                                         );
114
115                                         return id;
116                                 } catch(E) {
117                                         obj.error.sdump('D_ERROR','Error in OpenILS.data.observers.add(): ' + js2JSON(E) );
118                                 }
119                         }
120
121                         // This unregisters an observer function for a given observer id
122                         obj.observers.remove = function(id) {
123                                 try {
124                                         obj.error.sdump('D_OBSERVERS', 'entering observers.remove\nid = ' + id + '\n');
125                                         var path = obj.observers.id2path[ id ];
126                                         delete obj.observers.cache[ path ][ id ];
127                                         delete obj.observers.id2path[ id ];
128                                 } catch(E) {
129                                         obj.error.sdump('D_ERROR','Error in OpenILS.data.observers.remove(): ' + js2JSON(E) );
130                                 }
131                         }
132
133                         // This purges observer functions for a given path
134                         obj.observers.purge = function(full_path) {
135                                 obj.error.sdump('D_OBSERVERS', 'entering observers.purge\nfull_path = ' + full_path + '\n');
136                                 try {
137                                         var remove_these = [];
138                                         for (var id in obj.observers.cache[ full_path ]) remove_these.push( id );
139                                         for (var id in remove_these) delete obj.observers.id2path[ id ];
140                                         delete obj.observers.cache[ full_path ];
141                                 } catch(E) {
142                                         obj.error.sdump('D_ERROR','Error in OpenILS.data.observers.purge(): ' + js2JSON(E) );
143                                 }
144                         }
145
146                         obj.stash('observers'); // make this accessible globally
147
148                 } catch(E) {
149                         this.error.sdump('D_ERROR','Error in OpenILS.data.init_observer_functions(): ' + js2JSON(E) );
150                 }
151         },
152
153         'stash' : function () {
154                 try {
155                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
156                         const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
157                         var data_cache=new OpenILS( );
158                         for (var i = 0; i < arguments.length; i++) {
159                                 try {
160                                         if (arguments[i] != 'hash' && arguments[i] != 'list') this.error.sdump('D_DATA_STASH','stashing ' + arguments[i] + ' : ' + this[arguments[i]] + (typeof this[arguments[i]] == 'object' ? ' = ' + (this[arguments[i]]) : '') + '\n');
161                                 } catch(F) { alert(F); }
162                                 data_cache.wrappedJSObject.OpenILS.prototype.data[arguments[i]] = this[arguments[i]];
163                         }
164                 } catch(E) {
165                         this.error.sdump('D_ERROR','Error in OpenILS.data.stash(): ' + js2JSON(E) );
166                 }
167         },
168
169         'lookup' : function(key,value) {
170                 try {
171                         var obj = this; var found;
172                         if (obj.hash[key] && obj.hash[key][value]) return obj.hash[key][value];
173                         switch(key) {
174                                 case 'acpl': 
175                                         found = obj.network.simple_request('FM_ACPL_RETRIEVE_VIA_ID.authoritative',[ value ]);
176                                 break;
177                                 default: return undefined; break;
178                         }
179                         if (typeof found.ilsevent != 'undefined') throw(found);
180                         if (!obj.hash[key]) obj.hash[key] = {};
181                         obj.hash[key][value] = found; obj.list[key].push( found ); obj.stash('hash','list');
182                         return found;
183                 } catch(E) {
184                         this.error.sdump('D_ERROR','Error in OpenILS.data.lookup('+key+','+value+'): ' + js2JSON(E) );
185                         return undefined;
186                 }
187         },
188
189         '_debug_stash' : function() {
190                 try {
191                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
192                         const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
193                         var data_cache=new OpenILS( );
194                         for (var i in data_cache.wrappedJSObject.OpenILS.prototype.data) {
195                                 dump('_debug_stash ' + i + '\n');
196                         }
197                 } catch(E) {
198                         this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
199                 }
200         },
201
202         '_fm_objects' : {
203
204                 'pgt' : [ api.FM_PGT_RETRIEVE.app, api.FM_PGT_RETRIEVE.method, [], true ],
205                 'cit' : [ api.FM_CIT_RETRIEVE.app, api.FM_CIT_RETRIEVE.method, [], true ],
206                 'citm' : [ api.FM_CITM_RETRIEVE.app, api.FM_CITM_RETRIEVE.method, [], true ],
207                 /*
208                 'cst' : [ api.FM_CST_RETRIEVE.app, api.FM_CST_RETRIEVE.method, [], true ],
209                 */
210                 /*
211                 'acpl' : [ api.FM_ACPL_RETRIEVE.app, api.FM_ACPL_RETRIEVE.method, [], true ],
212                 */
213                 'ccs' : [ api.FM_CCS_RETRIEVE.app, api.FM_CCS_RETRIEVE.method, [], true ],
214                 'aou' : [ api.FM_AOU_RETRIEVE.app, api.FM_AOU_RETRIEVE.method, [], true ],
215                 'aout' : [ api.FM_AOUT_RETRIEVE.app, api.FM_AOUT_RETRIEVE.method, [], true ],
216                 'crahp' : [ api.FM_CRAHP_RETRIEVE.app, api.FM_CRAHP_RETRIEVE.method, [], true ]
217         },
218
219         'stash_retrieve' : function() {
220                 try {
221                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
222                         const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
223                         var data_cache=new OpenILS( );
224                         var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
225                         for (var i in dc) {
226                                 this.error.sdump('D_DATA_RETRIEVE','Retrieving ' + i + ' : ' + dc[i] + '\n');
227                                 this[i] = dc[i];
228                         }
229                         if (typeof this.on_complete == 'function') {
230
231                                 this.on_complete();
232                         }
233                 } catch(E) {
234                         this.error.sdump('D_ERROR','Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
235                 }
236         },
237
238         'print_list_defaults' : function() {
239                 var obj = this;
240                 //if (typeof obj.print_list_templates == 'undefined') {
241                 {
242                         obj.print_list_types = [ 
243                                 'offline_checkout', 
244                                 'offline_checkin', 
245                                 'offline_renew', 
246                                 'offline_inhouse_use', 
247                                 'items', 
248                                 'bills', 
249                                 'payment', 
250                                 'holds', 
251                                 /* 'patrons' */
252                         ];
253                         obj.print_list_templates = { 
254                                 'item_status' : {
255                                         'type' : 'items',
256                                         'header' : 'The following items have been examined:<hr/><ol>',
257                                         'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode%\r\n',
258                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\n<br/>\r\n'
259                                 }, 
260                                 'transit_list' : {
261                                         'type' : 'transits',
262                                         'header' : 'Transits:<hr/><ol>',
263                                         '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',
264                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\n<br/>\r\n'
265                                 }, 
266                                 'items_out' : {
267                                         'type' : 'items',
268                                         'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou have the following items:<hr/><ol>',
269                                         'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
270                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME%<br/>\r\n<br/>\r\n'
271                                 }, 
272                                 'checkout' : {
273                                         'type' : 'items',
274                                         'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou checked out the following items:<hr/><ol>',
275                                         'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
276                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME%<br/>\r\n<br/>\r\n'
277                                 }, 
278                                 'offline_checkout' : {
279                                         'type' : 'offline_checkout',
280                                         'header' : 'Patron %patron_barcode%<br/>\r\nYou checked out the following items:<hr/><ol>',
281                                         'line_item' : '<li>Barcode: %barcode%<br/>\r\nDue: %due_date%\r\n',
282                                         'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n'
283                                 },
284                                 'checkin' : {
285                                         'type' : 'items',
286                                         'header' : 'You checked in the following items:<hr/><ol>',
287                                         'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode%  Call Number: %call_number%\r\n',
288                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\n<br/>\r\n'
289                                 }, 
290                                 'bill_payment' : {
291                                         'type' : 'payment',
292                                         '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>',
293                                         'line_item' : 'Bill #%bill_id%  %last_billing_type% Received: $%payment%<br />%barcode% %title%<br /><br />',
294                                         'footer' : '</blockquote> </p> <hr />%SHORTNAME% %TODAY_TRIM%<br/> <br/> '
295                                 },
296                                 'bills_historical' : {
297                                         'type' : 'bills',
298                                         'header' : 'Welcome to %LIBRARY%!<br/>You had the following bills:<hr/><ol>',
299                                         '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/>',
300                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\n<br/>\r\n'
301                                 }, 
302                                 'bills_current' : {
303                                         'type' : 'bills',
304                                         'header' : 'Welcome to %LIBRARY%!<br/>You have the following bills:<hr/><ol>',
305                                         '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/>',
306                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\n<br/>\r\n'
307                                 },
308                                 'bills_main_view' : {
309                                         'type' : 'bills',
310                                         'header' : 'Welcome to %LIBRARY%!<br/>You have the following bills:<hr/><ol>',
311                                         'line_item' : '<dt><b>Bill #%id%</b> %title%</dt> <dd> <table width="100%"> <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/>',
312                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\n<br/>\r\n'
313                                 },
314                                 'offline_checkin' : {
315                                         'type' : 'offline_checkin',
316                                         'header' : 'You checked in the following items:<hr/><ol>',
317                                         'line_item' : '<li>Barcode: %barcode%\r\n',
318                                         'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n'
319                                 },
320                                 'offline_renew' : {
321                                         'type' : 'offline_renew',
322                                         'header' : 'You renewed the following items:<hr/><ol>',
323                                         'line_item' : '<li>Barcode: %barcode%\r\n',
324                                         'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n'
325                                 },
326                                 'offline_inhouse_use' : {
327                                         'type' : 'offline_inhouse_use',
328                                         'header' : 'You marked the following in-house items used:<hr/><ol>',
329                                         'line_item' : '<li>Barcode: %barcode%\r\nUses: %count%',
330                                         'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n'
331                                 },
332                                 'in_house_use' : {
333                                         'type' : 'items',
334                                         'header' : 'You marked the following in-house items used:<hr/><ol>',
335                                         'line_item' : '<li>Barcode: %barcode%\r\nUses: %uses%\r\n<br />%alert_message%',
336                                         'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n'
337                                 },
338                                 'holds' : {
339                                         'type' : 'holds',
340                                         'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou have the following titles on hold:<hr/><ol>',
341                                         'line_item' : '<li>%title%\r\n',
342                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME%<br/>\r\n<br/>\r\n'
343                                 }
344                         }; 
345
346                         obj.stash( 'print_list_templates', 'print_list_types' );
347                 }
348         },
349
350         'network_retrieve' : function() {
351                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
352                 var obj = this;
353
354
355                 JSAN.use('util.file'); var file = new util.file('print_list_templates');
356                 obj.print_list_defaults();
357                 obj.data_progress('Default print templates set. ');
358                 if (file._file.exists()) {
359                         try {
360                                 var x = file.get_object();
361                                 if (x) {
362                                         for (var i in x) {
363                                                 obj.print_list_templates[i] = x[i];
364                                         }
365                                         obj.stash('print_list_templates');
366                                         obj.data_progress('Saved print templates retrieved from file. ');
367                                 }
368                         } catch(E) {
369                                 alert(E);
370                         }
371                 }
372                 file.close();
373
374                 JSAN.use('util.file'); var file = new util.file('global_font_adjust');
375                 if (file._file.exists()) {
376                         try {
377                                 var x = file.get_object();
378                                 if (x) {
379                                         obj.global_font_adjust = x;
380                                         obj.stash('global_font_adjust');
381                                         obj.data_progress('Saved font settings retrieved from file. ');
382                                 }
383                         } catch(E) {
384                                 alert(E);
385                         }
386                 }
387                 file.close();
388
389                 JSAN.use('util.file'); var file = new util.file('no_sound');
390                 if (file._file.exists()) {
391                         try {
392                                 var x = file.get_content();
393                                 if (x) {
394                                         obj.no_sound = x;
395                                         obj.stash('no_sound');
396                                         obj.data_progress('Saved sound settings retrieved from file. ');
397                                 }
398                         } catch(E) {
399                                 alert(E);
400                         }
401                 }
402                 file.close();
403
404                 JSAN.use('util.file'); var file = new util.file('print_strategy');
405                 if (file._file.exists()) {
406                         try {
407                                 var x = file.get_content();
408                                 if (x) {
409                                         obj.print_strategy = x;
410                                         obj.stash('print_strategy');
411                                         obj.data_progress('Print strategy retrieved from file. ');
412                                 }
413                         } catch(E) {
414                                 alert(E);
415                         }
416                 }
417                 file.close();
418
419                 JSAN.use('util.functional');
420                 JSAN.use('util.fm_utils');
421
422                 function gen_fm_retrieval_func(classname,data) {
423                         var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
424                         return function () {
425                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
426
427                                 function convert() {
428                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
429                                         try {
430                                                 if (obj.list[classname].constructor.name == 'Array') {
431                                                         obj.hash[classname] = 
432                                                                 util.functional.convert_object_list_to_hash(
433                                                                         obj.list[classname]
434                                                                 );
435                                                 }
436                                         } catch(E) {
437
438                                                 obj.error.sdump('D_ERROR',E + '\n');
439                                         }
440
441                                 }
442
443                                 try {
444                                         var level = obj.error.sdump_levels.D_SES_RESULT;
445                                         if (classname == 'aou' || classname == 'my_aou')
446                                                 obj.error.sdump_levels.D_SES_RESULT = false;
447                                         var robj = obj.network.request( app, method, params);
448                                         if (!robj || robj.ilsevent) {
449                                                 obj.error.standard_unexpected_error_alert('The staff client failed to retrieve expected data from this call, "' + method + '"',robj);
450                                                 throw(robj);
451                                         }
452                                         obj.list[classname] = robj;
453                                         obj.error.sdump_levels.D_SES_RESULT = level;
454                                         convert();
455                                         obj.data_progress('Retrieved list for ' + classname + ' objects. ');
456
457                                 } catch(E) {
458                                         // if cacheable, try offline
459                                         if (cacheable) {
460                                                 /* FIXME -- we're going to revisit caching and do it differently
461                                                 try {
462                                                         var file = new util.file( classname );
463                                                         obj.list[classname] = file.get_object(); file.close();
464                                                         convert();
465                                                 } catch(E) {
466                                                         throw(E);
467                                                 }
468                                                 */
469                                                 throw(E); // for now
470                                         } else {
471                                                 throw(E); // for now
472                                         }
473                                 }
474                         }
475                 }
476
477                 this.chain = [];
478
479                 this.chain.push(
480                         function() {
481                                 try {
482                                         var robj = obj.network.simple_request('CIRC_MODIFIER_LIST',[]);
483                                         if (typeof robj.ilsevent != 'undefined') throw(robj);
484                                         obj.list.circ_modifier = robj;
485                                         obj.data_progress('Retrieved circ modifier list. ');
486                                 } catch(E) {
487                                         var error = 'Error: ' + js2JSON(E);
488                                         obj.error.sdump('D_ERROR',error);
489                                         throw(E);
490                                 }
491                         }
492                 );
493
494                 this.chain.push(
495                         function() {
496                                 try {
497                                         var robj = obj.network.simple_request('BILLING_TYPE_LIST',[]);
498                                         if (typeof robj.ilsevent != 'undefined') throw(robj);
499                                         obj.list.billing_type = robj;
500                                         obj.data_progress('Retrieved billing type list. ');
501                                 } catch(E) {
502                                         var error = 'Error: ' + js2JSON(E);
503                                         obj.error.sdump('D_ERROR',error);
504                                         throw(E);
505                                 }
506                         }
507                 );
508
509                 this.chain.push(
510                         function() {
511                                 var f = gen_fm_retrieval_func(
512                                         'cnal',
513                                         [
514                                                 api.FM_CNAL_RETRIEVE.app,
515                                                 api.FM_CNAL_RETRIEVE.method,
516                                                 [ obj.session.key ],
517                                                 false
518                                         ]
519                                 );
520                                 try {
521                                         f();
522                                 } catch(E) {
523                                         var error = 'Error: ' + js2JSON(E);
524                                         obj.error.sdump('D_ERROR',error);
525                                         throw(E);
526                                 }
527                         }
528                 );
529
530                 this.chain.push(
531                         function() {
532                                 var f = gen_fm_retrieval_func(
533                                         'au',
534                                         [
535                                                 api.FM_AU_RETRIEVE_VIA_SESSION.app,
536                                                 api.FM_AU_RETRIEVE_VIA_SESSION.method,
537                                                 [ obj.session.key ],
538                                                 false
539                                         ]
540                                 );
541                                 try {
542                                         f();
543                                 } catch(E) {
544                                         var error = 'Error: ' + js2JSON(E);
545                                         obj.error.sdump('D_ERROR',error);
546                                         throw(E);
547                                 }
548                                 obj.list.au = [ obj.list.au ];
549                         }
550                 );
551
552                 this.chain.push(
553                         function() {
554                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
555                                 var f = gen_fm_retrieval_func(
556                                         'my_asv',
557                                         [
558                                                 api.FM_ASV_RETRIEVE_REQUIRED.app,
559                                                 api.FM_ASV_RETRIEVE_REQUIRED.method,
560                                                 [ obj.session.key ],
561                                                 true
562                                         ]
563                                 );
564                                 try {
565                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
566                                         f();
567                                 } catch(E) {
568                                         var error = 'Error: ' + js2JSON(E);
569                                         obj.error.sdump('D_ERROR',error);
570                                         throw(E);
571                                 }
572                         }
573                 );
574
575                 this.chain.push(
576                         function() {
577                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
578                                 var f = gen_fm_retrieval_func(
579                                         'asv',
580                                         [
581                                                 api.FM_ASV_RETRIEVE.app,
582                                                 api.FM_ASV_RETRIEVE.method,
583                                                 [ obj.session.key ],
584                                                 true
585                                         ]
586                                 );
587                                 try {
588                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
589                                         f();
590                                 } catch(E) {
591                                         var error = 'Error: ' + js2JSON(E);
592                                         obj.error.sdump('D_ERROR',error);
593                                         throw(E);
594                                 }
595                         }
596                 );
597
598                 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
599
600                 for (var i in this._fm_objects) {
601                         this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
602                 }
603
604                 // The previous org_tree call returned a tree, not a list or hash.
605                 this.chain.push(
606                         function () {
607                                 obj.tree.aou = obj.list.aou;
608                                 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
609                                 for (var i = 0; i < obj.list.aou.length; i++) {
610                                         var c = obj.list.aou[i].children();
611                                         if (!c) c = [];
612                                         c = c.sort(
613                                                 function( a, b ) {
614                                                         if (a.shortname() < b.shortname()) return -1;
615                                                         if (a.shortname() > b.shortname()) return 1;
616                                                         return 0;
617                                                 }
618                                         );
619                                         obj.list.aou[i].children( c );
620                                 }
621                                 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
622                                 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
623                         }
624                 );
625
626                 // The previous pgt call returned a tree, not a list or hash.
627                 this.chain.push(
628                         function () {
629                                 obj.tree.pgt = obj.list.pgt;
630                                 obj.list.pgt = util.fm_utils.flatten_ou_branch( obj.tree.pgt );
631                                 obj.hash.pgt = util.functional.convert_object_list_to_hash( obj.list.pgt );
632                         }
633                 );
634
635                 // Do this after we get the user object
636                 this.chain.push(
637
638                         function() {
639
640                                 gen_fm_retrieval_func('my_aou', 
641                                         [ 
642                                                 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
643                                                 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
644                                                 [ obj.session.key, obj.list.au[0].ws_ou() ], /* use ws_ou and not home_ou */
645                                                 true
646                                         ]
647                                 )();
648                         }
649                 );
650
651                 this.chain.push(
652
653                         function () {
654
655                                 gen_fm_retrieval_func( 'my_actsc', 
656                                         [ 
657                                                 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
658                                                 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
659                                                 [ obj.session.key, obj.list.au[0].ws_ou() ],
660                                                 true
661                                         ]
662                                 )();
663                         }
664                 );
665
666                 this.chain.push(
667
668                         function () {
669
670                                 gen_fm_retrieval_func( 'my_asc', 
671                                         [ 
672                                                 api.FM_ASC_RETRIEVE_VIA_AOU.app,
673                                                 api.FM_ASC_RETRIEVE_VIA_AOU.method,
674                                                 [ obj.session.key, obj.list.au[0].ws_ou() ],
675                                                 true
676                                         ]
677                                 )();
678                         }
679                 );
680
681
682                 this.chain.push(
683                         function() {
684                                 var f = gen_fm_retrieval_func(
685                                         'cnct',
686                                         [
687                                                 api.FM_CNCT_RETRIEVE.app,
688                                                 api.FM_CNCT_RETRIEVE.method,
689                                                 [ obj.list.au[0].ws_ou() ], 
690                                                 false
691                                         ]
692                                 );
693                                 try {
694                                         f();
695                                 } catch(E) {
696                                         var error = 'Error: ' + js2JSON(E);
697                                         obj.error.sdump('D_ERROR',error);
698                                         throw(E);
699                                 }
700                         }
701                 );
702
703                 this.chain.push(
704                         function() {
705                                 var f = gen_fm_retrieval_func(
706                                         'my_cnct',
707                                         [
708                                                 api.FM_CNCT_RETRIEVE.app,
709                                                 api.FM_CNCT_RETRIEVE.method,
710                                                 [ obj.list.au[0].ws_ou() ], 
711                                                 false
712                                         ]
713                                 );
714                                 try {
715                                         f();
716                                 } catch(E) {
717                                         var error = 'Error: ' + js2JSON(E);
718                                         obj.error.sdump('D_ERROR',error);
719                                         throw(E);
720                                 }
721                         }
722                 );
723
724
725                 this.chain.push(
726                         function() {
727                                 var f = gen_fm_retrieval_func(
728                                         'acpl',
729                                         [
730                                                 api.FM_ACPL_RETRIEVE.app,
731                                                 api.FM_ACPL_RETRIEVE.method,
732                                                 [ obj.list.au[0].ws_ou() ],
733                                                 false
734                                         ]
735                                 );
736                                 try {
737                                         f();
738                                 } catch(E) {
739                                         var error = 'Error: ' + js2JSON(E);
740                                         obj.error.sdump('D_ERROR',error);
741                                         throw(E);
742                                 }
743                         }
744                 );
745
746                 this.chain.push(
747                         function() {
748                                 var f = gen_fm_retrieval_func(
749                                         'cbt',
750                                         [
751                                                 api.FM_CBT_RETRIEVE.app,
752                                                 api.FM_CBT_RETRIEVE.method,
753                                                 [ obj.session.key, obj.list.au[0].ws_ou() ],
754                                                 false
755                                         ]
756                                 );
757                                 try {
758                                         f();
759                                 } catch(E) {
760                                         var error = 'Error: ' + js2JSON(E);
761                                         obj.error.sdump('D_ERROR',error);
762                                         throw(E);
763                                 }
764                         }
765                 );
766
767                 if (typeof this.on_complete == 'function') {
768
769                         this.chain.push( this.on_complete );
770                 }
771                 JSAN.use('util.exec'); this.exec = new util.exec();
772                 this.exec.on_error = function(E) { 
773                 
774                         if (typeof obj.on_error == 'function') {
775                                 obj.on_error();
776                         } else {
777                                 alert('oops: ' + E ); 
778                         }
779
780                         return false; /* break chain */
781                 }
782
783                 this.exec.chain( this.chain );
784
785         }
786 }
787
788 dump('exiting OpenILS/data.js\n');