]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/offline_manage_xacts.js
'Print Export' is a non-templated print option that prints the csv dump for a list...
[Evergreen.git] / Open-ILS / xul / staff_client / server / admin / offline_manage_xacts.js
1 dump('entering admin/offline_manage_xacts.js\n');
2
3 if (typeof admin == 'undefined') admin = {};
4 admin.offline_manage_xacts = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8 }
9
10 admin.offline_manage_xacts.prototype = {
11
12         'sel_list' : [],
13         'seslist' : [],
14         'sel_errors' : [],
15
16         'init' : function( params ) {
17
18                 var obj = this;
19
20                 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
21
22                 obj.init_list(); obj.init_script_list(); obj.init_error_list();
23
24                 obj.retrieve_seslist(); obj.render_seslist();
25
26                 var x = document.getElementById('create');
27                 if (obj.check_perm(['OFFLINE_UPLOAD'])) {
28                         x.disabled = false;
29                         x.addEventListener('command',function() { try{obj.create_ses();}catch(E){alert(E);} },false);
30                 }
31
32                 x = obj.$('upload');
33                 x.addEventListener('command',function() { try{obj.upload();}catch(E){alert(E);} },false);
34
35                 x = obj.$('refresh');
36                 x.addEventListener('command',function() { try{$('deck').selectedIndex=0;obj.retrieve_seslist();obj.render_seslist();}catch(E){alert(E);} },false);
37
38                 x = obj.$('execute');
39                 x.addEventListener('command',function() { try{obj.execute_ses();}catch(E){alert(E);} },false);
40
41                 x = obj.$('retrieve_item');
42                 x.addEventListener('command',function() { try{obj.retrieve_item();}catch(E){alert(E);} },false);
43
44                 x = obj.$('retrieve_patron');
45                 x.addEventListener('command',function() { try{obj.retrieve_patron();}catch(E){alert(E);} },false);
46
47                 x = obj.$('retrieve_details');
48                 x.addEventListener('command',function() { try{obj.retrieve_details();}catch(E){alert(E);} },false);
49
50                 obj.$('deck').selectedIndex = 0;
51         },
52
53         '$' : function(id) { return document.getElementById(id); },
54
55         'init_list' : function() {
56                 var obj = this; JSAN.use('util.list'); JSAN.use('util.date'); JSAN.use('patron.util');
57                 obj.list = new util.list('session_tree');
58                 obj.list.init( {
59                         'columns' : [
60                                 {
61                                         'id' : 'org', 'hidden' : 'true', 'flex' : '1',
62                                         'label' : 'Organization',
63                                         'render' : function(my) { return obj.data.hash.aou[ my.org ].shortname(); },
64                                 },
65                                 { 
66                                         'id' : 'description', 'flex' : '2',
67                                         'label' : 'Description', 
68                                         'render' : function(my) { return my.description; },
69                                 },
70                                 {
71                                         'id' : 'create_time', 'flex' : '1',
72                                         'label' : 'Date Created',
73                                         'render' : function(my) { if (my.create_time) { var x = new Date(); x.setTime(my.create_time+"000"); return util.date.formatted_date(x,"%F %H:%M"); } else { return ""; }; },
74                                 },
75                                 {
76                                         'id' : 'creator', 'flex' : '1', 'hidden' : 'true',
77                                         'label' : 'Created By',
78                                         'render' : function(my) { var staff_obj = patron.util.retrieve_name_via_id( ses(), my.creator ); return staff_obj[0] + " @ " + obj.data.hash.aou[ staff_obj[3] ].shortname(); },
79                                 },
80                                 { 
81                                         'id' : 'count', 'flex' : '1',
82                                         'label' : 'Upload Count', 
83                                         'render' : function(my) { return my.scripts.length; },
84                                 },
85                                 { 
86                                         'id' : 'num_complete', 'flex' : '1', 
87                                         'label' : 'Transactions Processed', 
88                                         'render' : function(my) { return my.num_complete; },
89                                 },
90                                 { 
91                                         'id' : 'in_process', 'flex' : '1',
92                                         'label' : 'Processing?', 
93                                         'render' : function(my) { if (my.end_time) { return 'Completed' } else { return get_bool(my.in_process) ? 'Yes' : 'No'}; },
94                                 },
95                                 {
96                                         'id' : 'start_time', 'flex' : '1', 'hidden' : 'true',
97                                         'label' : 'Date Started',
98                                         'render' : function(my) { if (my.start_time) {var x = new Date(); x.setTime(my.start_time+"000"); return util.date.formatted_date(x,"%F %H:%M");} else { return ""; }; },
99                                 },
100                                 {
101                                         'id' : 'end_time', 'flex' : '1',
102                                         'label' : 'Date Completed',
103                                         'render' : function(my) { if (my.end_time) {var x = new Date(); x.setTime(my.end_time+"000"); return util.date.formatted_date(x,"%F %H:%M");} else { return ""; }; },
104                                 },
105                                 { 
106                                         'id' : 'key', 'hidden' : 'true', 'flex' : '1', 
107                                         'label' : 'Session', 
108                                         'render' : function(my) { return my.key; },
109                                 },
110                         ],
111                         'map_row_to_columns' : patron.util.std_map_row_to_columns(),
112                         'on_select' : function(ev) {
113                                 try {
114                                         $('deck').selectedIndex = 0;
115                                         $('execute').disabled = true;
116                                         $('upload').disabled = true;
117                                         setTimeout(
118                                                 function() {
119                                                         try {
120                                                                 JSAN.use('util.functional');
121                                                                 var sel = obj.list.retrieve_selection();
122                                                                 obj.sel_list = util.functional.map_list(
123                                                                         sel,
124                                                                         function(o) { return o.getAttribute('retrieve_id'); }
125                                                                 );
126                                                                 if (obj.sel_list.length == 0) return;
127                                                                 {       
128                                                                         var upload = true; var process = true;
129
130                                                                         if (obj.sel_list.length > 1) upload = false;
131
132                                                                         if (obj.seslist[ obj.sel_list[0] ].end_time) {
133                                                                                 upload = false; process = false;
134                                                                         }
135                                                                         if (obj.seslist[ obj.sel_list[0] ].in_process == 1) {
136                                                                                 upload = false; process = false;
137                                                                         }
138
139                                                                         /* should we really have this next restriction? */
140                                                                         for (var i = 0; i < obj.seslist[ obj.sel_list[0] ].scripts.length; i++) {
141                                                                                 if (obj.seslist[ obj.sel_list[0] ].scripts[i].workstation ==
142                                                                                         obj.data.ws_name ) upload = false;
143                                                                         }
144
145                                                                         if (upload) {
146                                                                                 if (obj.check_perm(['OFFLINE_UPLOAD'])) {
147                                                                                         document.getElementById('upload').disabled = false;
148                                                                                 }
149                                                                         } else {
150                                                                                 document.getElementById('upload').disabled = true;
151                                                                         }
152                                                                         if (process) {
153                                                                                 if (obj.check_perm(['OFFLINE_EXECUTE'])) {
154                                                                                         document.getElementById('execute').disabled = false;    
155                                                                                 }
156                                                                         } else {
157                                                                                 document.getElementById('execute').disabled = true;     
158                                                                         }
159                                                                 }
160                                                                 var complete = false;
161                                                                 for (var i = 0; i < obj.sel_list.length; i++) { 
162                                                                         if (obj.seslist[ obj.sel_list[i] ].end_time) { complete = true; }
163                                                                 }
164                                                                 if (complete) {
165                                                                         obj.render_errorlist();
166                                                                 } else {
167                                                                         if (obj.seslist[ obj.sel_list[0] ].in_process == 1) {
168                                                                                 obj.render_status();
169                                                                         } else {
170                                                                                 obj.render_scriptlist();
171                                                                         }
172                                                                 }
173                                                         } catch(E) {
174                                                                 alert('on_select: ' + E);
175                                                         }
176                                                 }, 0
177                                         );
178                                 } catch(E) {
179                                         alert('on_select:\nobj.seslist.length = ' + obj.seslist.length + '  obj.sel_list.length = ' + obj.sel_list.length + '\nerror: ' + E);
180                                 }
181                         },
182                 } );
183
184
185         },
186
187         'init_script_list' : function() {
188                 var obj = this; JSAN.use('util.list'); JSAN.use('util.date'); JSAN.use('patron.util');
189                 obj.script_list = new util.list('script_tree');
190                 obj.script_list.init( {
191                         'columns' : [
192                                 {
193                                         'id' : 'create_time', 'flex' : '1',
194                                         'label' : 'Date Uploaded',
195                                         'render' : function(my) { if (my.create_time) { var x = new Date(); x.setTime(my.create_time+"000"); return util.date.formatted_date(x,"%F %H:%M"); } else { return ""; }; },
196                                 },
197                                 {
198                                         'id' : 'requestor', 'flex' : '1', 'hidden' : 'true',
199                                         'label' : 'Uploaded By',
200                                         'render' : function(my) { var staff_obj = patron.util.retrieve_name_via_id( ses(), my.requestor ); return staff_obj[0] + " @ " + obj.data.hash.aou[ staff_obj[3] ].shortname(); },
201                                 },
202                                 { 
203                                         'id' : 'time_delta', 'hidden' : 'true', 'flex' : '1', 
204                                         'label' : 'Server/Local Time Delta', 
205                                         'render' : function(my) { return my.time_delta; },
206                                 },
207                                 { 
208                                         'id' : 'workstation', 'flex' : '1', 
209                                         'label' : 'Workstation', 
210                                         'render' : function(my) { return my.workstation; },
211                                 },
212                         ],
213                         'map_row_to_columns' : patron.util.std_map_row_to_columns(),
214                 } );
215
216
217         },
218
219         'init_error_list' : function() {
220                 var obj = this; JSAN.use('util.list');  JSAN.use('util.date'); JSAN.use('patron.util'); JSAN.use('util.functional');
221                 obj.error_list = new util.list('error_tree');
222                 obj.error_list.init( {
223                         'columns' : [
224                                 {
225                                         'id' : 'workstation', 'flex' : '1',
226                                         'label' : 'Workstation',
227                                         'render' : function(my) { return my.command._workstation ? my.command._workstation : my.command._worksation; },
228                                 },
229                                 {
230                                         'id' : 'timestamp', 'flex' : '1',
231                                         'label' : 'Timestamp',
232                                         'render' : function(my) { if (my.command.timestamp) { var x = new Date(); x.setTime(my.command.timestamp+"000"); return util.date.formatted_date(x,"%F %H:%M"); } else { return my.command._realtime; }; },
233                                 },
234                                 {
235                                         'id' : 'type', 'flex' : '1',
236                                         'label' : 'Type',
237                                         'render' : function(my) { return my.command.type; },
238                                 },
239                                 { 
240                                         'id' : 'ilsevent', 'hidden' : 'true', 'flex' : '1', 
241                                         'label' : 'Event Code', 
242                                         'render' : function(my) { return my.event.ilsevent; },
243                                 },
244                                 { 
245                                         'id' : 'textcode', 'flex' : '1', 
246                                         'label' : 'Event Name', 
247                                         'render' : function(my) { return typeof my.event.textcode != 'undefined' ? my.event.textcode : util.functional.map_list( my.event, function(o) { return o.textcode; }).join('/'); },
248                                 },
249                                 {
250                                         'id' : 'desc', 'flex' : '1', 'hidden' : 'true',
251                                         'label' : 'Event Description',
252                                         'render' : function(my) { return my.event.desc; },
253                                 },
254                                 {
255                                         'id' : 'i_barcode', 'flex' : '1',
256                                         'label' : 'Item Barcode',
257                                         'render' : function(my) { return my.command.barcode ? my.command.barcode : ""; },
258                                 },
259                                 {
260                                         'id' : 'p_barcode', 'flex' : '1',
261                                         'label' : 'Patron Barcode',
262                                         'render' : function(my) { if (my.command.patron_barcode) { return my.command.patron_barcode; } else { if (my.command.user.card.barcode) { return my.command.user.card.barcode; } else { return ""; } }; },
263                                 },
264                                 {
265                                         'id' : 'duedate', 'flex' : '1', 'hidden' : 'true',
266                                         'label' : 'Due Date',
267                                         'render' : function(my) { return my.command.due_date || ""; },
268                                 },
269                                 {
270                                         'id' : 'backdate', 'flex' : '1', 'hidden' : 'true',
271                                         'label' : 'Check In Backdate',
272                                         'render' : function(my) { return my.command.backdate || ""; },
273                                 },
274                                 {
275                                         'id' : 'count', 'flex' : '1', 'hidden' : 'true',
276                                         'label' : 'In House Use Count',
277                                         'render' : function(my) { return my.command.count || ""; },
278                                 },
279                                 {
280                                         'id' : 'noncat', 'flex' : '1', 'hidden' : 'true',
281                                         'label' : 'Non-Cataloged?',
282                                         'render' : function(my) { return get_bool(my.command.noncat) ? "Yes" : "No"; },
283                                 },
284                                 {
285                                         'id' : 'noncat_type', 'flex' : '1', 'hidden' : 'true',
286                                         'label' : 'Non-Cataloged Type',
287                                         'render' : function(my) { return data.hash.cnct[ my.command.noncat_type ] ? obj.data.hash.cnct[ my.command.noncat_type ].name() : ""; },
288                                 },
289                                 {
290                                         'id' : 'noncat_count', 'flex' : '1', 'hidden' : 'true',
291                                         'label' : 'Non-Cataloged Count',
292                                         'render' : function(my) { return my.command.noncat_count || ""; },
293                                 },
294                         ],
295                         'map_row_to_columns' : patron.util.std_map_row_to_columns(),
296                         'on_select' : function(ev) {
297                                 try {
298                                         var sel = obj.error_list.retrieve_selection();
299                                         obj.sel_errors = util.functional.map_list(
300                                                 sel,
301                                                 function(o) { return o.getAttribute('retrieve_id'); }
302                                         );
303                                         if (obj.sel_errors.length > 0) {
304                                                 obj.$('retrieve_item').disabled = false;
305                                                 obj.$('retrieve_patron').disabled = false;
306                                                 obj.$('retrieve_details').disabled = false;
307                                         } else {
308                                                 obj.$('retrieve_item').disabled = true;
309                                                 obj.$('retrieve_patron').disabled = true;
310                                                 obj.$('retrieve_details').disabled = true;
311                                         }
312                                 } catch(E) {
313                                         alert(E);
314                                 }
315                         }
316                 } );
317
318                 var export_button = document.getElementById('export_btn');
319                 if (export_button) export_button.addEventListener(
320                         'command',
321                         function(ev) {
322                                 try {
323                                         obj.error_list.on_all_fleshed =
324                                                 function() {
325                                                         try {
326                                                                 dump( obj.error_list.dump_csv() + '\n' );
327                                                                 copy_to_clipboard(obj.error_list.dump_csv());
328                                                                 setTimeout(function(){ obj.error_list.on_all_fleshed = null; },0);
329                                                         } catch(E) {
330                                                                 obj.error.standard_unexpected_error_alert('export',E); 
331                                                         }
332                                                 }
333                                         obj.error_list.full_retrieve();
334                                 } catch(E) {
335                                         obj.error.standard_unexpected_error_alert('export',E); 
336                                 }
337                         },
338                         false
339                 );
340                 
341                 var print_export_button = document.getElementById('print_export_btn');
342                 if (print_export_button) print_export_button.addEventListener(
343                         'command',
344                         function(ev) {
345                                 try {
346                                         obj.error_list.on_all_fleshed =
347                                                 function() {
348                                                         try {
349                                                                 dump( obj.error_list.dump_csv() + '\n' );
350                                                                 //copy_to_clipboard(obj.error_list.dump_csv());
351                                                                 JSAN.use('util.print'); var p = new util.print();
352                                                                 p.simple( obj.error_list.dump_csv(), { 'content_type' : 'text/plain' } );
353                                                                 setTimeout(function(){ obj.error_list.on_all_fleshed = null; },0);
354                                                         } catch(E) {
355                                                                 obj.error.standard_unexpected_error_alert('export',E); 
356                                                         }
357                                                 }
358                                         obj.error_list.full_retrieve();
359                                 } catch(E) {
360                                         obj.error.standard_unexpected_error_alert('print export',E); 
361                                 }
362                         },
363                         false
364                 );
365
366         },
367
368         'check_perm' : function(perms) {
369                 var obj = this;
370                 var robj = obj.network.simple_request('PERM_CHECK',[ses(),obj.data.list.au[0].id(),obj.data.list.au[0].ws_ou(),perms]);
371                 if (typeof robj.ilsevent != 'undefined') {
372                         obj.error.standard_unexpected_error_alert('check permission',E);
373                         return false;
374                 }
375                 return robj.length == 0 ? true : false;
376         },
377
378         'execute_ses' : function() {
379                 var obj = this;
380
381                 clear_the_cache();
382                 obj.data.stash_retrieve();
383
384                 for (var i = 0; i < obj.sel_list.length; i++) {
385
386                         var url  = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI)
387                                 + "?ses=" + window.escape(ses())
388                                 + "&action=execute" 
389                                 + "&seskey=" + window.escape(obj.seslist[obj.sel_list[i]].key)
390                                 + "&ws=" + window.escape(obj.data.ws_name);
391                         var x = new XMLHttpRequest();
392                         x.open("GET",url,false);
393                         x.send(null);
394
395                         dump(url + ' = ' + x.responseText + '\n' );
396                         var robj = JSON2js(x.responseText);
397
398                         if (robj.ilsevent != 0) { alert('Execute error: ' + x.responseText); }
399
400                         obj.retrieve_seslist(); obj.render_seslist();
401                 }
402         },
403
404         'ses_errors' : function() {
405                 var obj = this;
406
407                 clear_the_cache();
408                 obj.data.stash_retrieve();
409
410                 var url  = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI)
411                         + "?ses=" + window.escape(ses())
412                         + "&action=status" 
413                         + "&seskey=" + window.escape(obj.seslist[ obj.sel_list[0] ].key)
414                         + "&ws=" + window.escape(obj.data.ws_name)
415                         + '&status_type=exceptions';
416                 var x = new XMLHttpRequest();
417                 x.open("GET",url,false);
418                 x.send(null);
419
420                 dump(url + ' = ' + x.responseText + '\n' );
421                 var robj = JSON2js(x.responseText);
422
423                 return { 'errors' : robj, 'description' : obj.seslist[ obj.sel_list[0] ].description };
424
425         },
426
427         'rename_file' : function() {
428                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
429                 var obj = this;
430                 JSAN.use('util.file'); 
431                 var pending = new util.file('pending_xacts');
432                 if ( !pending._file.exists() ) { throw("Can't rename a non-existent file"); }
433                 obj.transition_filename = 'pending_xacts_' + new Date().getTime();
434                 var count = 0;
435                 var file = new util.file(obj.transition_filename);
436                 while (file._file.exists()) {
437                         obj.transition_filename = 'pending_xacts_' + new Date().getTime();
438                         file = new util.file(obj.transition_filename);
439                         if (count++>100) throw("Taking too long to find a unique filename.");
440                 }
441                 pending._file.moveTo(null,obj.transition_filename);
442         },
443
444         'revert_file' : function() {
445                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
446                 var obj = this;
447                 JSAN.use('util.file');
448                 var pending = new util.file('pending_xacts');
449                 if (pending._file.exists()) { obj.error.yns_alert('Something bad happened.  New offline transactions were accumulated during our attempted upload.  Tell your system admin that the file involved is ' + obj.transition_filename,'Scary Error','Ok',null,null,'Check here to confirm this message'); return; }
450                 var file = new util.file(obj.transition_filename);
451                 file._file.moveTo(null,'pending_xacts');
452         },
453
454         'archive_file' : function() {
455                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
456                 var obj = this;
457                 JSAN.use('util.file');
458                 var file = new util.file(obj.transition_filename);
459                 if (file._file.exists()) file._file.moveTo(null,obj.transition_filename + '.complete')
460         },
461
462         'upload' : function() {
463                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
464                 var obj = this;
465                 if (obj.sel_list.length == 0) { alert('Please select a session to upload to.'); return; }
466                 if (obj.sel_list.length > 1) { alert('Please select a single session to upload to.'); return; }
467
468                 JSAN.use('util.file');
469
470                 var file = new util.file('pending_xacts');
471                 if (!file._file.exists()) { alert('No pending transactions to upload.'); return; }
472
473                 obj.rename_file();
474
475                 obj.data.stash_retrieve();
476                 var seskey = obj.seslist[ obj.sel_list[0] ].key;
477                 JSAN.use('util.widgets');
478                 var xx = document.getElementById('iframe_placeholder'); util.widgets.remove_children(xx);
479                 var x = document.createElement('iframe'); xx.appendChild(x); x.flex = 1;
480                 x.setAttribute(
481                         'src',
482                         window.xulG.url_prefix( urls.XUL_REMOTE_BROWSER )
483                         + '?url=' + window.escape(
484                                 urls.XUL_OFFLINE_UPLOAD_XACTS
485                                 + '?ses=' + window.escape(ses())
486                                 + '&seskey=' + window.escape(seskey)
487                                 + '&ws=' + window.escape(obj.data.ws_name)
488                                 + '&delta=' + window.escape('0')
489                                 + '&filename=' + window.escape( obj.transition_filename )
490                         )
491                 );
492                 var newG = { 
493                         'url_prefix' : window.xulG.url_prefix, 
494                         'passthru_content_params' : {
495                                 'url_prefix' : window.xulG.url_prefix,
496                                 'handle_event' : function(robj){
497                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
498                                         try {
499                                                 dump('robj = ' + js2JSON(robj) + '\n');
500                                                 if ( robj.ilsevent != 0 ) {
501                                                         obj.revert_file();
502                                                         alert('There was an error:\n' + js2JSON(robj));
503                                                 } else {
504                                                         obj.archive_file();
505                                                 }
506                                                 obj.retrieve_seslist(); obj.render_seslist();
507                                                 setTimeout(
508                                                         function() {
509                                                                 JSAN.use('util.widgets');
510                                                                 util.widgets.remove_children('iframe_placeholder');
511                                                         },0
512                                                 );
513                                         } catch(E) {
514                                                 alert('handle_event error: ' + E);
515                                         }
516                                 } 
517                         }
518                 };
519                 x.contentWindow.xulG = newG;
520         },
521
522         'ses_status' : function() {
523                 var obj = this;
524
525                 clear_the_cache();
526                 obj.data.stash_retrieve();
527
528                 var url  = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI)
529                         + "?ses=" + window.escape(ses())
530                         + "&action=status" 
531                         + "&seskey=" + window.escape(obj.seslist[obj.sel_list[0]].key)
532                         + "&ws=" + window.escape(obj.data.ws_name)
533                         + "&status_type=scripts";
534                 var x = new XMLHttpRequest();
535                 x.open("GET",url,false);
536                 x.send(null);
537
538                 dump(url + ' = ' + x.responseText + '\n' );
539                 var robj = JSON2js(x.responseText);
540
541                 return robj;
542         },
543
544         'create_ses' : function() {
545
546                 var obj = this;
547
548                 var desc = window.prompt('Please enter a description:','','Create an Offline Transaction Session');
549                 if (desc=='' || desc==null) { return; }
550
551                 clear_the_cache();
552                 obj.data.stash_retrieve();
553
554                 var url  = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI)
555                         + "?ses=" + window.escape(ses())
556                         + "&action=create" 
557                         + "&desc=" + window.escape(desc)
558                         + "&ws=" + window.escape(obj.data.ws_name);
559                 var x = new XMLHttpRequest();
560                 x.open("GET",url,false);
561                 x.send(null);
562
563                 dump(url + ' = ' + x.responseText + '\n' );
564                 var robj = JSON2js(x.responseText);
565                 if (robj.ilsevent == 0) {
566                         obj.retrieve_seslist(); obj.render_seslist();
567                 } else {
568                         alert('Error: ' + x.responseText);
569                 }
570         },
571
572         'retrieve_seslist' : function() {
573
574                 var obj = this;
575
576                 try {
577
578                         clear_the_cache();
579                         obj.data.stash_retrieve();
580
581                         var url = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI) 
582                                 + "?ses=" + window.escape(ses())
583                                 + "&action=status"
584                                 + "&org=" + window.escape(obj.data.list.au[0].ws_ou())
585                                 + "&status_type=sessions";
586                         var x = new XMLHttpRequest();
587                         x.open("GET",url,false);
588                         x.send(null);
589
590                         dump(url + ' = ' + x.responseText + '\n' );
591
592                         var robj = JSON2js( x.responseText );
593                         if (typeof robj.ilsevent != 'undefined') throw(robj);
594
595                         obj.seslist = robj.sort(
596                                 function(a,b) {
597                                         return b.create_time - a.create_time;
598                                 }
599                         );
600
601                 } catch(E) {
602                         obj.error.standard_unexpected_error_alert('Error retrieving offline sessions.',E);
603                 }
604         },
605
606         'render_seslist' : function() {
607
608                 var obj = this;
609
610                 var old_idx = obj.list.node.currentIndex;
611                 if (old_idx < 0) old_idx = 0;
612
613                 obj.list.clear();
614
615                 var funcs = [];
616                 for (var i = 0; i < obj.seslist.length; i++) {
617                         funcs.push( 
618                                 function(idx,row){ 
619                                         return function(){
620                                                 obj.list.append( { 'retrieve_id' : idx, 'row' : row } );
621                                                 if (idx == old_idx) obj.list.node.view.selection.select(idx);
622                                         };
623                                 }(i,{ 'my' : obj.seslist[i] }) 
624                         );
625                 }
626
627                 JSAN.use('util.exec'); var exec = new util.exec();
628                 exec.chain( funcs );
629
630                 document.getElementById('execute').disabled = true;
631                 document.getElementById('upload').disabled = true;
632
633         },
634
635         'render_scriptlist' : function() {
636
637                 dump('render_scriptlist\n');
638
639                 document.getElementById('deck').selectedIndex = 1;
640
641                 var obj = this;
642
643                 obj.script_list.clear();
644
645                 var status = obj.ses_status();
646                 document.getElementById('status_caption').setAttribute('label','Uploaded Transactions for ' + status.description);
647
648                 var scripts = status.scripts;
649
650                 var funcs = [];
651                 for (var i = 0; i < scripts.length; i++) {
652                         funcs.push( 
653                                 function(row){ 
654                                         return function(){
655                                                 obj.script_list.append( { 'row' : row } );
656                                         };
657                                 }({ 'my' : scripts[i] }) 
658                         );
659                 }
660                 JSAN.use('util.exec'); var exec = new util.exec();
661                 exec.chain( funcs );
662         },
663         
664         'render_errorlist' : function() {
665
666                 dump('render_errorlist\n');
667
668                 document.getElementById('deck').selectedIndex = 2;
669
670                 var obj = this;
671
672                 obj.error_list.clear();
673
674                 var error_meta = obj.ses_errors();
675                 document.getElementById('errors_caption').setAttribute('label','Exceptions for ' + error_meta.description);
676
677                 obj.errors = error_meta.errors;
678
679                 var funcs = [];
680                 for (var i = 0; i < obj.errors.length; i++) {
681                         funcs.push( 
682                                 function(idx,row){ 
683                                         return function(){
684                                                 obj.error_list.append( { 'retrieve_id' : idx, 'row' : row } );
685                                         };
686                                 }(i,{ 'my' : obj.errors[i] }) 
687                         );
688                 }
689                 JSAN.use('util.exec'); var exec = new util.exec();
690                 exec.chain( funcs );
691         },
692
693         'render_status' : function() {
694         
695                 dump('render_status\n');
696
697                 document.getElementById('deck').selectedIndex = 3;
698
699         },
700
701         'retrieve_item' : function() {
702                 var obj = this;
703                 try {
704                         var barcodes = [];
705                         for (var i = 0; i < obj.sel_errors.length; i++) {
706                                 var error = obj.errors[ obj.sel_errors[i] ];
707                                 if ( ! error.command.barcode ) continue; 
708                                 if ( [ '', ' ', '???' ].indexOf( error.command.barcode ) != -1 ) continue;
709                                 barcodes.push( error.command.barcode );
710                         }
711                         if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
712                                 try {
713                                         var url = urls.XUL_COPY_STATUS
714                                                 + '?barcodes=' + window.escape( js2JSON(barcodes) );
715                                         window.xulG.new_tab(
716                                                 url
717                                         );
718                                 } catch(E) {
719                                         alert(E);
720                                 }
721                         }
722                 } catch(E) {
723                         alert(E);
724                 }
725         },
726
727         'retrieve_patron' : function() {
728                 var obj = this;
729                 try {
730                         for (var i = 0; i < obj.sel_errors.length; i++) {
731                                 var error = obj.errors[ obj.sel_errors[i] ];
732                                 if ( ! error.command.patron_barcode ) continue; 
733                                 if ( [ '', ' ', '???' ].indexOf( error.command.patron_barcode ) != -1 ) continue;
734                                 if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
735                                         try {
736                                                 var url = urls.XUL_PATRON_DISPLAY
737                                                         + '?barcode=' + window.escape( error.command.patron_barcode );
738                                                 window.xulG.new_tab(
739                                                         url
740                                                 );
741                                         } catch(E) {
742                                                 alert(E);
743                                         }
744                                 }
745                         }
746                 } catch(E) {
747                         alert(E);
748                 }
749         },
750
751         'retrieve_details' : function() {
752                 var obj = this;
753                 JSAN.use('util.window'); var win = new util.window();
754                 try {
755                         for (var i = 0; i < obj.sel_errors.length; i++) {
756                                 var error = obj.errors[ obj.sel_errors[i] ];
757                                 win.open(
758                                         'data:text/plain,' + window.escape(
759                                                 'Details:\n' + obj.error.pretty_print(js2JSON(error))
760                                         ),
761                                         'offline_error_details',
762                                         'height=240,width=320,scrollbars=yes,chrome,resizable,modal'
763                                 );
764                         }
765                 } catch(E) {
766                         alert(E);
767                 }
768
769         },
770 }
771
772 dump('exiting admin/offline_manage_xacts.js\n');