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