]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/offline_manage_xacts.js
export for offline xact exception 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
342         'check_perm' : function(perms) {
343                 var obj = this;
344                 var robj = obj.network.simple_request('PERM_CHECK',[ses(),obj.data.list.au[0].id(),obj.data.list.au[0].ws_ou(),perms]);
345                 if (typeof robj.ilsevent != 'undefined') {
346                         obj.error.standard_unexpected_error_alert('check permission',E);
347                         return false;
348                 }
349                 return robj.length == 0 ? true : false;
350         },
351
352         'execute_ses' : function() {
353                 var obj = this;
354
355                 clear_the_cache();
356                 obj.data.stash_retrieve();
357
358                 for (var i = 0; i < obj.sel_list.length; i++) {
359
360                         var url  = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI)
361                                 + "?ses=" + window.escape(ses())
362                                 + "&action=execute" 
363                                 + "&seskey=" + window.escape(obj.seslist[obj.sel_list[i]].key)
364                                 + "&ws=" + window.escape(obj.data.ws_name);
365                         var x = new XMLHttpRequest();
366                         x.open("GET",url,false);
367                         x.send(null);
368
369                         dump(url + ' = ' + x.responseText + '\n' );
370                         var robj = JSON2js(x.responseText);
371
372                         if (robj.ilsevent != 0) { alert('Execute error: ' + x.responseText); }
373
374                         obj.retrieve_seslist(); obj.render_seslist();
375                 }
376         },
377
378         'ses_errors' : function() {
379                 var obj = this;
380
381                 clear_the_cache();
382                 obj.data.stash_retrieve();
383
384                 var url  = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI)
385                         + "?ses=" + window.escape(ses())
386                         + "&action=status" 
387                         + "&seskey=" + window.escape(obj.seslist[ obj.sel_list[0] ].key)
388                         + "&ws=" + window.escape(obj.data.ws_name)
389                         + '&status_type=exceptions';
390                 var x = new XMLHttpRequest();
391                 x.open("GET",url,false);
392                 x.send(null);
393
394                 dump(url + ' = ' + x.responseText + '\n' );
395                 var robj = JSON2js(x.responseText);
396
397                 return { 'errors' : robj, 'description' : obj.seslist[ obj.sel_list[0] ].description };
398
399         },
400
401         'rename_file' : function() {
402                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
403                 var obj = this;
404                 JSAN.use('util.file'); 
405                 var pending = new util.file('pending_xacts');
406                 if ( !pending._file.exists() ) { throw("Can't rename a non-existent file"); }
407                 obj.transition_filename = 'pending_xacts_' + new Date().getTime();
408                 var count = 0;
409                 var file = new util.file(obj.transition_filename);
410                 while (file._file.exists()) {
411                         obj.transition_filename = 'pending_xacts_' + new Date().getTime();
412                         file = new util.file(obj.transition_filename);
413                         if (count++>100) throw("Taking too long to find a unique filename.");
414                 }
415                 pending._file.moveTo(null,obj.transition_filename);
416         },
417
418         'revert_file' : function() {
419                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
420                 var obj = this;
421                 JSAN.use('util.file');
422                 var pending = new util.file('pending_xacts');
423                 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; }
424                 var file = new util.file(obj.transition_filename);
425                 file._file.moveTo(null,'pending_xacts');
426         },
427
428         'archive_file' : function() {
429                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
430                 var obj = this;
431                 JSAN.use('util.file');
432                 var file = new util.file(obj.transition_filename);
433                 if (file._file.exists()) file._file.moveTo(null,obj.transition_filename + '.complete')
434         },
435
436         'upload' : function() {
437                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
438                 var obj = this;
439                 if (obj.sel_list.length == 0) { alert('Please select a session to upload to.'); return; }
440                 if (obj.sel_list.length > 1) { alert('Please select a single session to upload to.'); return; }
441
442                 JSAN.use('util.file');
443
444                 var file = new util.file('pending_xacts');
445                 if (!file._file.exists()) { alert('No pending transactions to upload.'); return; }
446
447                 obj.rename_file();
448
449                 obj.data.stash_retrieve();
450                 var seskey = obj.seslist[ obj.sel_list[0] ].key;
451                 JSAN.use('util.widgets');
452                 var xx = document.getElementById('iframe_placeholder'); util.widgets.remove_children(xx);
453                 var x = document.createElement('iframe'); xx.appendChild(x); x.flex = 1;
454                 x.setAttribute(
455                         'src',
456                         window.xulG.url_prefix( urls.XUL_REMOTE_BROWSER )
457                         + '?url=' + window.escape(
458                                 urls.XUL_OFFLINE_UPLOAD_XACTS
459                                 + '?ses=' + window.escape(ses())
460                                 + '&seskey=' + window.escape(seskey)
461                                 + '&ws=' + window.escape(obj.data.ws_name)
462                                 + '&delta=' + window.escape('0')
463                                 + '&filename=' + window.escape( obj.transition_filename )
464                         )
465                 );
466                 var newG = { 
467                         'url_prefix' : window.xulG.url_prefix, 
468                         'passthru_content_params' : {
469                                 'url_prefix' : window.xulG.url_prefix,
470                                 'handle_event' : function(robj){
471                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
472                                         try {
473                                                 dump('robj = ' + js2JSON(robj) + '\n');
474                                                 if ( robj.ilsevent != 0 ) {
475                                                         obj.revert_file();
476                                                         alert('There was an error:\n' + js2JSON(robj));
477                                                 } else {
478                                                         obj.archive_file();
479                                                 }
480                                                 obj.retrieve_seslist(); obj.render_seslist();
481                                                 setTimeout(
482                                                         function() {
483                                                                 JSAN.use('util.widgets');
484                                                                 util.widgets.remove_children('iframe_placeholder');
485                                                         },0
486                                                 );
487                                         } catch(E) {
488                                                 alert('handle_event error: ' + E);
489                                         }
490                                 } 
491                         }
492                 };
493                 x.contentWindow.xulG = newG;
494         },
495
496         'ses_status' : function() {
497                 var obj = this;
498
499                 clear_the_cache();
500                 obj.data.stash_retrieve();
501
502                 var url  = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI)
503                         + "?ses=" + window.escape(ses())
504                         + "&action=status" 
505                         + "&seskey=" + window.escape(obj.seslist[obj.sel_list[0]].key)
506                         + "&ws=" + window.escape(obj.data.ws_name)
507                         + "&status_type=scripts";
508                 var x = new XMLHttpRequest();
509                 x.open("GET",url,false);
510                 x.send(null);
511
512                 dump(url + ' = ' + x.responseText + '\n' );
513                 var robj = JSON2js(x.responseText);
514
515                 return robj;
516         },
517
518         'create_ses' : function() {
519
520                 var obj = this;
521
522                 var desc = window.prompt('Please enter a description:','','Create an Offline Transaction Session');
523                 if (desc=='' || desc==null) { return; }
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=create" 
531                         + "&desc=" + window.escape(desc)
532                         + "&ws=" + window.escape(obj.data.ws_name);
533                 var x = new XMLHttpRequest();
534                 x.open("GET",url,false);
535                 x.send(null);
536
537                 dump(url + ' = ' + x.responseText + '\n' );
538                 var robj = JSON2js(x.responseText);
539                 if (robj.ilsevent == 0) {
540                         obj.retrieve_seslist(); obj.render_seslist();
541                 } else {
542                         alert('Error: ' + x.responseText);
543                 }
544         },
545
546         'retrieve_seslist' : function() {
547
548                 var obj = this;
549
550                 try {
551
552                         clear_the_cache();
553                         obj.data.stash_retrieve();
554
555                         var url = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI) 
556                                 + "?ses=" + window.escape(ses())
557                                 + "&action=status"
558                                 + "&org=" + window.escape(obj.data.list.au[0].ws_ou())
559                                 + "&status_type=sessions";
560                         var x = new XMLHttpRequest();
561                         x.open("GET",url,false);
562                         x.send(null);
563
564                         dump(url + ' = ' + x.responseText + '\n' );
565
566                         var robj = JSON2js( x.responseText );
567                         if (typeof robj.ilsevent != 'undefined') throw(robj);
568
569                         obj.seslist = robj.sort(
570                                 function(a,b) {
571                                         return b.create_time - a.create_time;
572                                 }
573                         );
574
575                 } catch(E) {
576                         obj.error.standard_unexpected_error_alert('Error retrieving offline sessions.',E);
577                 }
578         },
579
580         'render_seslist' : function() {
581
582                 var obj = this;
583
584                 var old_idx = obj.list.node.currentIndex;
585                 if (old_idx < 0) old_idx = 0;
586
587                 obj.list.clear();
588
589                 var funcs = [];
590                 for (var i = 0; i < obj.seslist.length; i++) {
591                         funcs.push( 
592                                 function(idx,row){ 
593                                         return function(){
594                                                 obj.list.append( { 'retrieve_id' : idx, 'row' : row } );
595                                                 if (idx == old_idx) obj.list.node.view.selection.select(idx);
596                                         };
597                                 }(i,{ 'my' : obj.seslist[i] }) 
598                         );
599                 }
600
601                 JSAN.use('util.exec'); var exec = new util.exec();
602                 exec.chain( funcs );
603
604                 document.getElementById('execute').disabled = true;
605                 document.getElementById('upload').disabled = true;
606
607         },
608
609         'render_scriptlist' : function() {
610
611                 dump('render_scriptlist\n');
612
613                 document.getElementById('deck').selectedIndex = 1;
614
615                 var obj = this;
616
617                 obj.script_list.clear();
618
619                 var status = obj.ses_status();
620                 document.getElementById('status_caption').setAttribute('label','Uploaded Transactions for ' + status.description);
621
622                 var scripts = status.scripts;
623
624                 var funcs = [];
625                 for (var i = 0; i < scripts.length; i++) {
626                         funcs.push( 
627                                 function(row){ 
628                                         return function(){
629                                                 obj.script_list.append( { 'row' : row } );
630                                         };
631                                 }({ 'my' : scripts[i] }) 
632                         );
633                 }
634                 JSAN.use('util.exec'); var exec = new util.exec();
635                 exec.chain( funcs );
636         },
637         
638         'render_errorlist' : function() {
639
640                 dump('render_errorlist\n');
641
642                 document.getElementById('deck').selectedIndex = 2;
643
644                 var obj = this;
645
646                 obj.error_list.clear();
647
648                 var error_meta = obj.ses_errors();
649                 document.getElementById('errors_caption').setAttribute('label','Exceptions for ' + error_meta.description);
650
651                 obj.errors = error_meta.errors;
652
653                 var funcs = [];
654                 for (var i = 0; i < obj.errors.length; i++) {
655                         funcs.push( 
656                                 function(idx,row){ 
657                                         return function(){
658                                                 obj.error_list.append( { 'retrieve_id' : idx, 'row' : row } );
659                                         };
660                                 }(i,{ 'my' : obj.errors[i] }) 
661                         );
662                 }
663                 JSAN.use('util.exec'); var exec = new util.exec();
664                 exec.chain( funcs );
665         },
666
667         'render_status' : function() {
668         
669                 dump('render_status\n');
670
671                 document.getElementById('deck').selectedIndex = 3;
672
673         },
674
675         'retrieve_item' : function() {
676                 var obj = this;
677                 try {
678                         var barcodes = [];
679                         for (var i = 0; i < obj.sel_errors.length; i++) {
680                                 var error = obj.errors[ obj.sel_errors[i] ];
681                                 if ( ! error.command.barcode ) continue; 
682                                 if ( [ '', ' ', '???' ].indexOf( error.command.barcode ) != -1 ) continue;
683                                 barcodes.push( error.command.barcode );
684                         }
685                         if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
686                                 try {
687                                         var url = urls.XUL_COPY_STATUS
688                                                 + '?barcodes=' + window.escape( js2JSON(barcodes) );
689                                         window.xulG.new_tab(
690                                                 url
691                                         );
692                                 } catch(E) {
693                                         alert(E);
694                                 }
695                         }
696                 } catch(E) {
697                         alert(E);
698                 }
699         },
700
701         'retrieve_patron' : function() {
702                 var obj = this;
703                 try {
704                         for (var i = 0; i < obj.sel_errors.length; i++) {
705                                 var error = obj.errors[ obj.sel_errors[i] ];
706                                 if ( ! error.command.patron_barcode ) continue; 
707                                 if ( [ '', ' ', '???' ].indexOf( error.command.patron_barcode ) != -1 ) continue;
708                                 if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
709                                         try {
710                                                 var url = urls.XUL_PATRON_DISPLAY
711                                                         + '?barcode=' + window.escape( error.command.patron_barcode );
712                                                 window.xulG.new_tab(
713                                                         url
714                                                 );
715                                         } catch(E) {
716                                                 alert(E);
717                                         }
718                                 }
719                         }
720                 } catch(E) {
721                         alert(E);
722                 }
723         },
724
725         'retrieve_details' : function() {
726                 var obj = this;
727                 JSAN.use('util.window'); var win = new util.window();
728                 try {
729                         for (var i = 0; i < obj.sel_errors.length; i++) {
730                                 var error = obj.errors[ obj.sel_errors[i] ];
731                                 win.open(
732                                         'data:text/plain,' + window.escape(
733                                                 'Details:\n' + obj.error.pretty_print(js2JSON(error))
734                                         ),
735                                         'offline_error_details',
736                                         'height=240,width=320,scrollbars=yes,chrome,resizable,modal'
737                                 );
738                         }
739                 } catch(E) {
740                         alert(E);
741                 }
742
743         },
744 }
745
746 dump('exiting admin/offline_manage_xacts.js\n');