]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_browser.js
Improve COPY_DELETE_WARNING event handling
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / cat / copy_browser.js
1 dump('entering cat.copy_browser.js\n');
2 // vim:noet:sw=4:ts=4:
3
4 if (typeof cat == 'undefined') cat = {};
5 cat.copy_browser = function (params) {
6     try {
7         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
8         JSAN.use('util.error'); this.error = new util.error();
9     } catch(E) {
10         dump('cat.copy_browser: ' + E + '\n');
11     }
12 }
13
14 cat.copy_browser.prototype = {
15
16     'map_tree' : {},
17     'map_acn' : {},
18     'map_acp' : {},
19     'sel_list' : [],
20     'funcs' : [],
21
22     'init' : function( params ) {
23
24         try {
25             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
26             var obj = this;
27
28             obj.docid = params.docid;
29
30             JSAN.use('util.network'); obj.network = new util.network();
31             JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
32
33             obj.controller_init(params);
34
35             obj.list_init(params);
36
37             obj.source_init();
38
39             obj.controller.render();
40
41             obj.default_depth = obj.depth_menu_init();
42             obj.default_lib = obj.data.hash.aou[ obj.library_menu_init() ];
43
44             document.getElementById('show_acns').addEventListener(
45                 'command',
46                 function(ev) {
47                     JSAN.use('util.file');
48                     var file = new util.file(
49                         'copy_browser_prefs.'+obj.data.server_unadorned);
50                     util.widgets.save_attributes(file, {
51                         'lib_menu' : [ 'value' ],
52                         'depth_menu' : [ 'value' ],
53                         'show_acns' : [ 'checked' ],
54                         'show_acps' : [ 'checked' ],
55                         'hide_aous' : [ 'checked' ] });
56                 },
57                 false
58             );
59
60             document.getElementById('show_acps').addEventListener(
61                 'command',
62                 function(ev) {
63                     JSAN.use('util.file');
64                     var file = new util.file(
65                         'copy_browser_prefs.'+obj.data.server_unadorned);
66                     util.widgets.save_attributes(file, {
67                         'lib_menu' : [ 'value' ],
68                         'depth_menu' : [ 'value' ],
69                         'show_acns' : [ 'checked' ],
70                         'show_acps' : [ 'checked' ],
71                         'hide_aous' : [ 'checked' ] });
72                 },
73                 false
74             );
75
76             document.getElementById('hide_aous').addEventListener(
77                 'command',
78                 function(ev) {
79                     JSAN.use('util.file');
80                     var file = new util.file(
81                         'copy_browser_prefs.'+obj.data.server_unadorned);
82                     util.widgets.save_attributes(file, {
83                         'lib_menu' : [ 'value' ],
84                         'depth_menu' : [ 'value' ],
85                         'show_acns' : [ 'checked' ],
86                         'show_acps' : [ 'checked' ],
87                         'hide_aous' : [ 'checked' ] });
88                 },
89                 false
90             );
91
92             obj.show_my_libs( obj.default_lib.id() );
93
94             JSAN.use('util.exec'); var exec = new util.exec(20); exec.timer(obj.funcs,100);
95
96             obj.show_consortial_count();
97
98         } catch(E) {
99             this.error.standard_unexpected_error_alert('cat.copy_browser.init: ',E);
100         }
101     },
102
103     'controller_init' : function(params) {
104         var obj = this;
105         try {
106             JSAN.use('util.controller'); obj.controller = new util.controller();
107             obj.controller.init(
108                 {
109                     control_map : {
110                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
111                         'sel_clip' : [
112                             ['command'],
113                             function() { obj.list.clipboard(); }
114                         ],
115                         'cmd_broken' : [
116                             ['command'],
117                             function() { 
118                                 alert(document.getElementById('commonStrings').getString('common.unimplemented'));
119                             }
120                         ],
121                         'cmd_show_my_libs' : [
122                             ['command'],
123                             function() { 
124                                 obj.show_my_libs(); 
125                             }
126                         ],
127                         'cmd_show_all_libs' : [
128                             ['command'],
129                             function() {
130                                 obj.show_all_libs();
131                             }
132                         ],
133                         'cmd_show_libs_with_copies' : [
134                             ['command'],
135                             function() {
136                                 obj.show_libs_with_copies();
137                             }
138                         ],
139                         'cmd_clear' : [
140                             ['command'],
141                             function() {
142                                 obj.map_tree = {};
143                                 obj.list.clear();
144                             }
145                         ],
146                         'cmd_request_items' : [
147                             ['command'],
148                             function() {
149                                 JSAN.use('cat.util'); JSAN.use('util.functional');
150
151                                 var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; });
152
153                                 list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; });
154
155                                 cat.util.request_items( list );
156                             }
157                         ],
158                         'sel_mark_items_damaged' : [
159                             ['command'],
160                             function() {
161                                 JSAN.use('cat.util'); JSAN.use('util.functional');
162
163                                 var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; });
164
165                                 list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; });
166
167                                 cat.util.mark_item_damaged( list );
168
169                                 obj.refresh_list();
170                             }
171                         ],
172                         'sel_mark_items_missing' : [
173                             ['command'],
174                             function() {
175                                 JSAN.use('cat.util'); JSAN.use('util.functional');
176
177                                 var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; });
178
179                                 list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; });
180
181                                 cat.util.mark_item_missing( list );
182
183                                 obj.refresh_list();
184                             }
185                         ],
186                         'sel_patron' : [
187                             ['command'],
188                             function() {
189                                 JSAN.use('util.functional');
190
191                                 var list = util.functional.filter_list(
192                                     obj.sel_list,
193                                     function (o) {
194                                         return o.split(/_/)[0] == 'acp';
195                                     }
196                                 );
197
198                                 list = util.functional.map_list(
199                                     list,
200                                     function (o) {
201                                         return { 'copy_id' : o.split(/_/)[1] };
202                                     }
203                                 );
204                                 
205                                 JSAN.use('circ.util');
206                                 circ.util.show_last_few_circs(list);
207                             }
208                         ],
209                         'sel_copy_details' : [
210                             ['command'],
211                             function() {
212                                 JSAN.use('util.functional');
213
214                                 var list = util.functional.filter_list(
215                                     obj.sel_list,
216                                     function (o) {
217                                         return o.split(/_/)[0] == 'acp';
218                                     }
219                                 );
220
221                                 JSAN.use('circ.util');
222                                 circ.util.item_details_new(
223                                     util.functional.map_list(
224                                         list, function (o) {
225                                             return obj.map_acp[o].barcode();
226                                         }
227                                     )
228                                 );
229                             }
230                         ],
231                         'cmd_create_brt' : [
232                             ['command'],
233                             function() {
234                                 JSAN.use("cat.util");
235                                 JSAN.use("util.functional");
236
237                                 /* Filter selected rows that aren"t copies. */
238                                 var list = util.functional.filter_list(
239                                     obj.sel_list,
240                                     function (o) {
241                                         return o.split(/_/)[0] == "acp";
242                                     }
243                                 );
244                                 var results = cat.util.make_bookable(
245                                     util.functional.map_list(
246                                         list, function (o) {
247                                             return obj.map_acp[o].id();
248                                         }
249                                     )
250                                 );
251                                 if (results && results["brsrc"]) {
252                                     cat.util.edit_new_brsrc(results["brsrc"]);
253                                 }
254                             }
255                         ],
256                         'cmd_book_item_now' : [
257                             ['command'],
258                             function() {
259                                 JSAN.use("cat.util");
260                                 JSAN.use("util.functional");
261
262                                 /* Filter selected rows that aren"t copies. */
263                                 var list = util.functional.filter_list(
264                                     obj.sel_list,
265                                     function (o) {
266                                         return o.split(/_/)[0] == "acp";
267                                     }
268                                 );
269                                 var results = cat.util.make_bookable(
270                                     util.functional.map_list(
271                                         list, function (o) {
272                                             return obj.map_acp[o].id();
273                                         }
274                                     )
275                                 );
276                                 if (results) {
277                                     cat.util.edit_new_bresv(results);
278                                 }
279                             }
280                         ],
281                         'cmd_add_items' : [
282                             ['command'],
283                             function() {
284                                 try {
285                                     JSAN.use('util.functional');
286                                     var list = util.functional.map_list(
287                                         util.functional.filter_list(
288                                             obj.sel_list,
289                                             function (o) {
290                                                 return o.split(/_/)[0] == 'acn';
291                                             }
292                                         ),
293                                         function (o) {
294                                             return o.split(/_/)[1];
295                                         }
296                                     );
297                                     if (list.length == 0) return;
298
299                                     var copy_shortcut = {};
300                                     list = util.functional.map_list(
301                                         list,
302                                         function (o) {
303                                             var call_number = obj.map_acn['acn_'+o];
304                                             var ou_id = call_number.owning_lib();
305                                             var volume_id = o;
306                                             var label = call_number.label();
307                                             var acnc_id = typeof call_number.label_class() == 'object'
308                                                 ? call_number.label_class().id()
309                                                 : call_number.label_class();
310                                             var acnp_id = typeof call_number.prefix() == 'object'
311                                                 ? call_number.prefix().id()
312                                                 : call_number.prefix();
313                                             var acns_id = typeof call_number.suffix() == 'object'
314                                                 ? call_number.suffix().id()
315                                                 : call_number.suffix();
316                                             if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {};
317                                             var callnumber_composite_key = acnc_id + ':' + acnp_id + ':' + label + ':' + acns_id;
318                                             copy_shortcut[ou_id][ callnumber_composite_key ] = volume_id;
319
320                                             return ou_id;
321                                         }
322                                     );
323                                     /* quick fix */  /* what was this fixing? */
324                                     list = []; for (var i in copy_shortcut) { list.push( i ); }
325
326                                     var edit = 0;
327                                     try {
328                                         edit = obj.network.request(
329                                             api.PERM_MULTI_ORG_CHECK.app,
330                                             api.PERM_MULTI_ORG_CHECK.method,
331                                             [ 
332                                                 ses(), 
333                                                 obj.data.list.au[0].id(), 
334                                                 list,
335                                                 [ 'CREATE_COPY' ]
336                                             ]
337                                         ).length == 0 ? 1 : 0;
338                                     } catch(E) {
339                                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
340                                     }
341
342                                     if (edit==0) return; // no read-only view for this interface
343
344                                     if (!obj.can_have_copies) {
345                                         alert(document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.can_have_copies.false', obj.source));
346                                         return;
347                                     }
348
349                                     var title = document.getElementById('catStrings').getString('staff.cat.copy_browser.add_item.title');
350
351                                     var url;
352                                     var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true';
353                                     if (unified_interface) {
354                                         var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true';
355                                         url = xulG.url_prefix( horizontal_interface ? urls.XUL_VOLUME_COPY_CREATOR_HORIZONTAL : urls.XUL_VOLUME_COPY_CREATOR );
356                                     } else {
357                                         url = xulG.url_prefix( urls.XUL_VOLUME_COPY_CREATOR_ORIGINAL );
358                                     }
359
360                                     var w = xulG.new_tab(
361                                         url,
362                                         { 'tab_name' : title },
363                                         {
364                                             'doc_id' : obj.docid, 
365                                             'ou_ids' : list, 
366                                             'copy_shortcut' : copy_shortcut,
367                                             'onrefresh' : function() { obj.refresh_list(); }
368                                         }
369                                     );
370                                 } catch(E) {
371                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_item.error'),E);
372                                 }
373                             }
374                         ],
375                         'cmd_add_items_to_buckets' : [
376                             ['command'],
377                             function() {
378                                 try {
379                                     JSAN.use('util.functional');
380
381                                     var list = util.functional.filter_list(
382                                         obj.sel_list,
383                                         function (o) {
384                                             return o.split(/_/)[0] == 'acp';
385                                         }
386                                     );
387
388                                     list = util.functional.map_list(
389                                         list,
390                                         function (o) {
391                                             return o.split(/_/)[1];
392                                         }
393                                     );
394                                 
395                                     JSAN.use('cat.util');
396                                     cat.util.add_copies_to_bucket( list );
397
398                                 } catch(E) {
399                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_items_bucket.error'),E);
400                                 }
401                             }
402                         ],
403                         'cmd_edit_items' : [
404                             ['command'],
405                             function() {
406                                 try {
407                                     var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true';
408                                     if (!unified_interface) {
409                                         obj.controller.control_map['old_cmd_edit_items'][1]();
410                                         return;
411                                     }
412
413                                     JSAN.use('util.functional');
414
415                                     var list = util.functional.filter_list(
416                                         obj.sel_list,
417                                         function (o) {
418                                             return o.split(/_/)[0] == 'acp';
419                                         }
420                                     );
421
422                                     list = util.functional.map_list(
423                                         list,
424                                         function (o) {
425                                             var cloned_copy_obj = JSON2js( js2JSON( obj.map_acp[ o ] ) );
426                                             cloned_copy_obj.call_number( obj.map_acn[ 'acn_' + cloned_copy_obj.call_number() ] );
427                                             return cloned_copy_obj;
428                                         }
429                                     );
430
431                                     xulG.volume_item_creator( {'existing_copies':list, 'onrefresh' : function() { obj.refresh_list(); } } );
432
433                                 } catch(E) {
434                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E);
435                                     obj.refresh_list();
436                                 }
437                             }
438                         ],
439                         'cmd_replace_barcode' : [
440                             ['command'],
441                             function() {
442                                 try {
443                                     JSAN.use('util.functional');
444
445                                     var list = util.functional.filter_list(
446                                         obj.sel_list,
447                                         function (o) {
448                                             return o.split(/_/)[0] == 'acp';
449                                         }
450                                     );
451
452                                     list = util.functional.map_list(
453                                         list,
454                                         function (o) {
455                                             var cloned_copy_obj = JSON2js( js2JSON( obj.map_acp[ o ] ) );
456                                             cloned_copy_obj.call_number( obj.map_acn[ 'acn_' + cloned_copy_obj.call_number() ] );
457                                             return cloned_copy_obj;
458                                         }
459                                     );
460
461                                     xulG.volume_item_creator( {'existing_copies':list, 'onrefresh' : function() { obj.refresh_list(); } } );
462
463                                 } catch(E) {
464                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E);
465                                     obj.refresh_list();
466                                 }
467                             }
468                         ],
469
470                         'old_cmd_edit_items' : [
471                             ['command'],
472                             function() {
473                                 try {
474                                     JSAN.use('util.functional');
475
476                                     var list = util.functional.filter_list(
477                                         obj.sel_list,
478                                         function (o) {
479                                             return o.split(/_/)[0] == 'acp';
480                                         }
481                                     );
482
483                                     list = util.functional.map_list(
484                                         list,
485                                         function (o) {
486                                             return o.split(/_/)[1];
487                                         }
488                                     );
489
490                                     JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
491                                     obj.refresh_list();
492
493                                 } catch(E) {
494                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E);
495                                 }
496                             }
497                         ],
498                         'cmd_delete_items' : [
499                             ['command'],
500                             function() {
501                                 try {
502                                     JSAN.use('util.functional');
503
504                                     var list = util.functional.filter_list(
505                                         obj.sel_list,
506                                         function (o) {
507                                             return o.split(/_/)[0] == 'acp';
508                                         }
509                                     );
510
511                                     list = util.functional.map_list(
512                                         list,
513                                         function (o) {
514                                             return JSON2js( js2JSON( obj.map_acp[ 'acp_' + o.split(/_/)[1] ] ) );
515                                         }
516                                     );
517
518                                     var delete_msg;
519                                     if (list.length != 1) {
520                                         delete_msg = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_items.confirm.plural', [list.length]);
521                                     } else {
522                                         delete_msg = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.confirm');
523                                     }
524                                     var r = obj.error.yns_alert(
525                                             delete_msg,
526                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.title'),
527                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.delete'),
528                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.cancel'),
529                                             null,
530                                             document.getElementById('commonStrings').getString('common.confirm')
531                                     );
532
533                                     if (r == 0) {
534                                         var acn_hash = {}; var acn_list = [];
535                                         for (var i = 0; i < list.length; i++) {
536                                             list[i].isdeleted('1');
537                                             var acn_id = list[i].call_number();
538                                             if ( ! acn_hash[ acn_id ] ) {
539                                                 acn_hash[ acn_id ] = obj.map_acn[ 'acn_' + acn_id ];
540                                                 acn_hash[ acn_id ].copies( [] );
541                                             }
542                                             var temp = acn_hash[ acn_id ].copies();
543                                             temp.push( list[i] );
544                                             acn_hash[ acn_id ].copies( temp );
545                                         }
546                                         for (var i in acn_hash) acn_list.push( acn_hash[i] );
547                                         var robj = obj.network.simple_request(
548                                             'FM_ACN_TREE_UPDATE', 
549                                             [ ses(), acn_list, true ],
550                                             null,
551                                             {
552                                                 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.override'),
553                                                 'overridable_events' : [
554                                                     1208 /* TITLE_LAST_COPY */,
555                                                     1227 /* COPY_DELETE_WARNING */,
556                                                 ]
557                                             }
558                                         );
559                                         if (robj == null) throw(robj);
560                                         if (typeof robj.ilsevent != 'undefined') {
561                                             if (
562                                                 (robj.ilsevent != 0)
563                                                 && (robj.ilsevent != 1227 /* COPY_DELETE_WARNING */)
564                                                 && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */)
565                                                 && (robj.ilsevent != 5000 /* PERM_DENIED */)
566                                             ) {
567                                                 throw(robj);
568                                             }
569                                         }
570                                         obj.refresh_list();
571                                     }
572
573                                     
574                                 } catch(E) {
575                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.error'),E);
576                                     obj.refresh_list();
577                                 }
578                             }
579                         ],
580                         'cmd_print_spine_labels' : [
581                             ['command'],
582                             function() {
583                                 try {
584                                     JSAN.use('util.functional');
585                                     
586                                     var list = util.functional.filter_list(
587                                         obj.sel_list,
588                                         function (o) {
589                                             return o.split(/_/)[0] == 'acp';
590                                         }
591                                     );
592
593                                     list = util.functional.map_list(
594                                         list,
595                                         function (o) {
596                                             return obj.map_acp[ o ];
597                                         }
598                                     );
599
600                                     xulG.new_tab(
601                                         xulG.url_prefix( urls.XUL_SPINE_LABEL ),
602                                         { 'tab_name' : document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.tab') },
603                                         {
604                                             'barcodes' : util.functional.map_list( list, function(o){return o.barcode();})
605                                         }
606                                     );
607                                 } catch(E) {
608                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.error'),E);
609                                 }
610                             }
611                         ],
612                         'cmd_add_volumes' : [
613                             ['command'],
614                             function() {
615                                 try {
616                                     JSAN.use('util.functional');
617                                     var list = util.functional.filter_list(
618                                         obj.sel_list,
619                                         function (o) {
620                                             return o.split(/_/)[0] == 'aou';
621                                         }
622                                     );
623                                     list = util.functional.map_list(
624                                         list,
625                                         function (o) {
626                                             return o.split(/_/)[1];
627                                         }
628                                     );        
629                                     var edit = 0;
630                                     try {
631                                         edit = obj.network.request(
632                                             api.PERM_MULTI_ORG_CHECK.app,
633                                             api.PERM_MULTI_ORG_CHECK.method,
634                                             [ 
635                                                 ses(), 
636                                                 obj.data.list.au[0].id(), 
637                                                 list,
638                                                 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
639                                             ]
640                                         ).length == 0 ? 1 : 0;
641                                     } catch(E) {
642                                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
643                                     }
644
645                                     if (edit==0) {
646                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.permission_error'));
647                                         return; // no read-only view for this interface
648                                     }
649
650                                     if (!obj.can_have_copies) {
651                                         alert(document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.can_have_copies.false', obj.source));
652                                         return;
653                                     }
654
655                                     var title = document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.title');
656
657                                     var url;
658                                     var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true';
659                                     if (unified_interface) {
660                                         var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true';
661                                         url = xulG.url_prefix( horizontal_interface ? urls.XUL_VOLUME_COPY_CREATOR_HORIZONTAL : urls.XUL_VOLUME_COPY_CREATOR );
662                                     } else {
663                                         url = xulG.url_prefix( urls.XUL_VOLUME_COPY_CREATOR_ORIGINAL );
664                                     }
665
666                                     var w = xulG.new_tab(
667                                         url,
668                                         { 'tab_name' : title },
669                                         { 'doc_id' : obj.docid, 'ou_ids' : list, 'onrefresh' : function() { obj.refresh_list(); } }
670                                     );
671
672                                 } catch(E) {
673                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.error'),E);
674                                 }
675                             }
676                         ],
677                         'cmd_edit_volumes' : [
678                             ['command'],
679                             function() {
680                                 try {
681                                     JSAN.use('util.functional');
682                                     var volumes = util.functional.map_list(
683                                         util.functional.filter_list(
684                                             obj.sel_list,
685                                             function (o) {
686                                                 return o.split(/_/)[0] == 'acn';
687                                             }
688                                         ),
689                                         function (o) {
690                                             return o.split(/_/)[1];
691                                         }
692                                     );
693                                     volumes = util.functional.map_list(
694                                         volumes,
695                                         function (o) {
696                                             var my_acn = obj.map_acn['acn_' + o];
697                                             return function(r){return r;}(my_acn);
698                                         }
699                                     );
700
701                                     JSAN.use('cat.util'); 
702                                     if ( cat.util.batch_edit_volumes( volumes ) ) {
703                                         obj.refresh_list();
704                                     }
705
706                                 } catch(E) {
707                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.exception'),E);
708                                 }
709                             }
710                         ],
711                         'cmd_delete_volumes' : [
712                             ['command'],
713                             function() {
714                                 try {
715                                     JSAN.use('util.functional');
716
717                                     var list = util.functional.filter_list(
718                                         obj.sel_list,
719                                         function (o) {
720                                             return o.split(/_/)[0] == 'acn';
721                                         }
722                                     );
723
724                                     list = util.functional.map_list(
725                                         list,
726                                         function (o) {
727                                             return JSON2js( js2JSON( obj.map_acn[ 'acn_' + o.split(/_/)[1] ] ) );
728                                         }
729                                     );
730
731                                     var del_prompt;
732                                     if (list.length == 1) {
733                                         del_prompt = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.prompt');
734                                     } else {
735                                         del_prompt = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_volume.prompt.plural', [list.length]);
736                                     }
737
738                                     var r = obj.error.yns_alert(
739                                             del_prompt,
740                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.title'),
741                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.delete'),
742                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.cancel'),
743                                             null,
744                                             document.getElementById('commonStrings').getString('common.confirm')
745                                     );
746
747                                     if (r == 0) { // delete vols
748                                         for (var i = 0; i < list.length; i++) {
749                                             list[i].isdeleted('1');
750                                         }
751                                         var params = {};
752                                         loop: while(true) {
753                                             var robj = obj.network.simple_request(
754                                                 'FM_ACN_TREE_UPDATE', 
755                                                 [ ses(), list, true, params ],
756                                                 null,
757                                                 {
758                                                     'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.override'),
759                                                     'overridable_events' : [
760                                                         1208 /* TITLE_LAST_COPY */,
761                                                         1227 /* COPY_DELETE_WARNING */
762                                                     ]
763                                                 }
764                                             );
765                                             if (robj == null) throw(robj);
766                                             if (typeof robj.ilsevent != 'undefined') {
767                                                 if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
768                                                     var r2 = obj.error.yns_alert(
769                                                         document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain'),
770                                                         document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.title'),
771                                                         document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain.confirm'),
772                                                         document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain.cancel'),
773                                                         null,
774                                                         document.getElementById('commonStrings').getString('common.confirm')
775                                                     );
776                                                     if (r2 == 0) { // delete vols and copies
777                                                         params.force_delete_copies = true;
778                                                         continue loop;
779                                                     }
780                                                 } else {
781                                                     if (typeof robj.ilsevent != 'undefined') {
782                                                         if (
783                                                             (robj.ilsevent != 0)
784                                                             && (robj.ilsevent != 1227 /* COPY_DELETE_WARNING */)
785                                                             && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */)
786                                                             && (robj.ilsevent != 5000 /* PERM_DENIED */)
787                                                         ) {
788                                                             throw(robj);
789                                                         }
790                                                     }
791                                                 }
792                                             }
793                                             break loop;
794                                         }
795                                         obj.refresh_list();
796                                     }
797                                 } catch(E) {
798                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.exception'),E);
799                                     obj.refresh_list();
800                                 }
801
802                             }
803                         ],
804                         'cmd_mark_library' : [
805                             ['command'],
806                             function() {
807                                 try {
808                                     var list = util.functional.filter_list(
809                                         obj.sel_list,
810                                         function (o) {
811                                             return o.split(/_/)[0] == 'aou';
812                                         }
813                                     );
814
815                                     list = util.functional.map_list(
816                                         list,
817                                         function (o) {
818                                             return o.split(/_/)[1];
819                                         }
820                                     );
821
822                                     if (list.length == 1) {
823                                         obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid };
824                                         obj.data.stash('marked_library');
825                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.alert'));
826                                     } else {
827                                         obj.error.yns_alert(
828                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.prompt'),
829                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.title'),
830                                                 document.getElementById('commonStrings').getString('common.ok'),
831                                                 null,
832                                                 null,
833                                                 document.getElementById('commonStrings').getString('common.confirm')
834                                                 );
835                                     }
836                                 } catch(E) {
837                                     obj.error.standard_unexpected_error_alert('copy browser -> mark library',E);
838                                 }
839                             }
840                         ],
841
842                         'cmd_mark_volume' : [
843                             ['command'],
844                             function() {
845                                 try {
846                                     var list = util.functional.filter_list(
847                                         obj.sel_list,
848                                         function (o) {
849                                             return o.split(/_/)[0] == 'acn';
850                                         }
851                                     );
852
853                                     list = util.functional.map_list(
854                                         list,
855                                         function (o) {
856                                             return o.split(/_/)[1];
857                                         }
858                                     );
859
860                                     if (list.length == 1) {
861                                         obj.data.marked_volume = list[0];
862                                         obj.data.stash('marked_volume');
863                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.alert'));
864                                     } else {
865                                         obj.error.yns_alert(
866                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.prompt'),
867                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.title'),
868                                                 document.getElementById('commonStrings').getString('common.ok'),
869                                                 null,
870                                                 null,
871                                                 document.getElementById('commonStrings').getString('common.confirm')
872                                                 );
873                                     }
874                                 } catch(E) {
875                                     obj.error.standard_unexpected_error_alert('copy browser -> mark volume',E);
876                                 }
877                             }
878                         ],
879                         'cmd_refresh_list' : [
880                             ['command'],
881                             function() {
882                                 obj.refresh_list();
883                             }
884                         ],
885                         'cmd_transfer_volume' : [
886                             ['command'],
887                             function() {
888                                 try {
889                                     obj.data.stash_retrieve();
890                                     if (!obj.data.marked_library) {
891                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_volume.alert'));
892                                         return;
893                                     }
894                                     
895                                     JSAN.use('util.functional');
896
897                                     var list = util.functional.filter_list(
898                                         obj.sel_list,
899                                         function (o) {
900                                             return o.split(/_/)[0] == 'acn';
901                                         }
902                                     );
903
904                                     list = util.functional.map_list(
905                                         list,
906                                         function (o) {
907                                             return o.split(/_/)[1];
908                                         }
909                                     );
910
911                                     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
912
913                                     var acn_list = util.functional.map_list(
914                                         list,
915                                         function (o) {
916                                             return obj.map_acn[ 'acn_' + o ].label();
917                                         }
918                                     ).join(document.getElementById('commonStrings').getString('common.grouping_string'));
919
920                                     var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
921                                     xml += '<description>';
922                                     xml += document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.transfer.prompt', [acn_list, obj.data.hash.aou[ obj.data.marked_library.lib ].shortname()]);
923                                     xml += '</description>';
924                                     xml += '<hbox><button label="' + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.submit.label') + '" name="fancy_submit"/>';
925                                     xml += '<button label="' 
926                                         + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.label') 
927                                         + '" accesskey="' 
928                                         + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.accesskey') 
929                                         + '" name="fancy_cancel"/></hbox>';
930                                     xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
931                                     xml += '</vbox>';
932                                     JSAN.use('OpenILS.data');
933                                     var data = new OpenILS.data(); data.init({'via':'stash'});
934                                     //data.temp_transfer = xml; data.stash('temp_transfer');
935                                     JSAN.use('util.window'); var win = new util.window();
936                                     var fancy_prompt_data = win.open(
937                                         urls.XUL_FANCY_PROMPT,
938                                         //+ '?xml_in_stash=temp_transfer'
939                                         //+ '&title=' + window.escape('Volume Transfer'),
940                                         'fancy_prompt', 'chrome,resizable,modal,width=500,height=300',
941                                         {
942                                             'xml' : xml,
943                                             'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.title')
944                                         }
945                                     );
946
947                                     if (fancy_prompt_data.fancy_status == 'incomplete') {
948                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.incomplete'));
949                                         return;
950                                     }
951
952                                     var robj = obj.network.simple_request(
953                                         'FM_ACN_TRANSFER', 
954                                         [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'volumes' : list } ],
955                                         null,
956                                         {
957                                             'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.override.failure'),
958                                             'overridable_events' : [
959                                                 1208 /* TITLE_LAST_COPY */,
960                                                 1219 /* COPY_REMOTE_CIRC_LIB */,
961                                             ],
962                                         }
963                                     );
964
965                                     if (typeof robj.ilsevent != 'undefined') {
966                                         if (robj.ilsevent == 1221 /* ORG_CANNOT_HAVE_VOLS */) {
967                                             alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.ineligible_destination'));
968                                         } else {
969                                             throw(robj);
970                                         }
971                                     } else {
972                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.success'));
973                                     }
974
975                                 } catch(E) {
976                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.unexpected_error'),E);
977                                 }
978                                 obj.refresh_list();
979                             }
980                         ],
981
982                         'cmd_transfer_items' : [
983                             ['command'],
984                             function() {
985                                 try {
986                                     obj.data.stash_retrieve();
987                                     if (!obj.data.marked_volume) {
988                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.missing_volume'));
989                                         return;
990                                     }
991                                     
992                                     JSAN.use('util.functional');
993
994                                     var list = util.functional.filter_list(
995                                         obj.sel_list,
996                                         function (o) {
997                                             return o.split(/_/)[0] == 'acp';
998                                         }
999                                     );
1000
1001                                     list = util.functional.map_list(
1002                                         list,
1003                                         function (o) {
1004                                             return o.split(/_/)[1];
1005                                         }
1006                                     );
1007
1008                                     var volume = obj.network.simple_request('FM_ACN_RETRIEVE.authoritative',[ obj.data.marked_volume ]);
1009
1010                                     JSAN.use('cat.util'); cat.util.transfer_copies( { 
1011                                         'copy_ids' : list, 
1012                                         'docid' : volume.record(),
1013                                         'volume_label' : volume.label(),
1014                                         'owning_lib' : volume.owning_lib(),
1015                                     } );
1016
1017                                 } catch(E) {
1018                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.unexpected_error'),E);
1019                                 }
1020                                 obj.refresh_list();
1021                             }
1022                         ],
1023
1024                         'cmd_link_as_multi_bib' : [
1025                             ['command'],
1026                             function() {
1027                                 try {
1028                                     obj.data.stash_retrieve();
1029                                     if (!obj.data.marked_multi_home_record) {
1030                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.link_as_multi_bib.missing_bib'));
1031                                         return;
1032                                     }
1033
1034                                     JSAN.use('util.functional');
1035
1036                                     var list = util.functional.filter_list(
1037                                         obj.sel_list,
1038                                         function (o) {
1039                                             return o.split(/_/)[0] == 'acp';
1040                                         }
1041                                     );
1042
1043                                     list = util.functional.map_list(
1044                                         list,
1045                                         function (o) {
1046                                             return obj.map_acp[ o ].barcode();
1047                                         }
1048                                     );
1049
1050                                     xulG.new_tab(
1051                                         window.xulG.url_prefix(urls.MANAGE_MULTI_HOME_ITEMS),
1052                                         {},
1053                                         { 'docid' : obj.data.marked_multi_home_record, 'barcodes' : list }
1054                                     );
1055
1056                                 } catch(E) {
1057                                     alert('Error in copy_browser.js, cmd_link_as_multi_bib: ' + E);
1058                                 }
1059                                 obj.refresh_list();
1060                             }
1061                         ],
1062
1063                         'cmd_print_tree' : [
1064                             ['command'],
1065                             function() {
1066                                 try {
1067                                     var p = {
1068                                         'template' : 'holdings_maintenance',
1069                                         'mvr_id' : obj.docid,
1070                                         'print_data' : {}
1071                                     };
1072                                     bib_brief_overlay(p);
1073                                     p.data = p.print_data;
1074                                     obj.list.print(p);
1075                                 } catch(E) {
1076                                     alert('Error in copy_browser.js, cmd_print_tree: ' + E);
1077                                 }
1078                             }
1079                         ]
1080                     }
1081                 }
1082             );
1083
1084         } catch(E) {
1085             this.error.standard_unexpected_error_alert('cat.copy_browser.controller_init(): ',E);
1086         }
1087     },
1088
1089     'depth_menu_init' : function(params) {
1090         var obj = this;
1091         try {
1092             var list = [];
1093             var max_depth = 0;
1094             for (var i = 0; i < obj.data.list.aout.length; i++) {
1095                 var type = obj.data.list.aout[i];
1096                 var depth = type.depth();
1097                 if ( depth > max_depth) { max_depth = depth; }
1098                 if (typeof list[depth] == 'undefined') {
1099                     list[depth] = [
1100                         type.opac_label(),
1101                         type.depth(),
1102                         false,
1103                         ( type.depth() * 2)
1104                     ];
1105                 } else {
1106                     list[depth][0] += ' / ' + type.opac_label();
1107                 }
1108             }
1109             ml = util.widgets.make_menulist( list, max_depth );
1110             ml.setAttribute('id','depth_menu'); document.getElementById('x_depth_menu').appendChild(ml);
1111             ml.addEventListener(
1112                 'command',
1113                 function(ev) {
1114                     obj.default_depth = ev.target.value;
1115                     if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus(); 
1116                     JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
1117                     util.widgets.save_attributes(file, { 
1118                         'lib_menu' : [ 'value' ],
1119                         'depth_menu' : [ 'value' ],
1120                         'show_acns' : [ 'checked' ],
1121                         'show_acps' : [ 'checked' ],
1122                         'hide_aous' : [ 'checked' ]
1123                     });
1124                 },
1125                 false
1126             );
1127
1128             file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
1129             util.widgets.load_attributes(file);
1130             ml.value = ml.getAttribute('value');
1131             if (! ml.value) {
1132                 ml.value = max_depth;
1133                 ml.setAttribute('value',ml.value);
1134             }
1135
1136             return ml.value;
1137         } catch(E) {
1138             alert('Error in copy_browser.js, depth_menu_init(): ' + E);
1139         }
1140     },
1141
1142     'library_menu_init' : function(params) {
1143         var obj = this;
1144         try {
1145
1146             obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
1147             if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
1148             JSAN.use('util.functional'); 
1149             obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
1150
1151             var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1152
1153             JSAN.use('util.file'); JSAN.use('util.widgets');
1154
1155             var file; var list_data; var ml; 
1156
1157             file = new util.file('offline_ou_list'); 
1158             if (file._file.exists()) {
1159                 list_data = file.get_object(); file.close();
1160                 for (var i = 0; i < list_data[0].length; i++) { // make sure all entries are enabled
1161                     list_data[0][i][2] = false;
1162                 }
1163                 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
1164                 ml.setAttribute('id','lib_menu'); document.getElementById('x_lib_menu').appendChild(ml);
1165                 for (var i = 0; i < obj.org_ids.length; i++) {
1166                     ml.getElementsByAttribute('value',obj.org_ids[i])[0].setAttribute('class','has_copies');
1167                 }
1168                 ml.firstChild.addEventListener(
1169                     'popupshowing',
1170                     function(ev) {
1171                         document.getElementById('legend').setAttribute('hidden','false');
1172                     },
1173                     false
1174                 );
1175                 ml.firstChild.addEventListener(
1176                     'popuphidden',
1177                     function(ev) {
1178                         document.getElementById('legend').setAttribute('hidden','true');
1179                     },
1180                     false
1181                 );
1182                 ml.addEventListener(
1183                     'command',
1184                     function(ev) {
1185                         obj.default_lib = obj.data.hash.aou[ ev.target.value ];
1186                         if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus(); 
1187                         JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
1188                         util.widgets.save_attributes(file, { 
1189                             'lib_menu' : [ 'value' ],
1190                             'depth_menu' : [ 'value' ],
1191                             'show_acns' : [ 'checked' ],
1192                             'show_acps' : [ 'checked' ],
1193                             'hide_aous' : [ 'checked' ]
1194                         });
1195                         obj.refresh_list();
1196                     },
1197                     false
1198                 );
1199             } else {
1200                 throw(document.getElementById('catStrings').getString('staff.cat.copy_browser.missing_library') + '\n');
1201             }
1202
1203             file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
1204             util.widgets.load_attributes(file);
1205             ml.value = ml.getAttribute('value');
1206             if (! ml.value) {
1207                 ml.value = org.id();
1208                 ml.setAttribute('value',ml.value);
1209             }
1210
1211             return ml.value;
1212
1213         } catch(E) {
1214             this.error.standard_unexpected_error_alert('cat.copy_browser.library_menu_init(): ',E);
1215         }
1216     },
1217
1218     'show_consortial_count' : function() {
1219         var obj = this;
1220         try {
1221             obj.network.simple_request('FM_ACP_COUNT.authoritative',[ obj.data.tree.aou.id(), obj.docid ],function(req){ 
1222                 try {
1223                     var robj = req.getResultObject();
1224                     var x = document.getElementById('consortial_total');
1225                     if (x) x.setAttribute('value',robj[0].count);
1226                     x = document.getElementById('consortial_available');
1227                     if (x) x.setAttribute('value',robj[0].available);
1228                 } catch(E) {
1229                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.consortial_copy_count.error'),E);
1230                 }
1231             });
1232         } catch(E) {
1233             this.error.standard_unexpected_error_alert('cat.copy_browser.show_consortial_count: ',E);
1234         }
1235     },
1236
1237     'show_my_libs' : function(org) {
1238         var obj = this;
1239         try {
1240             if (!org) {
1241                 org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1242             } else {
1243                 if (typeof org != 'object') org = obj.data.hash.aou[ org ];
1244             }
1245             obj.show_libs( org, false );
1246 /*        
1247             var p_org = obj.data.hash.aou[ org.parent_ou() ];
1248             if (p_org) {
1249                 obj.funcs.push( function() { 
1250                     document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1251                     document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1252                     document.getElementById('lib_menu').setAttribute('disabled','true'); 
1253                 } );
1254                 for (var i = 0; i < p_org.children().length; i++) {
1255                     obj.funcs.push(
1256                         function(o) {
1257                             return function() {
1258                                 obj.show_libs( o, false );
1259                             }
1260                         }( p_org.children()[i] )
1261                     );
1262                 }
1263                 obj.funcs.push( function() { 
1264                     document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1265                     document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1266                     document.getElementById('lib_menu').setAttribute('disabled','false'); 
1267                 } );
1268             }
1269 */
1270         } catch(E) {
1271             alert(E);
1272         }
1273     },
1274
1275     'show_all_libs' : function() {
1276         var obj = this;
1277         try {
1278             obj.show_my_libs();
1279
1280             obj.show_libs( obj.data.tree.aou );
1281
1282             obj.funcs.push( function() { 
1283                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1284                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1285                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1286             } );
1287
1288             for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
1289                 var child = obj.data.tree.aou.children()[i];
1290                 if (obj.data.hash.aout[child.ou_type()].depth() <= obj.default_depth
1291                 && orgIsMine(obj.default_lib,child,obj.default_depth)) {
1292                     obj.funcs.push(
1293                         function(o) {
1294                             return function() {
1295                                 obj.show_libs( o );
1296                             }
1297                         }( child )
1298                     );
1299                 }
1300             }
1301             obj.funcs.push( function() { 
1302                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1303                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1304                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1305             } );
1306
1307         } catch(E) {
1308             alert(E);
1309         }
1310     },
1311
1312     'show_libs_with_copies' : function() {
1313         var obj = this;
1314         try {
1315             JSAN.use('util.functional');
1316
1317             var orgs = util.functional.map_list(
1318                 obj.org_ids,
1319                 function(id) { return obj.data.hash.aou[id]; }
1320             ).sort(
1321                 function( a, b ) {
1322                     if (a.shortname() < b.shortname()) return -1;
1323                     if (a.shortname() > b.shortname()) return 1;
1324                     return 0;
1325                 }
1326             );
1327             obj.funcs.push( function() { 
1328                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1329                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1330                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1331             } );
1332
1333             for (var i = 0; i < orgs.length; i++) {
1334                 obj.funcs.push(
1335                     function(o) {
1336                         return function() {
1337                             obj.show_libs(o,false);
1338                         }
1339                     }( orgs[i] )
1340                 );
1341             }
1342             obj.funcs.push( function() { 
1343                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1344                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1345                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1346             } );
1347
1348         } catch(E) {
1349             alert(E);
1350         }
1351     },
1352
1353     'show_libs' : function(start_aou,show_open) {
1354         var obj = this;
1355         try {
1356             if (!start_aou) throw('show_libs: Need a start_aou');
1357             JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1358             JSAN.use('util.functional'); 
1359
1360             var parents = [];
1361             var temp_aou = start_aou;
1362             while ( temp_aou.parent_ou() ) {
1363                 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
1364                 parents.push( temp_aou );
1365             }
1366             parents.reverse();
1367
1368             for (var i = 0; i < parents.length; i++) {
1369                 obj.funcs.push(
1370                     function(o,p) {
1371                         return function() { 
1372                             obj.append_org(o,p,{'container':'true','open':'true'}); 
1373                         };
1374                     }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
1375                 );
1376             }
1377
1378             obj.funcs.push(
1379                 function(o,p) {
1380                     return function() { obj.append_org(o,p); };
1381                 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
1382             );
1383
1384             obj.funcs.push(
1385                 function() {
1386                     if (start_aou.children()) {
1387                         var x = obj.map_tree[ 'aou_' + start_aou.id() ];
1388                         x.setAttribute('container','true');
1389                         if (show_open) x.setAttribute('open','true');
1390                         for (var i = 0; i < start_aou.children().length; i++) {
1391                             var child = start_aou.children()[i];
1392                             if (obj.data.hash.aout[child.ou_type()].depth() <= obj.default_depth
1393                             && orgIsMine(obj.default_lib,child,obj.default_depth)) {
1394                                 obj.funcs.push(
1395                                     function(o,p) {
1396                                         return function() { obj.append_org(o,p); };
1397                                     }( child, start_aou )
1398                                 );
1399                             }
1400                         }
1401                     }
1402                 }
1403             );
1404
1405         } catch(E) {
1406             alert(E);
1407         }
1408     },
1409
1410     'on_select' : function(list,twisty) {
1411         var obj = this;
1412         for (var i = 0; i < list.length; i++) {
1413             var node = obj.map_tree[ list[i] ];
1414             //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
1415             var row_type = list[i].split('_')[0];
1416             var id = list[i].split('_')[1];
1417             switch(row_type) {
1418                 case 'aou' : obj.on_select_org(id,twisty); break;
1419                 case 'acn' : obj.on_select_acn(id,twisty); break;
1420                 default: break;
1421             }
1422         }
1423     },
1424
1425     'on_select_acn' : function(acn_id,twisty) {
1426         var obj = this;
1427         try {
1428             var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
1429             obj.funcs.push( function() { 
1430                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1431                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1432                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1433             } );
1434             if (acn_tree.copies()) {
1435                 for (var i = 0; i < acn_tree.copies().length; i++) {
1436                     obj.funcs.push(
1437                         function(c,a) {
1438                             return function() {
1439                                 obj.append_acp(c,a);
1440                             }
1441                         }( acn_tree.copies()[i], acn_tree )
1442                     )
1443                 }
1444             }
1445             obj.funcs.push( function() { 
1446                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1447                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1448                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1449             } );
1450         } catch(E) {
1451             alert(E);
1452         }
1453     },
1454
1455     'on_select_org' : function(org_id,twisty) {
1456         var obj = this;
1457         try {
1458             var org = obj.data.hash.aou[ org_id ];
1459             obj.funcs.push( function() { 
1460                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1461                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1462                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1463             } );
1464             if (org.children()) {
1465                 for (var i = 0; i < org.children().length; i++) {
1466                     var child = org.children()[i];
1467                     if (obj.data.hash.aout[child.ou_type()].depth() <= obj.default_depth
1468                     && orgIsMine(obj.default_lib,child,obj.default_depth)) {
1469                         obj.funcs.push(
1470                             function(o,p) {
1471                                 return function() {
1472                                     obj.append_org(o,p)
1473                                 }
1474                             }(child,org)
1475                         );
1476                     }
1477                 }
1478             } 
1479             if (obj.map_acn[ 'aou_' + org_id ]) {
1480                 for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
1481                     obj.funcs.push(
1482                         function(o,a) {
1483                             return function() {
1484                                 obj.append_acn(o,a);
1485                             }
1486                         }( org, obj.map_acn[ 'aou_' + org_id ][i] )
1487                     );
1488                 }
1489             }
1490             obj.funcs.push( function() { 
1491                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1492                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1493                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1494             } );
1495         } catch(E) {
1496             alert('Error in copy_browser.js, on_select_org(): ' + E);
1497         }
1498     },
1499
1500     'append_org' : function (org,parent_org,params) {
1501         var obj = this;
1502         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1503         obj.error.consoleService.logStringMessage('append_org: org = ' + org.shortname() + ' parent_org = ' + (parent_org ? parent_org.shortname() : '') + ' params = ' + js2JSON(params) + '\n');
1504         try {
1505             if (obj.map_tree[ 'aou_' + org.id() ]) {
1506                 var x = obj.map_tree[ 'aou_' + org.id() ];
1507                 if (params) {
1508                     for (var i in params) {
1509                         x.setAttribute(i,params[i]);
1510                     }
1511                 }
1512                 return x;
1513             }
1514
1515             var data = {
1516                 'row' : {
1517                     'my' : {
1518                         'aou' : org,
1519                     }
1520                 },
1521                 'skip_all_columns_except' : [0,1,2],
1522                 'retrieve_id' : 'aou_' + org.id(),
1523                 'to_bottom' : true,
1524                 'no_auto_select' : true,
1525             };
1526         
1527             var acn_tree_list;
1528             if ( obj.org_ids.indexOf( Number( org.id() ) ) == -1 ) {
1529                 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) {
1530                     data.row.my.volume_count = '0';
1531                     data.row.my.copy_count = '<0>';
1532                 } else {
1533                     data.row.my.volume_count = '';
1534                     data.row.my.copy_count = '';
1535                 }
1536             } else {
1537                 var v_count = 0; var c_count = 0;
1538                 acn_tree_list = obj.network.simple_request(
1539                     'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS.authoritative',
1540                     [ ses(), obj.docid, [ org.id() ] ]
1541                 );
1542                 for (var i = 0; i < acn_tree_list.length; i++) {
1543                     v_count++;
1544                     obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
1545                     var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
1546                     for (var j = 0; j < copies.length; j++) {
1547                         obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
1548                     }
1549                 }
1550                 data.row.my.volume_count = String(v_count);
1551                 data.row.my.copy_count = '<' + c_count + '>';
1552             }
1553             if (document.getElementById('hide_aous').checked) {
1554                 if (org.children().length == 0
1555                         && data.row.my.volume_count == '0') {
1556                     if (!params) {
1557                         params = { 'hidden' : true };
1558                     } else {
1559                         params['hidden'] = true;
1560                     }
1561                     dump('hiding org.id() = ' + org.id() + '\n');
1562                 }
1563             }
1564             if (parent_org) {
1565                 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1566             }
1567             var nparams = obj.list.append(data);
1568             var node = nparams.my_node;
1569             if (params) {
1570                 for (var i in params) {
1571                     node.setAttribute(i,params[i]);
1572                 }
1573             }
1574             obj.map_tree[ 'aou_' + org.id() ] = node;
1575
1576             if (org.children()) {
1577                 node.setAttribute('container','true');
1578             }
1579
1580             if (parent_org) {
1581                 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1582                     data.node.setAttribute('open','true');
1583                 }
1584             } else {
1585                 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1586             }
1587
1588             if (acn_tree_list) {
1589                 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
1590                 node.setAttribute('container','true');
1591             }
1592
1593             if (document.getElementById('show_acns').checked) {
1594                 node.setAttribute('open','true');
1595                 obj.funcs.push( function() { obj.on_select_org( org.id() ); } );
1596             }
1597
1598         } catch(E) {
1599             dump(E+'\n');
1600             alert(E);
1601         }
1602     },
1603
1604     'append_acn' : function( org, acn_tree, params ) {
1605         var obj = this;
1606         try {
1607             if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
1608                 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
1609                 if (params) {
1610                     for (var i in params) {
1611                         x.setAttribute(i,params[i]);
1612                     }
1613                 }
1614                 return x;
1615             }
1616
1617             var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1618             var data = {
1619                 'row' : {
1620                     'my' : {
1621                         'aou' : org,
1622                         'acn' : acn_tree,
1623                         'volume_count' : '',
1624                         'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
1625                     }
1626                 },
1627                 'skip_all_columns_except' : [0,1,2],
1628                 'retrieve_id' : 'acn_' + acn_tree.id(),
1629                 'node' : parent_node,
1630                 'to_bottom' : true,
1631                 'no_auto_select' : true,
1632             };
1633             var nparams = obj.list.append(data);
1634             var node = nparams.my_node;
1635             obj.map_tree[ 'acn_' + acn_tree.id() ] =  node;
1636             if (params) {
1637                 for (var i in params) {
1638                     node.setAttribute(i,params[i]);
1639                 }
1640             }
1641             if (acn_tree.copies()) {
1642                 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
1643                 node.setAttribute('container','true');
1644             }
1645             if (document.getElementById('show_acps').checked) {
1646                 node.setAttribute('open','true');
1647                 obj.funcs.push( function() { obj.on_select_acn( acn_tree.id() ); } );
1648             }
1649
1650         } catch(E) {
1651             dump(E+'\n');
1652             alert(E);
1653         }
1654     },
1655
1656     'append_acp' : function( acp_item, acn_tree, params ) {
1657         var obj = this;
1658         try {
1659             if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
1660                 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
1661                 if (params) {
1662                     for (var i in params) {
1663                         x.setAttribute(i,params[i]);
1664                     }
1665                 }
1666                 return x;
1667             }
1668
1669             var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
1670             var data = {
1671                 'row' : {
1672                     'my' : {
1673                         'doc_id' : obj.docid,
1674                         'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
1675                         'acn' : acn_tree,
1676                         'acp' : acp_item,
1677                         'circ' :
1678                             acp_item.circulations() 
1679                             ? (
1680                                 acp_item.circulations().length > 0
1681                                 ? acp_item.circulations()[0]
1682                                 : null
1683                             ) 
1684                             : null,
1685                         'volume_count' : '',
1686                         'copy_count' : '',
1687                     }
1688                 },
1689                 'retrieve_id' : 'acp_' + acp_item.id(),
1690                 'node' : parent_node,
1691                 'to_bottom' : true,
1692                 'no_auto_select' : true,
1693             };
1694             var nparams = obj.list.append(data);
1695             var node = nparams.my_node;
1696             obj.map_tree[ 'acp_' + acp_item.id() ] =  node;
1697             if (params) {
1698                 for (var i in params) {
1699                     node.setAttribute(i,params[i]);
1700                 }
1701             }
1702
1703         } catch(E) {
1704             dump(E+'\n');
1705             alert(E);
1706         }
1707     },
1708
1709     'list_init' : function( params ) {
1710
1711         try {
1712             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1713             var obj = this;
1714             
1715             JSAN.use('circ.util');
1716             var columns = [
1717                 {
1718                     'id' : 'tree_location',
1719                     'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.tree_location'),
1720                     'flex' : 1, 'primary' : true, 'hidden' : false, 
1721                     'render' : function(my) { return my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"; },
1722                 },
1723                 {
1724                     'id' : 'volume_count',
1725                     'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.volume_count'),
1726                     'flex' : 0, 'primary' : false, 'hidden' : false, 
1727                     'render' : function(my) { return my.volume_count; },
1728                 },
1729                 {
1730                     'id' : 'copy_count',
1731                     'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.copy_count'),
1732                     'flex' : 0,
1733                     'primary' : false, 'hidden' : false, 
1734                     'render' : function(my) { return my.copy_count; },
1735                 },
1736             ].concat(
1737                 circ.util.columns( 
1738                     { 
1739                         'location' : { 'hidden' : false },
1740                         'circ_lib' : { 'hidden' : false },
1741                         'owning_lib' : { 'hidden' : false },
1742                         'call_number' : { 'hidden' : false },
1743                         'parts' : { 'hidden' : false },
1744                         'due_date' : { 'hidden' : false },
1745                         'acp_status' : { 'hidden' : false },
1746                     },
1747                     {
1748                         'just_these' : [
1749                             'due_date',
1750                             'owning_lib',
1751                             'circ_lib',
1752                             'label_class',
1753                             'prefix',
1754                             'call_number',
1755                             'suffix',
1756                             'copy_number',
1757                             'parts',
1758                             'location',
1759                             'barcode',
1760                             'loan_duration',
1761                             'fine_level',
1762                             'circulate',
1763                             'holdable',
1764                             'opac_visible',
1765                             'ref',
1766                             'deposit',
1767                             'deposit_amount',
1768                             'price',
1769                             'circ_as_type',
1770                             'circ_modifier',
1771                             'acp_status',
1772                             'alert_message',
1773                             'acp_mint_condition',
1774                             'acp_id'
1775                         ]
1776                     }
1777                 )
1778             );
1779             JSAN.use('util.list'); obj.list = new util.list('copy_tree');
1780             obj.list.init(
1781                 {
1782                     'no_auto_select' : true,
1783                     'columns' : columns,
1784                     'retrieve_row' : function(params) {
1785
1786                         var row = params.row;
1787
1788                     /*    
1789                         if (!row.my.mvr) obj.funcs.push(
1790                             function() {
1791
1792                                 row.my.mvr = obj.network.request(
1793                                     api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
1794                                     api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
1795                                     [ row.my.circ.target_copy() ]
1796                                 );
1797
1798                             }
1799                         );
1800                         if (!row.my.acp) {
1801                             obj.funcs.push(    
1802                                 function() {
1803
1804                                     row.my.acp = obj.network.request(
1805                                         api.FM_ACP_RETRIEVE.app,
1806                                         api.FM_ACP_RETRIEVE.method,
1807                                         [ row.my.circ.target_copy() ]
1808                                     );
1809
1810                                     params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1811
1812                                 }
1813                             );
1814                         } else {
1815                             params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1816                         }
1817                     */
1818                         obj.funcs.push(
1819                             function() {
1820
1821                                 if (typeof params.on_retrieve == 'function') {
1822                                     params.on_retrieve(row);
1823                                 }
1824
1825                             }
1826                         );
1827
1828                         return row;
1829                     },
1830                     'on_click' : function(ev) {
1831                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1832                         var row = {}; var col = {}; var nobj = {};
1833                         obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj); 
1834                         if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
1835                         var node = obj.list.node.contentView.getItemAtIndex(row.value);
1836                         var list = [ node.getAttribute('retrieve_id') ];
1837                         if (typeof obj.on_select == 'function') {
1838                             obj.on_select(list,true);
1839                         }
1840                         if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1841                             window.xulG.on_select(list);
1842                         }
1843                     },
1844                     'on_select' : function(ev) {
1845                         JSAN.use('util.functional');
1846                         var sel = obj.list.retrieve_selection();
1847                         obj.controller.view.sel_clip.disabled = sel.length < 1;
1848                         obj.sel_list = util.functional.map_list(
1849                             sel,
1850                             function(o) { return o.getAttribute('retrieve_id'); }
1851                         );
1852                         obj.toggle_actions();
1853                         if (typeof obj.on_select == 'function') {
1854                             obj.on_select(obj.sel_list);
1855                         }
1856                         if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1857                             window.xulG.on_select(obj.sel_list);
1858                         }
1859                     },
1860                 }
1861             );
1862
1863             $('list_actions').appendChild( obj.list.render_list_actions() );
1864             obj.list.set_list_actions();
1865
1866         } catch(E) {
1867             this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
1868             alert(E);
1869         }
1870     },
1871
1872     // Sets can_have_copies and source member variables.
1873     'source_init' : function() {
1874         var obj = this;
1875         try {
1876             JSAN.use('cat.util');
1877             var cbsObj = cat.util.get_cbs_for_bre_id(obj.docid);
1878             if(cbsObj) {
1879                 obj.can_have_copies = (cbsObj.can_have_copies() == get_db_true());
1880                 obj.source = cbsObj.source();
1881             } else {
1882                 obj.can_have_copies = true;
1883             }
1884         } catch(E) {
1885             obj.error.sdump('D_ERROR','can have copies check: ' + E);
1886             alert(E);
1887         }
1888     },
1889
1890     'toggle_actions' : function() {
1891         var obj = this;
1892         try {
1893             var found_aou = false; var found_acn = false; var found_acp = false;
1894             var found_aou_with_can_have_vols = false;
1895             var sel_copy_libs = {};
1896             for (var i = 0; i < obj.sel_list.length; i++) {
1897                 var type = obj.sel_list[i].split(/_/)[0];
1898                 switch(type) {
1899                     case 'aou' : 
1900                         found_aou = true; 
1901                         var org = obj.data.hash.aou[ obj.sel_list[i].split(/_/)[1] ];
1902                         if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) found_aou_with_can_have_vols = true;
1903                     break;
1904                     case 'acn' : found_acn = true; break;
1905                     case 'acp' :
1906                         found_acp = true;
1907                         sel_copy_libs[
1908                             obj.map_acn[
1909                                 "acn_" +
1910                                 obj.map_acp[obj.sel_list[i]].call_number()
1911                             ].owning_lib()
1912                         ] = true;
1913                         break;
1914                 }
1915             }
1916             obj.controller.view.cmd_add_items.setAttribute('disabled','true');
1917             obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','true');
1918             obj.controller.view.cmd_edit_items.setAttribute('disabled','true');
1919             obj.controller.view.cmd_replace_barcode.setAttribute('disabled','true');
1920             obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
1921             obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','true');
1922             obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
1923             obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1924             obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
1925             obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
1926             obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
1927             obj.controller.view.cmd_transfer_volume.setAttribute('disabled','true');
1928             obj.controller.view.cmd_transfer_items.setAttribute('disabled','true');
1929             obj.controller.view.sel_copy_details.setAttribute('disabled','true');
1930             obj.controller.view.cmd_create_brt.setAttribute('disabled','true');
1931             obj.controller.view.cmd_book_item_now.setAttribute('disabled','true');
1932             obj.controller.view.sel_patron.setAttribute('disabled','true');
1933             obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
1934             obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
1935             if (found_aou && found_aou_with_can_have_vols) {
1936                 obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
1937                 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1938             }
1939             if (found_acn) {
1940                 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
1941                 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
1942                 obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
1943                 obj.controller.view.cmd_add_items.setAttribute('disabled','false');
1944                 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','false');
1945             }
1946             if (found_acp) {
1947                 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
1948                 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
1949                 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','false');
1950                 obj.controller.view.cmd_edit_items.setAttribute('disabled','false');
1951                 obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
1952                 obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
1953                 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','false');
1954                 obj.controller.view.cmd_transfer_items.setAttribute('disabled','false');
1955                 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
1956                 obj.controller.view.cmd_create_brt.setAttribute('disabled','false');
1957                 obj.controller.view.sel_patron.setAttribute('disabled','false');
1958
1959                 var L = 0; for (var k in sel_copy_libs) L++;
1960                 if (L < 2) {
1961                     obj.controller.view.cmd_book_item_now.setAttribute('disabled','false');
1962                 }
1963             }
1964         } catch(E) {
1965             obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.actions.error'),E);
1966         }
1967     },
1968
1969     'refresh_list' : function() { 
1970         try {
1971             var obj = this;
1972             obj.list.clear();
1973             obj.map_tree = {};
1974             obj.map_acn = {};
1975             obj.map_acp = {};
1976             obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
1977             if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
1978             JSAN.use('util.functional'); 
1979             obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
1980             obj.show_my_libs( obj.default_lib.id() );
1981             // FIXME - we get a null from the copy_count call if we call it too quickly here
1982             setTimeout( function() { obj.show_consortial_count(); }, 2000 );
1983         } catch(E) {
1984             this.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.refresh_list.error'),E);
1985         }
1986     },
1987 }
1988
1989 dump('exiting cat.copy_browser.js\n');