]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_buckets.js
xul_param and modal xulG conversion
[Evergreen.git] / Open-ILS / xul / staff_client / server / cat / copy_buckets.js
1 dump('entering cat.copy_buckets.js\n');
2
3 if (typeof cat == 'undefined') cat = {};
4 cat.copy_buckets = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8         JSAN.use('util.date');
9         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
10         this.first_pause = true;
11 }
12
13 cat.copy_buckets.prototype = {
14         'selection_list1' : [],
15         'selection_list2' : [],
16         'bucket_id_name_map' : {},
17
18         'render_pending_copies' : function() {
19                 if (this.first_pause) {
20                         this.first_pause = false;
21                 } else {
22                         alert("Action completed.");
23                 }
24                 var obj = this;
25                 obj.list1.clear();
26                 for (var i = 0; i < obj.copy_ids.length; i++) {
27                         var item = obj.flesh_item_for_list( obj.copy_ids[i] );
28                         if (item) obj.list1.append( item );
29                 }
30         },
31
32         'init' : function( params ) {
33
34                 var obj = this;
35
36                 obj.copy_ids = params['copy_ids'] || [];
37
38                 JSAN.use('circ.util');
39                 var columns = circ.util.columns( 
40                         { 
41                                 'barcode' : { 'hidden' : false },
42                                 'title' : { 'hidden' : false },
43                                 'location' : { 'hidden' : false },
44                                 'call_number' : { 'hidden' : false },
45                                 'status' : { 'hidden' : false },
46                                 'deleted' : { 'hidden' : false },
47                         } 
48                 );
49
50                 JSAN.use('util.list'); 
51
52                 obj.list1 = new util.list('pending_copies_list');
53                 obj.list1.init(
54                         {
55                                 'columns' : columns,
56                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
57                                 'on_select' : function(ev) {
58                                         try {
59                                                 JSAN.use('util.functional');
60                                                 var sel = obj.list1.retrieve_selection();
61                                                 document.getElementById('clip_button1').disabled = sel.length < 1;
62                                                 obj.selection_list1 = util.functional.map_list(
63                                                         sel,
64                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
65                                                 );
66                                                 obj.error.sdump('D_TRACE','circ/copy_buckets: selection list 1 = ' + js2JSON(obj.selection_list1) );
67                                                 if (obj.selection_list1.length == 0) {
68                                                         obj.controller.view.copy_buckets_sel_add.disabled = true;
69                                                 } else {
70                                                         obj.controller.view.copy_buckets_sel_add.disabled = false;
71                                                 }
72                                         } catch(E) {
73                                                 alert('FIXME: ' + E);
74                                         }
75                                 },
76
77                         }
78                 );
79
80                 obj.render_pending_copies();
81         
82                 obj.list2 = new util.list('copies_in_bucket_list');
83                 obj.list2.init(
84                         {
85                                 'columns' : columns,
86                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
87                                 'on_select' : function(ev) {
88                                         try {
89                                                 JSAN.use('util.functional');
90                                                 var sel = obj.list2.retrieve_selection();
91                                                 document.getElementById('clip_button2').disabled = sel.length < 1;
92                                                 obj.selection_list2 = util.functional.map_list(
93                                                         sel,
94                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
95                                                 );
96                                                 obj.error.sdump('D_TRACE','circ/copy_buckets: selection list 2 = ' + js2JSON(obj.selection_list2) );
97                                                 if (obj.selection_list2.length == 0) {
98                                                         obj.controller.view.copy_buckets_delete_item.disabled = true;
99                                                         obj.controller.view.copy_buckets_delete_item.setAttribute('disabled','true');
100                                                         obj.controller.view.copy_buckets_export.disabled = true;
101                                                         obj.controller.view.copy_buckets_export.setAttribute('disabled','true');
102                                                 } else {
103                                                         obj.controller.view.copy_buckets_delete_item.disabled = false;
104                                                         obj.controller.view.copy_buckets_delete_item.setAttribute('disabled','false');
105                                                         obj.controller.view.copy_buckets_export.disabled = false;
106                                                         obj.controller.view.copy_buckets_export.setAttribute('disabled','false');
107                                                 }
108                                         } catch(E) {
109                                                 alert('FIXME: ' + E);
110                                         }
111                                 },
112                         }
113                 );
114                 
115                 JSAN.use('util.controller'); obj.controller = new util.controller();
116                 obj.controller.init(
117                         {
118                                 'control_map' : {
119                                         'save_columns2' : [
120                                                 ['command'],
121                                                 function() { obj.list2.save_columns(); }
122                                         ],
123                                         'save_columns1' : [
124                                                 ['command'],
125                                                 function() { obj.list1.save_columns(); }
126                                         ],
127                                         'sel_clip2' : [
128                                                 ['command'],
129                                                 function() { obj.list2.clipboard(); }
130                                         ],
131                                         'sel_clip1' : [
132                                                 ['command'],
133                                                 function() { obj.list1.clipboard(); }
134                                         ],
135                                         'copy_buckets_menulist_placeholder' : [
136                                                 ['render'],
137                                                 function(e) {
138                                                         return function() {
139                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
140                                                                 var items = [ ['Choose a bucket...',''], ['Retrieve shared bucket...',-1] ].concat(
141                                                                         util.functional.map_list(
142                                                                                 obj.network.simple_request(
143                                                                                         'BUCKET_RETRIEVE_VIA_USER',
144                                                                                         [ ses(), obj.data.list.au[0].id() ]
145                                                                                 ).copy,
146                                                                                 function(o) {
147                                                                                         obj.bucket_id_name_map[ o.id() ] = o.name();
148                                                                                         return [ o.name(), o.id() ];
149                                                                                 }
150                                                                         )
151                                                                 );
152                                                                 obj.error.sdump('D_TRACE','items = ' + js2JSON(items));
153                                                                 util.widgets.remove_children( e );
154                                                                 var ml = util.widgets.make_menulist(
155                                                                         items
156                                                                 );
157                                                                 e.appendChild( ml );
158                                                                 ml.setAttribute('id','bucket_menulist');
159                                                                 ml.setAttribute('accesskey','');
160
161                                                                 function change_bucket(ev) {
162                                                                         var bucket_id = ev.target.value;
163                                                                         if (bucket_id < 0 ) {
164                                                                                 bucket_id = window.prompt('Enter bucket number:');
165                                                                                 ev.target.value = bucket_id;
166                                                                                 ev.target.setAttribute('value',bucket_id);
167                                                                         }
168                                                                         if (!bucket_id) return;
169                                                                         var bucket = obj.network.simple_request(
170                                                                                 'BUCKET_FLESH',
171                                                                                 [ ses(), 'copy', bucket_id ]
172                                                                         );
173                                                                         if (typeof bucket.ilsevent != 'undefined') {
174                                                                                 if (bucket.ilsevent == 1506 /* CONTAINER_NOT_FOUND */) {
175                                                                                         alert('Could not find a bucket with ID = ' + bucket_id);
176                                                                                 } else {
177                                                                                         obj.error.standard_unexpected_error_alert('Error retrieving bucket.  Did you use a valid bucket id?',bucket);
178                                                                                 }
179                                                                                 return;
180                                                                         }
181                                                                         try {
182                                                                                 var x = document.getElementById('info_box');
183                                                                                 x.setAttribute('hidden','false');
184                                                                                 x = document.getElementById('bucket_number');
185                                                                                 x.setAttribute('value',bucket.id());
186                                                                                 x = document.getElementById('bucket_name');
187                                                                                 x.setAttribute('value',bucket.name());
188                                                                                 x = document.getElementById('bucket_owner');
189                                                                                 var s = bucket.owner(); JSAN.use('patron.util');
190                                                                                 if (s && typeof s != "object") s = patron.util.retrieve_fleshed_au_via_id(ses(),s); 
191                                                                                 x.setAttribute('value',s.card().barcode() + " @ " + obj.data.hash.aou[ s.home_ou() ].shortname());
192
193                                                                         } catch(E) {
194                                                                                 alert(E);
195                                                                         }
196                                                                         var items = bucket.items() || [];
197                                                                         obj.list2.clear();
198                                                                         for (var i = 0; i < items.length; i++) {
199                                                                                 var item = obj.flesh_item_for_list( 
200                                                                                         items[i].target_copy(),
201                                                                                         items[i].id()
202                                                                                 );
203                                                                                 if (item) obj.list2.append( item );
204                                                                         }
205                                                                 }
206
207                                                                 ml.addEventListener( 'change_bucket', change_bucket , false);
208                                                                 ml.addEventListener( 'command', function() {
209                                                                         JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
210                                                                 }, false);
211                                                                 obj.controller.view.bucket_menulist = ml;
212                                                                 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
213                                                                 document.getElementById('refresh').addEventListener( 'command', function() {
214                                                                         JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
215                                                                 }, false);
216                                                         };
217                                                 },
218                                         ],
219
220                                         'copy_buckets_add' : [
221                                                 ['command'],
222                                                 function() {
223                                                         var bucket_id = obj.controller.view.bucket_menulist.value;
224                                                         if (!bucket_id) return;
225                                                         for (var i = 0; i < obj.copy_ids.length; i++) {
226                                                                 var bucket_item = new ccbi();
227                                                                 bucket_item.isnew('1');
228                                                                 bucket_item.bucket(bucket_id);
229                                                                 bucket_item.target_copy( obj.copy_ids[i] );
230                                                                 try {
231                                                                         var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
232                                                                                 [ ses(), 'copy', bucket_item ]);
233
234                                                                         if (typeof robj == 'object') throw robj;
235
236                                                                         var item = obj.flesh_item_for_list( obj.copy_ids[i], robj );
237                                                                         if (!item) continue;
238
239                                                                         obj.list2.append( item );
240                                                                 } catch(E) {
241                                                                         obj.error.standard_unexpected_error_alert('Addition likely failed.',E);
242                                                                 }
243                                                         }
244                                                 }
245                                         ],
246                                         'copy_buckets_sel_add' : [
247                                                 ['command'],
248                                                 function() {                                                        
249                                                         var bucket_id = obj.controller.view.bucket_menulist.value;
250                                                         if (!bucket_id) return;
251                                                         for (var i = 0; i < obj.selection_list1.length; i++) {
252                                                                 var acp_id = obj.selection_list1[i][0];
253                                                                 //var barcode = obj.selection_list1[i][1];
254                                                                 var bucket_item = new ccbi();
255                                                                 bucket_item.isnew('1');
256                                                                 bucket_item.bucket(bucket_id);
257                                                                 bucket_item.target_copy( acp_id );
258                                                                 try {
259                                                                         var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
260                                                                                 [ ses(), 'copy', bucket_item ]);
261
262                                                                         if (typeof robj == 'object') throw robj;
263
264                                                                         var item = obj.flesh_item_for_list( acp_id, robj );
265                                                                         if (!item) continue;
266
267                                                                         obj.list2.append( item );
268                                                                 } catch(E) {
269                                                                         obj.error.standard_unexpected_error_alert('Deletion likely failed.',E);
270                                                                 }
271                                                         }
272
273                                                 }
274                                         ],
275                                         'copy_buckets_export' : [
276                                                 ['command'],
277                                                 function() {                                                        
278                                                         for (var i = 0; i < obj.selection_list2.length; i++) {
279                                                                 var acp_id = obj.selection_list2[i][0];
280                                                                 //var barcode = obj.selection_list1[i][1];
281                                                                 //var bucket_item_id = obj.selection_list1[i][2];
282                                                                 var item = obj.flesh_item_for_list( acp_id );
283                                                                 if (item) {
284                                                                         obj.list1.append( item );
285                                                                         obj.copy_ids.push( acp_id );
286                                                                 }
287                                                         }
288                                                 }
289                                         ],
290
291                                         'copy_buckets_delete_item' : [
292                                                 ['command'],
293                                                 function() {
294                                                         for (var i = 0; i < obj.selection_list2.length; i++) {
295                                                                 try {
296                                                                         //var acp_id = obj.selection_list2[i][0];
297                                                                         //var barcode = obj.selection_list2[i][1];
298                                                                         var bucket_item_id = obj.selection_list2[i][2];
299                                                                         var robj = obj.network.simple_request('BUCKET_ITEM_DELETE',
300                                                                                 [ ses(), 'copy', bucket_item_id ]);
301                                                                         if (typeof robj == 'object') throw robj;
302                                                                 } catch(E) {
303                                                                         obj.error.standard_unexpected_error_alert('Deletion likely failed.',E);
304                                                                 }
305                                                         }
306                                                         alert("Action completed.");
307                                                         setTimeout(
308                                                                 function() {
309                                                                         JSAN.use('util.widgets'); 
310                                                                         util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
311                                                                 }, 0
312                                                         );
313                                                 }
314                                         ],
315                                         'copy_buckets_delete_bucket' : [
316                                                 ['command'],
317                                                 function() {
318                                                         try {
319                                                                 var bucket = obj.controller.view.bucket_menulist.value;
320                                                                 var name = obj.bucket_id_name_map[ bucket ];
321                                                                 var conf = window.confirm('Delete the bucket named ' + name + '?');
322                                                                 if (!conf) return;
323                                                                 obj.list2.clear();
324                                                                 var robj = obj.network.simple_request('BUCKET_DELETE',[ses(),'copy',bucket]);
325                                                                 if (typeof robj == 'object') throw robj;
326                                                                 alert("Action completed.");
327                                                                 obj.controller.render('copy_buckets_menulist_placeholder');
328                                                         } catch(E) {
329                                                                 obj.error.standard_unexpected_error_alert('Bucket deletion likely failed.',E);
330                                                         }
331                                                 }
332                                         ],
333                                         'copy_buckets_new_bucket' : [
334                                                 ['command'],
335                                                 function() {
336                                                         try {
337                                                                 var name = prompt('What would you like to name the bucket?','','Bucket Creation');
338
339                                                                 if (name) {
340                                                                         var bucket = new ccb();
341                                                                         bucket.btype('staff_client');
342                                                                         bucket.owner( obj.data.list.au[0].id() );
343                                                                         bucket.name( name );
344
345                                                                         var robj = obj.network.simple_request('BUCKET_CREATE',[ses(),'copy',bucket]);
346
347                                                                         if (typeof robj == 'object') {
348                                                                                 if (robj.ilsevent == 1710 /* CONTAINER_EXISTS */) {
349                                                                                         alert('You already have a bucket with that name.');
350                                                                                         return;
351                                                                                 }
352                                                                                 throw robj;
353                                                                         }
354
355                                                                         alert('Bucket "' + name + '" created.');
356
357                                                                         obj.controller.render('copy_buckets_menulist_placeholder');
358                                                                         obj.controller.view.bucket_menulist.value = robj;
359                                                                         setTimeout(
360                                                                                 function() {
361                                                                                         JSAN.use('util.widgets'); 
362                                                                                         util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
363                                                                                 }, 0
364                                                                         );
365                                                                 }
366                                                         } catch(E) {
367                                                                 obj.error.standard_unexpected_error_alert('Bucket creation failed.',E);
368                                                         }
369                                                 }
370                                         ],
371                                         'copy_buckets_batch_copy_edit' : [
372                                                 ['command'],
373                                                 function() {
374                                                         try {
375
376                                                                 obj.list2.select_all();
377                                                         
378                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
379
380                                                                 var list = util.functional.map_list(
381                                                                         obj.list2.dump_retrieve_ids(),
382                                                                         function (o) {
383                                                                                 return JSON2js(o)[0]; // acp_id
384                                                                         }
385                                                                 );
386
387                                                                 var copies = util.functional.map_list(
388                                                                         list,
389                                                                         function (acp_id) {
390                                                                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
391                                                                         }
392                                                                 );
393
394                                                                 var edit = 0;
395                                                                 try {
396                                                                         edit = obj.network.request(
397                                                                                 api.PERM_MULTI_ORG_CHECK.app,
398                                                                                 api.PERM_MULTI_ORG_CHECK.method,
399                                                                                 [ 
400                                                                                         ses(), 
401                                                                                         obj.data.list.au[0].id(), 
402                                                                                         util.functional.map_list(
403                                                                                                 copies,
404                                                                                                 function (o) {
405                                                                                                         return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
406                                                                                                 }
407                                                                                         ),
408                                                                                         copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
409                                                                                 ]
410                                                                         ).length == 0 ? 1 : 0;
411                                                                 } catch(E) {
412                                                                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
413                                                                 }
414
415                                                                 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
416
417                                                                 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
418                                                                 setTimeout(
419                                                                         function() {
420                                                                                 JSAN.use('util.widgets'); 
421                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
422                                                                         }, 0
423                                                                 );
424                                                         } catch(E) {
425                                                                 alert( js2JSON(E) );
426                                                         }
427                                                 }
428                                         ],
429                                         'copy_buckets_batch_copy_delete' : [
430                                                 ['command'],
431                                                 function() {
432                                                         try {
433                                                         
434                                                                 obj.list2.select_all();
435
436                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
437
438                                                                 var list = util.functional.map_list(
439                                                                         obj.list2.dump_retrieve_ids(),
440                                                                         function (o) {
441                                                                                 return JSON2js(o)[0]; // acp_id
442                                                                         }
443                                                                 );
444
445                                                                 var copies = util.functional.map_list(
446                                                                         list,
447                                                                         function (acp_id) {
448                                                                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
449                                                                         }
450                                                                 );
451
452                                                                 for (var i = 0; i < copies.length; i++) {
453                                                                         copies[i].ischanged(1);
454                                                                         copies[i].isdeleted(1);
455                                                                 }
456
457                                                                 var robj = obj.network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE',[ ses(), copies, true]);
458                                                                 if (typeof robj.ilsevent != 'undefined') obj.error.standard_unexpected_error_alert('Batch Item Deletion',robj);
459
460                                                                 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
461                                                                 setTimeout(
462                                                                         function() {
463                                                                                 JSAN.use('util.widgets'); 
464                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
465                                                                         }, 0
466                                                                 );
467                                                         } catch(E) {
468                                                                 alert( js2JSON(E) );
469                                                         }
470                                                 }
471                                         ],
472
473                                         'copy_buckets_transfer_to_volume' : [
474                                                 ['command'],
475                                                 function() {
476                                                         try {
477                                                                 obj.list2.select_all();
478
479                                                                 obj.data.stash_retrieve();
480                                                                 if (!obj.data.marked_volume) {
481                                                                         alert('Please mark a volume as the destination from within the copy browser and then try this again.');
482                                                                         return;
483                                                                 }
484
485                                                                 var copy_ids = util.functional.map_list(
486                                                                         obj.list2.dump_retrieve_ids(),
487                                                                         function (o) {
488                                                                                 return JSON2js(o)[0]; // acp_id
489                                                                         }
490                                                                 )
491
492                                                                 var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
493
494                                                                 var msg = 'Transfer the items in bucket "';
495                                                                 msg += obj.controller.view.bucket_menulist.getAttribute('label') + '" ';
496                                                                 msg += 'from their original volumes to ';
497                                                                 msg += obj.data.hash.aou[ volume.owning_lib() ].shortname() + "'s volume labelled ";
498                                                                 msg += '"' + volume.label() + '" on the following record?';
499
500                                                                 JSAN.use('cat.util'); cat.util.transfer_copies( { 
501                                                                         'copy_ids' : copy_ids, 
502                                                                         'message' : msg, 
503                                                                         'docid' : volume.record(),
504                                                                         'volume_label' : volume.label(),
505                                                                         'owning_lib' : volume.owning_lib(),
506                                                                 } );
507
508                                                                 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
509                                                                 setTimeout(
510                                                                         function() {
511                                                                                 JSAN.use('util.widgets'); 
512                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
513                                                                         }, 0
514                                                                 );
515                                                                 
516                                                         } catch(E) {
517                                                                 obj.error.standard_unexpected_error_alert('Items not likely transferred.',E);
518                                                         }
519                                                 }
520                                         ],
521                                         'cmd_broken' : [
522                                                 ['command'],
523                                                 function() { alert('Not Yet Implemented'); }
524                                         ],
525                                         'cmd_copy_buckets_print' : [
526                                                 ['command'],
527                                                 function() {
528                                                         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
529                                                         obj.list2.on_all_fleshed = function() {
530                                                                 try {
531                                                                         dump( js2JSON( obj.list2.dump_with_keys() ) + '\n' );
532                                                                         data.stash_retrieve();
533                                                                         var lib = data.hash.aou[ data.list.au[0].ws_ou() ];
534                                                                         lib.children(null);
535                                                                         var p = { 
536                                                                                 'lib' : lib,
537                                                                                 'staff' : data.list.au[0],
538                                                                                 'header' : data.print_list_templates.item_status.header,
539                                                                                 'line_item' : data.print_list_templates.item_status.line_item,
540                                                                                 'footer' : data.print_list_templates.item_status.footer,
541                                                                                 'type' : data.print_list_templates.item_status.type,
542                                                                                 'list' : obj.list2.dump_with_keys(),
543                                                                         };
544                                                                         JSAN.use('util.print'); var print = new util.print();
545                                                                         print.tree_list( p );
546                                                                         setTimeout(function(){obj.list2.on_all_fleshed = null;},0);
547                                                                 } catch(E) {
548                                                                         alert(E); 
549                                                                 }
550                                                         }
551                                                         obj.list2.full_retrieve();
552                                                 }
553                                         ],
554                                         'cmd_copy_buckets_export' : [
555                                                 ['command'],
556                                                 function() {
557                                                         obj.list2.on_all_fleshed = function() {
558                                                                 try {
559                                                                         dump(obj.list2.dump_csv() + '\n');
560                                                                         copy_to_clipboard(obj.list2.dump_csv());
561                                                                         setTimeout(function(){obj.list2.on_all_fleshed = null;},0);
562                                                                 } catch(E) {
563                                                                         alert(E); 
564                                                                 }
565                                                         }
566                                                         obj.list2.full_retrieve();
567                                                 }
568                                         ],
569                                         'cmd_export1' : [
570                                                 ['command'],
571                                                 function() {
572                                                         obj.list1.on_all_fleshed = function() {
573                                                                 try {
574                                                                         dump(obj.list1.dump_csv() + '\n');
575                                                                         copy_to_clipboard(obj.list1.dump_csv());
576                                                                         setTimeout(function(){obj.list1.on_all_fleshed = null;},0);
577                                                                 } catch(E) {
578                                                                         alert(E); 
579                                                                 }
580                                                         }
581                                                         obj.list1.full_retrieve();
582                                                 }
583                                         ],
584
585                     'cmd_print_export1' : [
586                         ['command'],
587                         function() {
588                             try {
589                                 obj.list1.on_all_fleshed =
590                                     function() {
591                                         try {
592                                             dump( obj.list1.dump_csv() + '\n' );
593                                             //copy_to_clipboard(obj.list.dump_csv());
594                                             JSAN.use('util.print'); var print = new util.print();
595                                             print.simple(obj.list1.dump_csv(),{'content_type':'text/plain'});
596                                             setTimeout(function(){ obj.list1.on_all_fleshed = null; },0);
597                                         } catch(E) {
598                                             obj.error.standard_unexpected_error_alert('print export',E);
599                                         }
600                                     }
601                                 obj.list1.full_retrieve();
602                             } catch(E) {
603                                 obj.error.standard_unexpected_error_alert('print export',E);
604                             }
605                         }
606                     ],
607
608
609                     'cmd_print_export2' : [
610                         ['command'],
611                         function() {
612                             try {
613                                 obj.list2.on_all_fleshed =
614                                     function() {
615                                         try {
616                                             dump( obj.list2.dump_csv() + '\n' );
617                                             //copy_to_clipboard(obj.list.dump_csv());
618                                             JSAN.use('util.print'); var print = new util.print();
619                                             print.simple(obj.list2.dump_csv(),{'content_type':'text/plain'});
620                                             setTimeout(function(){ obj.list2.on_all_fleshed = null; },0);
621                                         } catch(E) {
622                                             obj.error.standard_unexpected_error_alert('print export',E);
623                                         }
624                                     }
625                                 obj.list2.full_retrieve();
626                             } catch(E) {
627                                 obj.error.standard_unexpected_error_alert('print export',E);
628                             }
629                         }
630                     ],
631
632                                         'cmd_copy_buckets_reprint' : [
633                                                 ['command'],
634                                                 function() {
635                                                 }
636                                         ],
637                                         'cmd_copy_buckets_done' : [
638                                                 ['command'],
639                                                 function() {
640                                                         window.close();
641                                                 }
642                                         ],
643                                         'cmd_export_to_copy_status' : [
644                                                 ['command'],
645                                                 function() {
646                                                         try {
647                                                                 obj.list2.select_all();
648                                                                 JSAN.use('util.functional');
649                                                                 var barcodes = util.functional.map_list(
650                                                                         obj.list2.dump_retrieve_ids(),
651                                                                         function(o) { return JSON2js(o)[1]; }
652                                                                 );
653                                                                 var url = urls.XUL_COPY_STATUS; // + '?barcodes=' + window.escape( js2JSON(barcodes) );
654                                                                 //JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
655                                                                 //data.temp_barcodes_for_copy_status = barcodes;
656                                                                 //data.stash('temp_barcodes_for_copy_status');
657                                                                 xulG.new_tab( url, {}, { 'barcodes' : barcodes });
658                                                         } catch(E) {
659                                                                 obj.error.standard_unexpected_error_alert('Copy Status from Copy Buckets',E);
660                                                         }
661                                                 }
662                                         ],
663                                 }
664                         }
665                 );
666                 this.controller.render();
667
668                 if (typeof xulG == 'undefined') {
669                         obj.controller.view.cmd_export_to_copy_status.disabled = true;
670                         obj.controller.view.cmd_export_to_copy_status.setAttribute('disabled',true);
671                 } else {
672                         obj.controller.view.cmd_copy_buckets_done.disabled = true;
673                         obj.controller.view.cmd_copy_buckets_done.setAttribute('disabled',true);
674                 }
675         
676         },
677
678         'flesh_item_for_list' : function(acp_id,bucket_item_id) {
679                 var obj = this;
680                 try {
681                         var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ acp_id ]);
682                         if (copy == null || typeof copy.ilsevent != 'undefined') {
683                                 throw(copy);
684                         } else {
685                                 var item = {
686                                         'retrieve_id' : js2JSON( [ copy.id(), copy.barcode(), bucket_item_id ] ),
687                                         'row' : {
688                                                 'my' : {
689                                                         'mvr' : obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]),
690                                                         'acp' : copy,
691                                                 }
692                                         }
693                                 };
694                                 return item;
695                         }
696                 } catch(E) {
697                         obj.error.standard_unexpected_error_alert('List building failed.',E);
698                         return null;
699                 }
700
701         },
702         
703 }
704
705 dump('exiting cat.copy_buckets.js\n');