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