]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/offline_manage_xacts.js
remote auto_select for transit list and offline xact manager..robustify xact manager...
[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                 try {
371                         var robj = obj.network.simple_request('PERM_CHECK',[ses(),obj.data.list.au[0].id(),obj.data.list.au[0].ws_ou(),perms]);
372                         if (typeof robj.ilsevent != 'undefined') {
373                                 obj.error.standard_unexpected_error_alert('check permission',E);
374                                 return false;
375                         }
376                         return robj.length == 0 ? true : false;
377                 } catch(E) {
378                         obj.error.standard_unexpected_error_alert('Error checking permissions',E);
379                 }
380         },
381
382         'execute_ses' : function() {
383                 var obj = this;
384
385                 try {
386
387                 clear_the_cache();
388                 obj.data.stash_retrieve();
389
390                 for (var i = 0; i < obj.sel_list.length; i++) {
391
392                         var url  = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI)
393                                 + "?ses=" + window.escape(ses())
394                                 + "&action=execute" 
395                                 + "&seskey=" + window.escape(obj.seslist[obj.sel_list[i]].key)
396                                 + "&ws=" + window.escape(obj.data.ws_name);
397                         var x = new XMLHttpRequest();
398                         x.open("GET",url,false);
399                         x.send(null);
400
401                         dump(url + ' = ' + x.responseText + '\n' );
402                         if (!x.responseText) throw('Bad response from CGI component');
403                         var robj = JSON2js(x.responseText);
404
405                         if (robj.ilsevent != 0) { alert('Execute error: ' + x.responseText); }
406
407                         obj.retrieve_seslist(); obj.render_seslist();
408                 }
409
410                 } catch(E) {
411                         obj.error.standard_unexpected_error_alert('Error executing session',E);
412                 }
413         },
414
415         'ses_errors' : function() {
416                 var obj = this;
417
418                 try {
419
420                 clear_the_cache();
421                 obj.data.stash_retrieve();
422
423                 var url  = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI)
424                         + "?ses=" + window.escape(ses())
425                         + "&action=status" 
426                         + "&seskey=" + window.escape(obj.seslist[ obj.sel_list[0] ].key)
427                         + "&ws=" + window.escape(obj.data.ws_name)
428                         + '&status_type=exceptions';
429                 var x = new XMLHttpRequest();
430                 x.open("GET",url,false);
431                 x.send(null);
432
433                 dump(url + ' = ' + x.responseText + '\n' );
434                 if (!x.responseText) throw('Bad response from CGI component');
435                 var robj = JSON2js(x.responseText);
436
437                 return { 'errors' : robj, 'description' : obj.seslist[ obj.sel_list[0] ].description };
438
439                 } catch(E) {
440                         throw('Error retrieving session errors: ' + E);
441                 }
442
443         },
444
445         'rename_file' : function() {
446                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
447                 var obj = this;
448
449                 try {
450
451                 JSAN.use('util.file'); 
452                 var pending = new util.file('pending_xacts');
453                 if ( !pending._file.exists() ) { throw("Can't rename a non-existent file"); }
454                 obj.transition_filename = 'pending_xacts_' + new Date().getTime();
455                 var count = 0;
456                 var file = new util.file(obj.transition_filename);
457                 while (file._file.exists()) {
458                         obj.transition_filename = 'pending_xacts_' + new Date().getTime();
459                         file = new util.file(obj.transition_filename);
460                         if (count++>100) throw("Taking too long to find a unique filename.");
461                 }
462                 pending._file.moveTo(null,obj.transition_filename);
463
464                 } catch(E) {
465                         obj.error.standard_unexpected_error_alert('Error renaming xact file',E);
466                 }
467         },
468
469         'revert_file' : function() {
470                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
471                 var obj = this;
472
473                 try {
474
475                 JSAN.use('util.file');
476                 var pending = new util.file('pending_xacts');
477                 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; }
478                 var file = new util.file(obj.transition_filename);
479                 file._file.moveTo(null,'pending_xacts');
480
481                 } catch(E) {
482                         obj.error.standard_unexpected_error_alert('Error reverting xact file',E);
483                 }
484         },
485
486         'archive_file' : function() {
487                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
488                 var obj = this;
489
490                 try {
491
492                 JSAN.use('util.file');
493                 var file = new util.file(obj.transition_filename);
494                 if (file._file.exists()) file._file.moveTo(null,obj.transition_filename + '.complete');
495
496                 } catch(E) {
497                         obj.error.standard_unexpected_error_alert('Error archiving xact file',E);
498                 }
499         },
500
501         'upload' : function() {
502                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
503                 var obj = this;
504
505                 try {
506
507                 if (obj.sel_list.length == 0) { alert('Please select a session to upload to.'); return; }
508                 if (obj.sel_list.length > 1) { alert('Please select a single session to upload to.'); return; }
509
510                 JSAN.use('util.file');
511
512                 var file = new util.file('pending_xacts');
513                 if (!file._file.exists()) { alert('No pending transactions to upload.'); return; }
514
515                 obj.rename_file();
516
517                 obj.data.stash_retrieve();
518                 var seskey = obj.seslist[ obj.sel_list[0] ].key;
519                 JSAN.use('util.widgets');
520                 var xx = document.getElementById('iframe_placeholder'); util.widgets.remove_children(xx);
521                 var x = document.createElement('iframe'); xx.appendChild(x); x.flex = 1;
522                 x.setAttribute(
523                         'src',
524                         window.xulG.url_prefix( urls.XUL_REMOTE_BROWSER )
525                         + '?url=' + window.escape(
526                                 urls.XUL_OFFLINE_UPLOAD_XACTS
527                                 + '?ses=' + window.escape(ses())
528                                 + '&seskey=' + window.escape(seskey)
529                                 + '&ws=' + window.escape(obj.data.ws_name)
530                                 + '&delta=' + window.escape('0')
531                                 + '&filename=' + window.escape( obj.transition_filename )
532                         )
533                 );
534                 var newG = { 
535                         'url_prefix' : window.xulG.url_prefix, 
536                         'passthru_content_params' : {
537                                 'url_prefix' : window.xulG.url_prefix,
538                                 'handle_event' : function(robj){
539                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
540                                         try {
541                                                 dump('robj = ' + js2JSON(robj) + '\n');
542                                                 if ( robj.ilsevent != 0 ) {
543                                                         obj.revert_file();
544                                                         alert('There was an error:\n' + js2JSON(robj));
545                                                 } else {
546                                                         obj.archive_file();
547                                                 }
548                                                 obj.retrieve_seslist(); obj.render_seslist();
549                                                 setTimeout(
550                                                         function() {
551                                                                 JSAN.use('util.widgets');
552                                                                 util.widgets.remove_children('iframe_placeholder');
553                                                         },0
554                                                 );
555                                         } catch(E) {
556                                                 alert('handle_event error: ' + E);
557                                         }
558                                 } 
559                         }
560                 };
561                 x.contentWindow.xulG = newG;
562
563                 } catch(E) {
564                         obj.error.standard_unexpected_error_alert('Error uploading xacts',E);
565                 }
566         },
567
568         'ses_status' : function() {
569                 var obj = this;
570
571                 try {
572
573                 clear_the_cache();
574                 obj.data.stash_retrieve();
575
576                 var url  = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI)
577                         + "?ses=" + window.escape(ses())
578                         + "&action=status" 
579                         + "&seskey=" + window.escape(obj.seslist[obj.sel_list[0]].key)
580                         + "&ws=" + window.escape(obj.data.ws_name)
581                         + "&status_type=scripts";
582                 var x = new XMLHttpRequest();
583                 x.open("GET",url,false);
584                 x.send(null);
585
586                 dump(url + ' = ' + x.responseText + '\n' );
587                 if (!x.responseText) throw('Bad response from CGI component');
588                 var robj = JSON2js(x.responseText);
589
590                 return robj;
591
592                 } catch(E) {
593
594                         obj.error.standard_unexpected_error_alert('Error retrieving session status',E);
595                         return { 'ilsevent' : -2 };     
596
597                 }
598         },
599
600         'create_ses' : function() {
601
602                 var obj = this;
603
604                 try {
605
606                 var desc = window.prompt('Please enter a description:','','Create an Offline Transaction Session');
607                 if (desc=='' || desc==null) { return; }
608
609                 clear_the_cache();
610                 obj.data.stash_retrieve();
611
612                 var url  = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI)
613                         + "?ses=" + window.escape(ses())
614                         + "&action=create" 
615                         + "&desc=" + window.escape(desc)
616                         + "&ws=" + window.escape(obj.data.ws_name);
617                 var x = new XMLHttpRequest();
618                 x.open("GET",url,false);
619                 x.send(null);
620
621                 dump(url + ' = ' + x.responseText + '\n' );
622                 if (!x.responseText) throw('Bad response from CGI component');
623                 var robj = JSON2js(x.responseText);
624                 if (robj.ilsevent == 0) {
625                         obj.retrieve_seslist(); obj.render_seslist();
626                 } else {
627                         alert('Error: ' + x.responseText);
628                 }
629
630                 } catch(E) {
631                         obj.error.standard_unexpected_error_alert('Error creating session',E);
632                 }
633
634         },
635
636         'retrieve_seslist' : function() {
637
638                 var obj = this;
639
640                 try {
641
642                         clear_the_cache();
643                         obj.data.stash_retrieve();
644
645                         var url = xulG.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS_CGI) 
646                                 + "?ses=" + window.escape(ses())
647                                 + "&action=status"
648                                 + "&org=" + window.escape(obj.data.list.au[0].ws_ou())
649                                 + "&status_type=sessions";
650                         var x = new XMLHttpRequest();
651                         x.open("GET",url,false);
652                         x.send(null);
653
654                         dump(url + ' = ' + typeof(x.responseText) + '\n' );
655
656                         if (!x.responseText) throw('Bad response from CGI component');
657
658                         var robj = JSON2js( x.responseText );
659                         if (typeof robj.ilsevent != 'undefined') throw(robj);
660
661                         if (!robj) throw(robj);
662
663                         obj.seslist = robj.sort(
664                                 function(a,b) {
665                                         return b.create_time - a.create_time;
666                                 }
667                         );
668
669                 } catch(E) {
670                         obj.error.standard_unexpected_error_alert('Error retrieving offline sessions.',E);
671                 }
672         },
673
674         'render_seslist' : function() {
675
676                 var obj = this;
677
678                 try {
679
680                 var old_idx = obj.list.node.currentIndex;
681                 if (old_idx < 0) old_idx = 0;
682
683                 obj.list.clear();
684
685                 var funcs = [];
686                 for (var i = 0; i < obj.seslist.length; i++) {
687                         funcs.push( 
688                                 function(idx,row){ 
689                                         return function(){
690                                                 obj.list.append( { 'retrieve_id' : idx, 'row' : row, 'no_auto_select' : true } );
691                                                 if (idx == old_idx) obj.list.node.view.selection.select(idx);
692                                         };
693                                 }(i,{ 'my' : obj.seslist[i] }) 
694                         );
695                 }
696
697                 JSAN.use('util.exec'); var exec = new util.exec();
698                 exec.chain( funcs );
699
700                 document.getElementById('execute').disabled = true;
701                 document.getElementById('upload').disabled = true;
702
703                 } catch(E) {
704                         obj.error.standard_unexpected_error_alert('Error rendering session list',E);
705                 }
706         },
707
708         'render_scriptlist' : function() {
709
710                 dump('render_scriptlist\n');
711
712                 var obj = this;
713
714                 try { 
715
716                 document.getElementById('deck').selectedIndex = 1;
717
718                 obj.script_list.clear();
719
720                 var status = obj.ses_status();
721                 document.getElementById('status_caption').setAttribute('label','Uploaded Transactions for ' + status.description);
722
723                 var scripts = status.scripts;
724
725                 var funcs = [];
726                 for (var i = 0; i < scripts.length; i++) {
727                         funcs.push( 
728                                 function(row){ 
729                                         return function(){
730                                                 obj.script_list.append( { 'row' : row, 'no_auto_select' : true  } );
731                                         };
732                                 }({ 'my' : scripts[i] }) 
733                         );
734                 }
735                 JSAN.use('util.exec'); var exec = new util.exec();
736                 exec.chain( funcs );
737
738                 } catch(E) {
739                         obj.error.standard_unexpected_error_alert('Error rendering script list',E);
740                 }
741         },
742         
743         'render_errorlist' : function() {
744
745                 dump('render_errorlist\n');
746
747                 var obj = this;
748
749                 try {
750
751                 document.getElementById('deck').selectedIndex = 2;
752
753                 obj.error_list.clear();
754
755                 var error_meta = obj.ses_errors();
756                 document.getElementById('errors_caption').setAttribute('label','Exceptions for ' + error_meta.description);
757
758                 obj.errors = error_meta.errors;
759
760                 var funcs = [];
761                 for (var i = 0; i < obj.errors.length; i++) {
762                         funcs.push( 
763                                 function(idx,row){ 
764                                         return function(){
765                                                 obj.error_list.append( { 'retrieve_id' : idx, 'row' : row, 'no_auto_select' : true  } );
766                                         };
767                                 }(i,{ 'my' : obj.errors[i] }) 
768                         );
769                 }
770                 JSAN.use('util.exec'); var exec = new util.exec();
771                 exec.chain( funcs );
772
773                 } catch(E) {
774                         obj.error.standard_unexpected_error_alert('Error rendering error list',E);
775                 }
776         },
777
778         'render_status' : function() {
779         
780                 dump('render_status\n');
781
782                 document.getElementById('deck').selectedIndex = 3;
783
784         },
785
786         'retrieve_item' : function() {
787                 var obj = this;
788                 try {
789                         var barcodes = [];
790                         for (var i = 0; i < obj.sel_errors.length; i++) {
791                                 var error = obj.errors[ obj.sel_errors[i] ];
792                                 if ( ! error.command.barcode ) continue; 
793                                 if ( [ '', ' ', '???' ].indexOf( error.command.barcode ) != -1 ) continue;
794                                 barcodes.push( error.command.barcode );
795                         }
796                         if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
797                                 try {
798                                         var url = urls.XUL_COPY_STATUS
799                                                 + '?barcodes=' + window.escape( js2JSON(barcodes) );
800                                         window.xulG.new_tab(
801                                                 url
802                                         );
803                                 } catch(E) {
804                                         alert(E);
805                                 }
806                         }
807                 } catch(E) {
808                         alert(E);
809                 }
810         },
811
812         'retrieve_patron' : function() {
813                 var obj = this;
814                 try {
815                         for (var i = 0; i < obj.sel_errors.length; i++) {
816                                 var error = obj.errors[ obj.sel_errors[i] ];
817                                 if ( ! error.command.patron_barcode ) continue; 
818                                 if ( [ '', ' ', '???' ].indexOf( error.command.patron_barcode ) != -1 ) continue;
819                                 if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
820                                         try {
821                                                 var url = urls.XUL_PATRON_DISPLAY
822                                                         + '?barcode=' + window.escape( error.command.patron_barcode );
823                                                 window.xulG.new_tab(
824                                                         url
825                                                 );
826                                         } catch(E) {
827                                                 alert(E);
828                                         }
829                                 }
830                         }
831                 } catch(E) {
832                         alert(E);
833                 }
834         },
835
836         'retrieve_details' : function() {
837                 var obj = this;
838                 JSAN.use('util.window'); var win = new util.window();
839                 try {
840                         for (var i = 0; i < obj.sel_errors.length; i++) {
841                                 var error = obj.errors[ obj.sel_errors[i] ];
842                                 win.open(
843                                         'data:text/plain,' + window.escape(
844                                                 'Details:\n' + obj.error.pretty_print(js2JSON(error))
845                                         ),
846                                         'offline_error_details',
847                                         'height=240,width=320,scrollbars=yes,chrome,resizable,modal'
848                                 );
849                         }
850                 } catch(E) {
851                         alert(E);
852                 }
853
854         },
855 }
856
857 dump('exiting admin/offline_manage_xacts.js\n');