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