]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js
receipt template for Item Renew interface
[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                                 'renew' : {
273                                         'type' : 'items',
274                                         'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou have renewed 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                                 'checkout' : {
279                                         'type' : 'items',
280                                         'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou checked out the following items:<hr/><ol>',
281                                         'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode% Due: %due_date%\r\n',
282                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME%<br/>\r\n<br/>\r\n'
283                                 }, 
284                                 'offline_checkout' : {
285                                         'type' : 'offline_checkout',
286                                         'header' : 'Patron %patron_barcode%<br/>\r\nYou checked out the following items:<hr/><ol>',
287                                         'line_item' : '<li>Barcode: %barcode%<br/>\r\nDue: %due_date%\r\n',
288                                         'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n'
289                                 },
290                                 'checkin' : {
291                                         'type' : 'items',
292                                         'header' : 'You checked in the following items:<hr/><ol>',
293                                         'line_item' : '<li>%title%<br/>\r\nBarcode: %barcode%  Call Number: %call_number%\r\n',
294                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\n<br/>\r\n'
295                                 }, 
296                                 'bill_payment' : {
297                                         'type' : 'payment',
298                                         '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>',
299                                         'line_item' : 'Bill #%bill_id%  %last_billing_type% Received: $%payment%<br />%barcode% %title%<br /><br />',
300                                         'footer' : '</blockquote> </p> <hr />%SHORTNAME% %TODAY_TRIM%<br/> <br/> '
301                                 },
302                                 'bills_historical' : {
303                                         'type' : 'bills',
304                                         'header' : 'Welcome to %LIBRARY%!<br/>You had 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_current' : {
309                                         'type' : 'bills',
310                                         'header' : 'Welcome to %LIBRARY%!<br/>You have the following bills:<hr/><ol>',
311                                         '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/>',
312                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\n<br/>\r\n'
313                                 },
314                                 'bills_main_view' : {
315                                         'type' : 'bills',
316                                         'header' : 'Welcome to %LIBRARY%!<br/>You have the following bills:<hr/><ol>',
317                                         '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/>',
318                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\n<br/>\r\n'
319                                 },
320                                 'offline_checkin' : {
321                                         'type' : 'offline_checkin',
322                                         'header' : 'You checked in 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_renew' : {
327                                         'type' : 'offline_renew',
328                                         'header' : 'You renewed the following items:<hr/><ol>',
329                                         'line_item' : '<li>Barcode: %barcode%\r\n',
330                                         'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n'
331                                 },
332                                 'offline_inhouse_use' : {
333                                         'type' : 'offline_inhouse_use',
334                                         'header' : 'You marked the following in-house items used:<hr/><ol>',
335                                         'line_item' : '<li>Barcode: %barcode%\r\nUses: %count%',
336                                         'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n'
337                                 },
338                                 'in_house_use' : {
339                                         'type' : 'items',
340                                         'header' : 'You marked the following in-house items used:<hr/><ol>',
341                                         'line_item' : '<li>Barcode: %barcode%\r\nUses: %uses%\r\n<br />%alert_message%',
342                                         'footer' : '</ol><hr />%TODAY_TRIM%<br/>\r\n<br/>\r\n'
343                                 },
344                                 'holds' : {
345                                         'type' : 'holds',
346                                         'header' : 'Welcome to %LIBRARY%!<br/>\r\nYou have the following titles on hold:<hr/><ol>',
347                                         'line_item' : '<li>%title%\r\n',
348                                         'footer' : '</ol><hr />%SHORTNAME% %TODAY_TRIM%<br/>\r\nYou were helped by %STAFF_FIRSTNAME%<br/>\r\n<br/>\r\n'
349                                 }
350                         }; 
351
352                         obj.stash( 'print_list_templates', 'print_list_types' );
353                 }
354         },
355
356         'network_retrieve' : function() {
357                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
358                 var obj = this;
359
360
361                 JSAN.use('util.file'); var file = new util.file('print_list_templates');
362                 obj.print_list_defaults();
363                 obj.data_progress('Default print templates set. ');
364                 if (file._file.exists()) {
365                         try {
366                                 var x = file.get_object();
367                                 if (x) {
368                                         for (var i in x) {
369                                                 obj.print_list_templates[i] = x[i];
370                                         }
371                                         obj.stash('print_list_templates');
372                                         obj.data_progress('Saved print templates retrieved from file. ');
373                                 }
374                         } catch(E) {
375                                 alert(E);
376                         }
377                 }
378                 file.close();
379
380                 JSAN.use('util.file'); var file = new util.file('global_font_adjust');
381                 if (file._file.exists()) {
382                         try {
383                                 var x = file.get_object();
384                                 if (x) {
385                                         obj.global_font_adjust = x;
386                                         obj.stash('global_font_adjust');
387                                         obj.data_progress('Saved font settings retrieved from file. ');
388                                 }
389                         } catch(E) {
390                                 alert(E);
391                         }
392                 }
393                 file.close();
394
395                 JSAN.use('util.file'); var file = new util.file('no_sound');
396                 if (file._file.exists()) {
397                         try {
398                                 var x = file.get_content();
399                                 if (x) {
400                                         obj.no_sound = x;
401                                         obj.stash('no_sound');
402                                         obj.data_progress('Saved sound settings retrieved from file. ');
403                                 }
404                         } catch(E) {
405                                 alert(E);
406                         }
407                 }
408                 file.close();
409
410                 JSAN.use('util.file'); var file = new util.file('print_strategy');
411                 if (file._file.exists()) {
412                         try {
413                                 var x = file.get_content();
414                                 if (x) {
415                                         obj.print_strategy = x;
416                                         obj.stash('print_strategy');
417                                         obj.data_progress('Print strategy retrieved from file. ');
418                                 }
419                         } catch(E) {
420                                 alert(E);
421                         }
422                 }
423                 file.close();
424
425                 JSAN.use('util.functional');
426                 JSAN.use('util.fm_utils');
427
428                 function gen_fm_retrieval_func(classname,data) {
429                         var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
430                         return function () {
431                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
432
433                                 function convert() {
434                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
435                                         try {
436                                                 if (obj.list[classname].constructor.name == 'Array') {
437                                                         obj.hash[classname] = 
438                                                                 util.functional.convert_object_list_to_hash(
439                                                                         obj.list[classname]
440                                                                 );
441                                                 }
442                                         } catch(E) {
443
444                                                 obj.error.sdump('D_ERROR',E + '\n');
445                                         }
446
447                                 }
448
449                                 try {
450                                         var level = obj.error.sdump_levels.D_SES_RESULT;
451                                         if (classname == 'aou' || classname == 'my_aou')
452                                                 obj.error.sdump_levels.D_SES_RESULT = false;
453                                         var robj = obj.network.request( app, method, params);
454                                         if (robj != null && typeof robj.ilsevent != 'undefined') {
455                                                 obj.error.standard_unexpected_error_alert('The staff client failed to retrieve expected data from this call, "' + method + '"',robj);
456                                                 throw(robj);
457                                         }
458                                         obj.list[classname] = robj == null ? [] : robj;
459                                         obj.error.sdump_levels.D_SES_RESULT = level;
460                                         convert();
461                                         obj.data_progress('Retrieved list for ' + classname + ' objects. ');
462
463                                 } catch(E) {
464                                         // if cacheable, try offline
465                                         if (cacheable) {
466                                                 /* FIXME -- we're going to revisit caching and do it differently
467                                                 try {
468                                                         var file = new util.file( classname );
469                                                         obj.list[classname] = file.get_object(); file.close();
470                                                         convert();
471                                                 } catch(E) {
472                                                         throw(E);
473                                                 }
474                                                 */
475                                                 throw(E); // for now
476                                         } else {
477                                                 throw(E); // for now
478                                         }
479                                 }
480                         }
481                 }
482
483                 this.chain = [];
484
485                 this.chain.push(
486                         function() {
487                                 try {
488                                         var robj = obj.network.simple_request('CIRC_MODIFIER_LIST',[]);
489                                         if (typeof robj.ilsevent != 'undefined') throw(robj);
490                                         obj.list.circ_modifier = robj;
491                                         obj.data_progress('Retrieved circ modifier list. ');
492                                 } catch(E) {
493                                         var error = 'Error: ' + js2JSON(E);
494                                         obj.error.sdump('D_ERROR',error);
495                                         throw(E);
496                                 }
497                         }
498                 );
499
500                 this.chain.push(
501                         function() {
502                                 var f = gen_fm_retrieval_func(
503                                         'cnal',
504                                         [
505                                                 api.FM_CNAL_RETRIEVE.app,
506                                                 api.FM_CNAL_RETRIEVE.method,
507                                                 [ obj.session.key ],
508                                                 false
509                                         ]
510                                 );
511                                 try {
512                                         f();
513                                 } catch(E) {
514                                         var error = 'Error: ' + js2JSON(E);
515                                         obj.error.sdump('D_ERROR',error);
516                                         throw(E);
517                                 }
518                         }
519                 );
520
521                 this.chain.push(
522                         function() {
523                                 var f = gen_fm_retrieval_func(
524                                         'csp',
525                                         [
526                                                 api.FM_CSP_PCRUD_SEARCH.app,
527                                                 api.FM_CSP_PCRUD_SEARCH.method,
528                                                 [ obj.session.key, {"id":{"!=":null}}, {"order_by":{"csp":"id"}} ],
529                                                 false
530                                         ]
531                                 );
532                                 try {
533                                         f();
534                                 } catch(E) {
535                                         var error = 'Error: ' + js2JSON(E);
536                                         obj.error.sdump('D_ERROR',error);
537                                         throw(E);
538                                 }
539                         }
540                 );
541
542                 this.chain.push(
543                         function() {
544                                 var f = gen_fm_retrieval_func(
545                                         'au',
546                                         [
547                                                 api.FM_AU_RETRIEVE_VIA_SESSION.app,
548                                                 api.FM_AU_RETRIEVE_VIA_SESSION.method,
549                                                 [ obj.session.key ],
550                                                 false
551                                         ]
552                                 );
553                                 try {
554                                         f();
555                                 } catch(E) {
556                                         var error = 'Error: ' + js2JSON(E);
557                                         obj.error.sdump('D_ERROR',error);
558                                         throw(E);
559                                 }
560                                 obj.list.au = [ obj.list.au ];
561                         }
562                 );
563
564                 this.chain.push(
565                         function() {
566                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
567                                 var f = gen_fm_retrieval_func(
568                                         'my_asv',
569                                         [
570                                                 api.FM_ASV_RETRIEVE_REQUIRED.app,
571                                                 api.FM_ASV_RETRIEVE_REQUIRED.method,
572                                                 [ obj.session.key ],
573                                                 true
574                                         ]
575                                 );
576                                 try {
577                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
578                                         f();
579                                 } catch(E) {
580                                         var error = 'Error: ' + js2JSON(E);
581                                         obj.error.sdump('D_ERROR',error);
582                                         throw(E);
583                                 }
584                         }
585                 );
586
587                 this.chain.push(
588                         function() {
589                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
590                                 var f = gen_fm_retrieval_func(
591                                         'asv',
592                                         [
593                                                 api.FM_ASV_RETRIEVE.app,
594                                                 api.FM_ASV_RETRIEVE.method,
595                                                 [ obj.session.key ],
596                                                 true
597                                         ]
598                                 );
599                                 try {
600                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
601                                         f();
602                                 } catch(E) {
603                                         var error = 'Error: ' + js2JSON(E);
604                                         obj.error.sdump('D_ERROR',error);
605                                         throw(E);
606                                 }
607                         }
608                 );
609
610                 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
611
612                 for (var i in this._fm_objects) {
613                         this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
614                 }
615
616                 // The previous org_tree call returned a tree, not a list or hash.
617                 this.chain.push(
618                         function () {
619                                 obj.tree.aou = obj.list.aou;
620                                 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
621                                 for (var i = 0; i < obj.list.aou.length; i++) {
622                                         var c = obj.list.aou[i].children();
623                                         if (!c) c = [];
624                                         c = c.sort(
625                                                 function( a, b ) {
626                                                         if (a.shortname() < b.shortname()) return -1;
627                                                         if (a.shortname() > b.shortname()) return 1;
628                                                         return 0;
629                                                 }
630                                         );
631                                         obj.list.aou[i].children( c );
632                                 }
633                                 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
634                                 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
635                         }
636                 );
637
638                 // The previous pgt call returned a tree, not a list or hash.
639                 this.chain.push(
640                         function () {
641                                 obj.tree.pgt = obj.list.pgt;
642                                 obj.list.pgt = util.fm_utils.flatten_ou_branch( obj.tree.pgt );
643                                 obj.hash.pgt = util.functional.convert_object_list_to_hash( obj.list.pgt );
644                         }
645                 );
646
647                 // Do these after we get the user object
648
649                 this.chain.push(
650                         function() {
651                                 try {
652                                         var robj = obj.network.simple_request('FM_AOUS_RETRIEVE',[ obj.session.key, obj.list.au[0].ws_ou() ]);
653                                         if (typeof robj.ilsevent != 'undefined') throw(robj);
654                                         obj.hash.aous = robj;
655                                         obj.data_progress('Retrieved org unit settings. ');
656                                 } catch(E) {
657                                         var error = 'Error: ' + js2JSON(E);
658                                         obj.error.sdump('D_ERROR',error);
659                                         throw(E);
660                                 }
661                         }
662                 );
663
664                 this.chain.push(
665
666                         function() {
667
668                                 gen_fm_retrieval_func('my_aou', 
669                                         [ 
670                                                 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
671                                                 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
672                                                 [ obj.session.key, obj.list.au[0].ws_ou() ], /* use ws_ou and not home_ou */
673                                                 true
674                                         ]
675                                 )();
676                         }
677                 );
678
679                 this.chain.push(
680
681                         function () {
682
683                                 gen_fm_retrieval_func( 'my_actsc', 
684                                         [ 
685                                                 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
686                                                 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
687                                                 [ obj.session.key, obj.list.au[0].ws_ou() ],
688                                                 true
689                                         ]
690                                 )();
691                         }
692                 );
693
694                 this.chain.push(
695
696                         function () {
697
698                                 gen_fm_retrieval_func( 'my_asc', 
699                                         [ 
700                                                 api.FM_ASC_RETRIEVE_VIA_AOU.app,
701                                                 api.FM_ASC_RETRIEVE_VIA_AOU.method,
702                                                 [ obj.session.key, obj.list.au[0].ws_ou() ],
703                                                 true
704                                         ]
705                                 )();
706                         }
707                 );
708
709
710                 this.chain.push(
711                         function() {
712                                 var f = gen_fm_retrieval_func(
713                                         'cnct',
714                                         [
715                                                 api.FM_CNCT_RETRIEVE.app,
716                                                 api.FM_CNCT_RETRIEVE.method,
717                                                 [ obj.list.au[0].ws_ou() ], 
718                                                 false
719                                         ]
720                                 );
721                                 try {
722                                         f();
723                                 } catch(E) {
724                                         var error = 'Error: ' + js2JSON(E);
725                                         obj.error.sdump('D_ERROR',error);
726                                         throw(E);
727                                 }
728                         }
729                 );
730
731                 this.chain.push(
732                         function() {
733                                 var f = gen_fm_retrieval_func(
734                                         'my_cnct',
735                                         [
736                                                 api.FM_CNCT_RETRIEVE.app,
737                                                 api.FM_CNCT_RETRIEVE.method,
738                                                 [ obj.list.au[0].ws_ou() ], 
739                                                 false
740                                         ]
741                                 );
742                                 try {
743                                         f();
744                                 } catch(E) {
745                                         var error = 'Error: ' + js2JSON(E);
746                                         obj.error.sdump('D_ERROR',error);
747                                         throw(E);
748                                 }
749                         }
750                 );
751
752
753                 this.chain.push(
754                         function() {
755                                 var f = gen_fm_retrieval_func(
756                                         'acpl',
757                                         [
758                                                 api.FM_ACPL_RETRIEVE.app,
759                                                 api.FM_ACPL_RETRIEVE.method,
760                                                 [ obj.list.au[0].ws_ou() ],
761                                                 false
762                                         ]
763                                 );
764                                 try {
765                                         f();
766                                 } catch(E) {
767                                         var error = 'Error: ' + js2JSON(E);
768                                         obj.error.sdump('D_ERROR',error);
769                                         throw(E);
770                                 }
771                         }
772                 );
773
774                 this.chain.push(
775                         function() {
776                                 var f = gen_fm_retrieval_func(
777                                         'cbt',
778                                         [
779                                                 api.FM_CBT_RETRIEVE.app,
780                                                 api.FM_CBT_RETRIEVE.method,
781                                                 [ obj.session.key, obj.list.au[0].ws_ou() ],
782                                                 false
783                                         ]
784                                 );
785                                 try {
786                                         f();
787                                 } catch(E) {
788                                         var error = 'Error: ' + js2JSON(E);
789                                         obj.error.sdump('D_ERROR',error);
790                                         throw(E);
791                                 }
792                         }
793                 );
794
795                 if (typeof this.on_complete == 'function') {
796
797                         this.chain.push( this.on_complete );
798                 }
799                 JSAN.use('util.exec'); this.exec = new util.exec();
800                 this.exec.on_error = function(E) { 
801                 
802                         if (typeof obj.on_error == 'function') {
803                                 return obj.on_error(E); /* false breaks chain */
804                         } else {
805                                 alert('oops: ' + E ); 
806                             return false; /* break chain */
807                         }
808
809                 }
810
811                 this.exec.chain( this.chain );
812
813         }
814 }
815
816 dump('exiting OpenILS/data.js\n');