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