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