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