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