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