]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_buckets.js
21c716945e7a4ebf2ecce914545d159b0daeca63
[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') throw robj;
348
349                                                                         alert('Bucket "' + name + '" created.');
350
351                                                                         obj.controller.render('copy_buckets_menulist_placeholder');
352                                                                         obj.controller.view.bucket_menulist.value = robj;
353                                                                         setTimeout(
354                                                                                 function() {
355                                                                                         JSAN.use('util.widgets'); 
356                                                                                         util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
357                                                                                 }, 0
358                                                                         );
359                                                                 }
360                                                         } catch(E) {
361                                                                 obj.error.standard_unexpected_error_alert('Bucket creation failed.',E);
362                                                         }
363                                                 }
364                                         ],
365                                         'copy_buckets_batch_copy_edit' : [
366                                                 ['command'],
367                                                 function() {
368                                                         try {
369
370                                                                 obj.list2.select_all();
371                                                         
372                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
373
374                                                                 var list = util.functional.map_list(
375                                                                         obj.list2.dump_retrieve_ids(),
376                                                                         function (o) {
377                                                                                 return JSON2js(o)[0]; // acp_id
378                                                                         }
379                                                                 );
380
381                                                                 var copies = util.functional.map_list(
382                                                                         list,
383                                                                         function (acp_id) {
384                                                                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
385                                                                         }
386                                                                 );
387
388                                                                 var edit = 0;
389                                                                 try {
390                                                                         edit = obj.network.request(
391                                                                                 api.PERM_MULTI_ORG_CHECK.app,
392                                                                                 api.PERM_MULTI_ORG_CHECK.method,
393                                                                                 [ 
394                                                                                         ses(), 
395                                                                                         obj.data.list.au[0].id(), 
396                                                                                         util.functional.map_list(
397                                                                                                 copies,
398                                                                                                 function (o) {
399                                                                                                         return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
400                                                                                                 }
401                                                                                         ),
402                                                                                         copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
403                                                                                 ]
404                                                                         ).length == 0 ? 1 : 0;
405                                                                 } catch(E) {
406                                                                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
407                                                                 }
408
409                                                                 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
410
411                                                                 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
412                                                                 setTimeout(
413                                                                         function() {
414                                                                                 JSAN.use('util.widgets'); 
415                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
416                                                                         }, 0
417                                                                 );
418                                                         } catch(E) {
419                                                                 alert( js2JSON(E) );
420                                                         }
421                                                 }
422                                         ],
423                                         'copy_buckets_batch_copy_delete' : [
424                                                 ['command'],
425                                                 function() {
426                                                         try {
427                                                         
428                                                                 obj.list2.select_all();
429
430                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
431
432                                                                 var list = util.functional.map_list(
433                                                                         obj.list2.dump_retrieve_ids(),
434                                                                         function (o) {
435                                                                                 return JSON2js(o)[0]; // acp_id
436                                                                         }
437                                                                 );
438
439                                                                 var copies = util.functional.map_list(
440                                                                         list,
441                                                                         function (acp_id) {
442                                                                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
443                                                                         }
444                                                                 );
445
446                                                                 for (var i = 0; i < copies.length; i++) {
447                                                                         copies[i].ischanged(1);
448                                                                         copies[i].isdeleted(1);
449                                                                 }
450
451                                                                 var robj = obj.network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE',[ ses(), copies, true]);
452                                                                 if (typeof robj.ilsevent != 'undefined') obj.error.standard_unexpected_error_alert('Batch Item Deletion',robj);
453
454                                                                 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
455                                                                 setTimeout(
456                                                                         function() {
457                                                                                 JSAN.use('util.widgets'); 
458                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
459                                                                         }, 0
460                                                                 );
461                                                         } catch(E) {
462                                                                 alert( js2JSON(E) );
463                                                         }
464                                                 }
465                                         ],
466
467                                         'copy_buckets_transfer_to_volume' : [
468                                                 ['command'],
469                                                 function() {
470                                                         try {
471                                                                 obj.list2.select_all();
472
473                                                                 obj.data.stash_retrieve();
474                                                                 if (!obj.data.marked_volume) {
475                                                                         alert('Please mark a volume as the destination from within the copy browser and then try this again.');
476                                                                         return;
477                                                                 }
478
479                                                                 var copy_ids = util.functional.map_list(
480                                                                         obj.list2.dump_retrieve_ids(),
481                                                                         function (o) {
482                                                                                 return JSON2js(o)[0]; // acp_id
483                                                                         }
484                                                                 )
485
486                                                                 var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
487
488                                                                 var msg = 'Transfer the items in bucket "';
489                                                                 msg += obj.controller.view.bucket_menulist.getAttribute('label') + '" ';
490                                                                 msg += 'from their original volumes to ';
491                                                                 msg += obj.data.hash.aou[ volume.owning_lib() ].shortname() + "'s volume labelled ";
492                                                                 msg += '"' + volume.label() + '" on the following record?';
493
494                                                                 JSAN.use('cat.util'); cat.util.transfer_copies( { 
495                                                                         'copy_ids' : copy_ids, 
496                                                                         'message' : msg, 
497                                                                         'docid' : volume.record(),
498                                                                         'volume_label' : volume.label(),
499                                                                         'owning_lib' : volume.owning_lib(),
500                                                                 } );
501
502                                                                 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
503                                                                 setTimeout(
504                                                                         function() {
505                                                                                 JSAN.use('util.widgets'); 
506                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
507                                                                         }, 0
508                                                                 );
509                                                                 
510                                                         } catch(E) {
511                                                                 obj.error.standard_unexpected_error_alert('Items not likely transferred.',E);
512                                                         }
513                                                 }
514                                         ],
515                                         'cmd_broken' : [
516                                                 ['command'],
517                                                 function() { alert('Not Yet Implemented'); }
518                                         ],
519                                         'cmd_copy_buckets_print' : [
520                                                 ['command'],
521                                                 function() {
522                                                         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
523                                                         obj.list2.on_all_fleshed = function() {
524                                                                 try {
525                                                                         dump( js2JSON( obj.list2.dump_with_keys() ) + '\n' );
526                                                                         data.stash_retrieve();
527                                                                         var lib = data.hash.aou[ data.list.au[0].ws_ou() ];
528                                                                         lib.children(null);
529                                                                         var p = { 
530                                                                                 'lib' : lib,
531                                                                                 'staff' : data.list.au[0],
532                                                                                 'header' : data.print_list_templates.item_status.header,
533                                                                                 'line_item' : data.print_list_templates.item_status.line_item,
534                                                                                 'footer' : data.print_list_templates.item_status.footer,
535                                                                                 'type' : data.print_list_templates.item_status.type,
536                                                                                 'list' : obj.list2.dump_with_keys(),
537                                                                         };
538                                                                         JSAN.use('util.print'); var print = new util.print();
539                                                                         print.tree_list( p );
540                                                                         setTimeout(function(){obj.list2.on_all_fleshed = null;},0);
541                                                                 } catch(E) {
542                                                                         alert(E); 
543                                                                 }
544                                                         }
545                                                         obj.list2.full_retrieve();
546                                                 }
547                                         ],
548                                         'cmd_copy_buckets_export' : [
549                                                 ['command'],
550                                                 function() {
551                                                         obj.list2.on_all_fleshed = function() {
552                                                                 try {
553                                                                         dump(obj.list2.dump_csv() + '\n');
554                                                                         copy_to_clipboard(obj.list2.dump_csv());
555                                                                         setTimeout(function(){obj.list2.on_all_fleshed = null;},0);
556                                                                 } catch(E) {
557                                                                         alert(E); 
558                                                                 }
559                                                         }
560                                                         obj.list2.full_retrieve();
561                                                 }
562                                         ],
563                                         'cmd_export1' : [
564                                                 ['command'],
565                                                 function() {
566                                                         obj.list1.on_all_fleshed = function() {
567                                                                 try {
568                                                                         dump(obj.list1.dump_csv() + '\n');
569                                                                         copy_to_clipboard(obj.list1.dump_csv());
570                                                                         setTimeout(function(){obj.list1.on_all_fleshed = null;},0);
571                                                                 } catch(E) {
572                                                                         alert(E); 
573                                                                 }
574                                                         }
575                                                         obj.list1.full_retrieve();
576                                                 }
577                                         ],
578
579                     'cmd_print_export1' : [
580                         ['command'],
581                         function() {
582                             try {
583                                 obj.list1.on_all_fleshed =
584                                     function() {
585                                         try {
586                                             dump( obj.list1.dump_csv() + '\n' );
587                                             //copy_to_clipboard(obj.list.dump_csv());
588                                             JSAN.use('util.print'); var print = new util.print();
589                                             print.simple(obj.list1.dump_csv(),{'content_type':'text/plain'});
590                                             setTimeout(function(){ obj.list1.on_all_fleshed = null; },0);
591                                         } catch(E) {
592                                             obj.error.standard_unexpected_error_alert('print export',E);
593                                         }
594                                     }
595                                 obj.list1.full_retrieve();
596                             } catch(E) {
597                                 obj.error.standard_unexpected_error_alert('print export',E);
598                             }
599                         }
600                     ],
601
602
603                     'cmd_print_export2' : [
604                         ['command'],
605                         function() {
606                             try {
607                                 obj.list2.on_all_fleshed =
608                                     function() {
609                                         try {
610                                             dump( obj.list2.dump_csv() + '\n' );
611                                             //copy_to_clipboard(obj.list.dump_csv());
612                                             JSAN.use('util.print'); var print = new util.print();
613                                             print.simple(obj.list2.dump_csv(),{'content_type':'text/plain'});
614                                             setTimeout(function(){ obj.list2.on_all_fleshed = null; },0);
615                                         } catch(E) {
616                                             obj.error.standard_unexpected_error_alert('print export',E);
617                                         }
618                                     }
619                                 obj.list2.full_retrieve();
620                             } catch(E) {
621                                 obj.error.standard_unexpected_error_alert('print export',E);
622                             }
623                         }
624                     ],
625
626                                         'cmd_copy_buckets_reprint' : [
627                                                 ['command'],
628                                                 function() {
629                                                 }
630                                         ],
631                                         'cmd_copy_buckets_done' : [
632                                                 ['command'],
633                                                 function() {
634                                                         window.close();
635                                                 }
636                                         ],
637                                         'cmd_export_to_copy_status' : [
638                                                 ['command'],
639                                                 function() {
640                                                         try {
641                                                                 obj.list2.select_all();
642                                                                 JSAN.use('util.functional');
643                                                                 var barcodes = util.functional.map_list(
644                                                                         obj.list2.dump_retrieve_ids(),
645                                                                         function(o) { return JSON2js(o)[1]; }
646                                                                 );
647                                                                 var url = urls.XUL_COPY_STATUS; // + '?barcodes=' + window.escape( js2JSON(barcodes) );
648                                                                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
649                                                                 data.temp_barcodes_for_copy_status = barcodes;
650                                                                 data.stash('temp_barcodes_for_copy_status');
651                                                                 xulG.new_tab( url, {}, {});
652                                                         } catch(E) {
653                                                                 obj.error.standard_unexpected_error_alert('Copy Status from Copy Buckets',E);
654                                                         }
655                                                 }
656                                         ],
657                                 }
658                         }
659                 );
660                 this.controller.render();
661
662                 if (typeof xulG == 'undefined') {
663                         obj.controller.view.cmd_export_to_copy_status.disabled = true;
664                         obj.controller.view.cmd_export_to_copy_status.setAttribute('disabled',true);
665                 } else {
666                         obj.controller.view.cmd_copy_buckets_done.disabled = true;
667                         obj.controller.view.cmd_copy_buckets_done.setAttribute('disabled',true);
668                 }
669         
670         },
671
672         'flesh_item_for_list' : function(acp_id,bucket_item_id) {
673                 var obj = this;
674                 try {
675                         var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ acp_id ]);
676                         if (copy == null || typeof copy.ilsevent != 'undefined') {
677                                 throw(copy);
678                         } else {
679                                 var item = {
680                                         'retrieve_id' : js2JSON( [ copy.id(), copy.barcode(), bucket_item_id ] ),
681                                         'row' : {
682                                                 'my' : {
683                                                         'mvr' : obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]),
684                                                         'acp' : copy,
685                                                 }
686                                         }
687                                 };
688                                 return item;
689                         }
690                 } catch(E) {
691                         obj.error.standard_unexpected_error_alert('List building failed.',E);
692                         return null;
693                 }
694
695         },
696         
697 }
698
699 dump('exiting cat.copy_buckets.js\n');