]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js
print bills with titles from main billing 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' ? ' = ' + js2JSON(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',[ 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
510                 this.chain.push(
511                         function() {
512                                 var f = gen_fm_retrieval_func(
513                                         'cnal',
514                                         [
515                                                 api.FM_CNAL_RETRIEVE.app,
516                                                 api.FM_CNAL_RETRIEVE.method,
517                                                 [ obj.session.key ],
518                                                 false
519                                         ]
520                                 );
521                                 try {
522                                         f();
523                                 } catch(E) {
524                                         var error = 'Error: ' + js2JSON(E);
525                                         obj.error.sdump('D_ERROR',error);
526                                         throw(E);
527                                 }
528                         }
529                 );
530
531                 this.chain.push(
532                         function() {
533                                 var f = gen_fm_retrieval_func(
534                                         'au',
535                                         [
536                                                 api.FM_AU_RETRIEVE_VIA_SESSION.app,
537                                                 api.FM_AU_RETRIEVE_VIA_SESSION.method,
538                                                 [ obj.session.key ],
539                                                 false
540                                         ]
541                                 );
542                                 try {
543                                         f();
544                                 } catch(E) {
545                                         var error = 'Error: ' + js2JSON(E);
546                                         obj.error.sdump('D_ERROR',error);
547                                         throw(E);
548                                 }
549                                 obj.list.au = [ obj.list.au ];
550                         }
551                 );
552
553                 this.chain.push(
554                         function() {
555                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
556                                 var f = gen_fm_retrieval_func(
557                                         'my_asv',
558                                         [
559                                                 api.FM_ASV_RETRIEVE_REQUIRED.app,
560                                                 api.FM_ASV_RETRIEVE_REQUIRED.method,
561                                                 [ obj.session.key ],
562                                                 true
563                                         ]
564                                 );
565                                 try {
566                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
567                                         f();
568                                 } catch(E) {
569                                         var error = 'Error: ' + js2JSON(E);
570                                         obj.error.sdump('D_ERROR',error);
571                                         throw(E);
572                                 }
573                         }
574                 );
575
576                 this.chain.push(
577                         function() {
578                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
579                                 var f = gen_fm_retrieval_func(
580                                         'asv',
581                                         [
582                                                 api.FM_ASV_RETRIEVE.app,
583                                                 api.FM_ASV_RETRIEVE.method,
584                                                 [ obj.session.key ],
585                                                 true
586                                         ]
587                                 );
588                                 try {
589                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
590                                         f();
591                                 } catch(E) {
592                                         var error = 'Error: ' + js2JSON(E);
593                                         obj.error.sdump('D_ERROR',error);
594                                         throw(E);
595                                 }
596                         }
597                 );
598
599                 obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
600
601                 for (var i in this._fm_objects) {
602                         this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
603                 }
604
605                 // The previous org_tree call returned a tree, not a list or hash.
606                 this.chain.push(
607                         function () {
608                                 obj.tree.aou = obj.list.aou;
609                                 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
610                                 for (var i = 0; i < obj.list.aou.length; i++) {
611                                         var c = obj.list.aou[i].children();
612                                         if (!c) c = [];
613                                         c = c.sort(
614                                                 function( a, b ) {
615                                                         if (a.shortname() < b.shortname()) return -1;
616                                                         if (a.shortname() > b.shortname()) return 1;
617                                                         return 0;
618                                                 }
619                                         );
620                                         obj.list.aou[i].children( c );
621                                 }
622                                 obj.list.aou = util.fm_utils.flatten_ou_branch( obj.tree.aou );
623                                 obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
624                         }
625                 );
626
627                 // The previous pgt call returned a tree, not a list or hash.
628                 this.chain.push(
629                         function () {
630                                 obj.tree.pgt = obj.list.pgt;
631                                 obj.list.pgt = util.fm_utils.flatten_ou_branch( obj.tree.pgt );
632                                 obj.hash.pgt = util.functional.convert_object_list_to_hash( obj.list.pgt );
633                         }
634                 );
635
636                 // Do this after we get the user object
637                 this.chain.push(
638
639                         function() {
640
641                                 gen_fm_retrieval_func('my_aou', 
642                                         [ 
643                                                 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.app,
644                                                 api.FM_AOU_RETRIEVE_RELATED_VIA_SESSION.method,
645                                                 [ obj.session.key, obj.list.au[0].ws_ou() ], /* use ws_ou and not home_ou */
646                                                 true
647                                         ]
648                                 )();
649                         }
650                 );
651
652                 this.chain.push(
653
654                         function () {
655
656                                 gen_fm_retrieval_func( 'my_actsc', 
657                                         [ 
658                                                 api.FM_ACTSC_RETRIEVE_VIA_AOU.app,
659                                                 api.FM_ACTSC_RETRIEVE_VIA_AOU.method,
660                                                 [ obj.session.key, obj.list.au[0].ws_ou() ],
661                                                 true
662                                         ]
663                                 )();
664                         }
665                 );
666
667                 this.chain.push(
668
669                         function () {
670
671                                 gen_fm_retrieval_func( 'my_asc', 
672                                         [ 
673                                                 api.FM_ASC_RETRIEVE_VIA_AOU.app,
674                                                 api.FM_ASC_RETRIEVE_VIA_AOU.method,
675                                                 [ obj.session.key, obj.list.au[0].ws_ou() ],
676                                                 true
677                                         ]
678                                 )();
679                         }
680                 );
681
682
683                 this.chain.push(
684                         function() {
685                                 var f = gen_fm_retrieval_func(
686                                         'cnct',
687                                         [
688                                                 api.FM_CNCT_RETRIEVE.app,
689                                                 api.FM_CNCT_RETRIEVE.method,
690                                                 [ obj.list.au[0].ws_ou() ], 
691                                                 false
692                                         ]
693                                 );
694                                 try {
695                                         f();
696                                 } catch(E) {
697                                         var error = 'Error: ' + js2JSON(E);
698                                         obj.error.sdump('D_ERROR',error);
699                                         throw(E);
700                                 }
701                         }
702                 );
703
704                 this.chain.push(
705                         function() {
706                                 var f = gen_fm_retrieval_func(
707                                         'acpl',
708                                         [
709                                                 api.FM_ACPL_RETRIEVE.app,
710                                                 api.FM_ACPL_RETRIEVE.method,
711                                                 [ obj.list.au[0].ws_ou() ],
712                                                 false
713                                         ]
714                                 );
715                                 try {
716                                         f();
717                                 } catch(E) {
718                                         var error = 'Error: ' + js2JSON(E);
719                                         obj.error.sdump('D_ERROR',error);
720                                         throw(E);
721                                 }
722                         }
723                 );
724
725
726
727                 if (typeof this.on_complete == 'function') {
728
729                         this.chain.push( this.on_complete );
730                 }
731                 JSAN.use('util.exec'); this.exec = new util.exec();
732                 this.exec.on_error = function(E) { 
733                 
734                         if (typeof obj.on_error == 'function') {
735                                 obj.on_error();
736                         } else {
737                                 alert('oops: ' + E ); 
738                         }
739
740                         return false; /* break chain */
741                 }
742
743                 this.exec.chain( this.chain );
744
745         }
746 }
747
748 dump('exiting OpenILS/data.js\n');