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