]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_browser.js
Tweaked Holdings Maintenance so that it only shows the selected library, its ancestor...
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / cat / copy_browser.js
1 dump('entering cat.copy_browser.js\n');
2 // vim:noet:sw=4:ts=4:
3
4 if (typeof cat == 'undefined') cat = {};
5 cat.copy_browser = function (params) {
6     try {
7         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
8         JSAN.use('util.error'); this.error = new util.error();
9     } catch(E) {
10         dump('cat.copy_browser: ' + E + '\n');
11     }
12 }
13
14 cat.copy_browser.prototype = {
15
16     'map_tree' : {},
17     'map_acn' : {},
18     'map_acp' : {},
19     'sel_list' : [],
20     'funcs' : [],
21
22     'init' : function( params ) {
23
24         try {
25             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
26             var obj = this;
27
28             obj.docid = params.docid;
29
30             JSAN.use('util.network'); obj.network = new util.network();
31             JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
32
33             obj.controller_init(params);
34
35             obj.list_init(params);
36
37             obj.controller.render();
38
39             obj.default_depth = obj.depth_menu_init();
40             obj.default_lib = obj.data.hash.aou[ obj.library_menu_init() ];
41
42             document.getElementById('show_acns').addEventListener(
43                 'command',
44                 function(ev) {
45                     JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
46                     util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
47                 },
48                 false
49             );
50
51             document.getElementById('show_acps').addEventListener(
52                 'command',
53                 function(ev) {
54                     JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
55                     util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
56                 },
57                 false
58             );
59
60             obj.show_my_libs( obj.default_lib.id() );
61
62             JSAN.use('util.exec'); var exec = new util.exec(20); exec.timer(obj.funcs,100);
63
64             obj.show_consortial_count();
65
66         } catch(E) {
67             this.error.standard_unexpected_error_alert('cat.copy_browser.init: ',E);
68         }
69     },
70
71     'controller_init' : function(params) {
72         var obj = this;
73         try {
74             JSAN.use('util.controller'); obj.controller = new util.controller();
75             obj.controller.init(
76                 {
77                     control_map : {
78                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
79                         'sel_clip' : [
80                             ['command'],
81                             function() { obj.list.clipboard(); }
82                         ],
83                         'cmd_broken' : [
84                             ['command'],
85                             function() { 
86                                 alert(document.getElementById('commonStrings').getString('common.unimplemented'));
87                             }
88                         ],
89                         'cmd_show_my_libs' : [
90                             ['command'],
91                             function() { 
92                                 obj.show_my_libs(); 
93                             }
94                         ],
95                         'cmd_show_all_libs' : [
96                             ['command'],
97                             function() {
98                                 obj.show_all_libs();
99                             }
100                         ],
101                         'cmd_show_libs_with_copies' : [
102                             ['command'],
103                             function() {
104                                 obj.show_libs_with_copies();
105                             }
106                         ],
107                         'cmd_clear' : [
108                             ['command'],
109                             function() {
110                                 obj.map_tree = {};
111                                 obj.list.clear();
112                             }
113                         ],
114                         'sel_mark_items_damaged' : [
115                             ['command'],
116                             function() {
117                                 JSAN.use('cat.util'); JSAN.use('util.functional');
118
119                                 var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; });
120
121                                 list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; });
122
123                                 cat.util.mark_item_damaged( list );
124
125                                 obj.refresh_list();
126                             }
127                         ],
128                         'sel_mark_items_missing' : [
129                             ['command'],
130                             function() {
131                                 JSAN.use('cat.util'); JSAN.use('util.functional');
132
133                                 var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; });
134
135                                 list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; });
136
137                                 cat.util.mark_item_missing( list );
138
139                                 obj.refresh_list();
140                             }
141                         ],
142                         'sel_patron' : [
143                             ['command'],
144                             function() {
145                                 JSAN.use('util.functional');
146
147                                 var list = util.functional.filter_list(
148                                     obj.sel_list,
149                                     function (o) {
150                                         return o.split(/_/)[0] == 'acp';
151                                     }
152                                 );
153
154                                 list = util.functional.map_list(
155                                     list,
156                                     function (o) {
157                                         return { 'copy_id' : o.split(/_/)[1] };
158                                     }
159                                 );
160                                 
161                                 JSAN.use('circ.util');
162                                 circ.util.show_last_few_circs(list);
163                             }
164                         ],
165                         'sel_copy_details' : [
166                             ['command'],
167                             function() {
168                                 JSAN.use('util.functional');
169
170                                 var list = util.functional.filter_list(
171                                     obj.sel_list,
172                                     function (o) {
173                                         return o.split(/_/)[0] == 'acp';
174                                     }
175                                 );
176
177                                 JSAN.use('circ.util');
178                                 circ.util.item_details_new(
179                                     util.functional.map_list(
180                                         list, function (o) {
181                                             return obj.map_acp[o].barcode();
182                                         }
183                                     )
184                                 );
185                             }
186                         ],
187                         'cmd_create_brt' : [
188                             ['command'],
189                             function() {
190                                 JSAN.use("cat.util");
191                                 JSAN.use("util.functional");
192
193                                 /* Filter selected rows that aren"t copies. */
194                                 var list = util.functional.filter_list(
195                                     obj.sel_list,
196                                     function (o) {
197                                         return o.split(/_/)[0] == "acp";
198                                     }
199                                 );
200                                 var results = cat.util.make_bookable(
201                                     util.functional.map_list(
202                                         list, function (o) {
203                                             return obj.map_acp[o].id();
204                                         }
205                                     )
206                                 );
207                                 if (results && results["brsrc"]) {
208                                     cat.util.edit_new_brsrc(results["brsrc"]);
209                                 }
210                             }
211                         ],
212                         'cmd_book_item_now' : [
213                             ['command'],
214                             function() {
215                                 JSAN.use("cat.util");
216                                 JSAN.use("util.functional");
217
218                                 /* Filter selected rows that aren"t copies. */
219                                 var list = util.functional.filter_list(
220                                     obj.sel_list,
221                                     function (o) {
222                                         return o.split(/_/)[0] == "acp";
223                                     }
224                                 );
225                                 var results = cat.util.make_bookable(
226                                     util.functional.map_list(
227                                         list, function (o) {
228                                             return obj.map_acp[o].id();
229                                         }
230                                     )
231                                 );
232                                 if (results) {
233                                     cat.util.edit_new_bresv(results);
234                                 }
235                             }
236                         ],
237                         'cmd_add_items' : [
238                             ['command'],
239                             function() {
240                                 try {
241                                     JSAN.use('util.functional');
242                                     var list = util.functional.map_list(
243                                         util.functional.filter_list(
244                                             obj.sel_list,
245                                             function (o) {
246                                                 return o.split(/_/)[0] == 'acn';
247                                             }
248                                         ),
249                                         function (o) {
250                                             return o.split(/_/)[1];
251                                         }
252                                     );
253                                     if (list.length == 0) return;
254
255                                     var copy_shortcut = {};
256                                     list = util.functional.map_list(
257                                         list,
258                                         function (o) {
259                                             var 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                                     JSAN.use('util.window'); var win = new util.window();
292                                     var w = win.open(
293                                         window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR),
294                                             //+'?doc_id=' + window.escape(obj.docid)
295                                             //+'&ou_ids=' + window.escape( js2JSON(list) )
296                                             //+'&copy_shortcut=' + window.escape( js2JSON(copy_shortcut) ),
297                                         title,
298                                         'chrome,resizable'
299                                     );
300                                     w.refresh = function() { obj.refresh_list(); }
301                                     w.xulG = { 'doc_id':obj.docid, 'ou_ids' : list, 'copy_shortcut' : copy_shortcut };
302                                 } catch(E) {
303                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_item.error'),E);
304                                 }
305                             }
306                         ],
307                         'cmd_add_items_to_buckets' : [
308                             ['command'],
309                             function() {
310                                 try {
311                                     JSAN.use('util.functional');
312
313                                     var list = util.functional.filter_list(
314                                         obj.sel_list,
315                                         function (o) {
316                                             return o.split(/_/)[0] == 'acp';
317                                         }
318                                     );
319
320                                     list = util.functional.map_list(
321                                         list,
322                                         function (o) {
323                                             return o.split(/_/)[1];
324                                         }
325                                     );
326                                 
327                                     JSAN.use('cat.util');
328                                     cat.util.add_copies_to_bucket( list );
329
330                                 } catch(E) {
331                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_items_bucket.error'),E);
332                                 }
333                             }
334                         ],
335                         'cmd_replace_barcode' : [
336                             ['command'],
337                             function() {
338                                 try {
339                                     JSAN.use('util.functional');
340
341                                     var list = util.functional.filter_list(
342                                         obj.sel_list,
343                                         function (o) {
344                                             return o.split(/_/)[0] == 'acp';
345                                         }
346                                     );
347
348                                     list = util.functional.map_list(
349                                         list,
350                                         function (o) {
351                                             var cloned_copy_obj = JSON2js( js2JSON( obj.map_acp[ o ] ) );
352                                             cloned_copy_obj.call_number( obj.map_acn[ 'acn_' + cloned_copy_obj.call_number() ] );
353                                             return cloned_copy_obj;
354                                         }
355                                     );
356
357                                     xulG.volume_item_creator( {'existing_copies':list, 'onrefresh' : function() { obj.refresh_list(); } } );
358
359                                 } catch(E) {
360                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.replace_barcode.error'),E);
361                                     obj.refresh_list();
362                                 }
363                             }
364                         ],
365                         'cmd_edit_items' : [
366                             ['command'],
367                             function() {
368                                 try {
369                                     JSAN.use('util.functional');
370
371                                     var list = util.functional.filter_list(
372                                         obj.sel_list,
373                                         function (o) {
374                                             return o.split(/_/)[0] == 'acp';
375                                         }
376                                     );
377
378                                     list = util.functional.map_list(
379                                         list,
380                                         function (o) {
381                                             return o.split(/_/)[1];
382                                         }
383                                     );
384
385                                     JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
386                                     obj.refresh_list();
387
388                                 } catch(E) {
389                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E);
390                                 }
391                             }
392                         ],
393                         'cmd_delete_items' : [
394                             ['command'],
395                             function() {
396                                 try {
397                                     JSAN.use('util.functional');
398
399                                     var list = util.functional.filter_list(
400                                         obj.sel_list,
401                                         function (o) {
402                                             return o.split(/_/)[0] == 'acp';
403                                         }
404                                     );
405
406                                     list = util.functional.map_list(
407                                         list,
408                                         function (o) {
409                                             return JSON2js( js2JSON( obj.map_acp[ 'acp_' + o.split(/_/)[1] ] ) );
410                                         }
411                                     );
412
413                                     var delete_msg;
414                                     if (list.length != 1) {
415                                         delete_msg = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_items.confirm.plural', [list.length]);
416                                     } else {
417                                         delete_msg = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.confirm');
418                                     }
419                                     var r = obj.error.yns_alert(
420                                             delete_msg,
421                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.title'),
422                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.delete'),
423                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.cancel'),
424                                             null,
425                                             document.getElementById('commonStrings').getString('common.confirm')
426                                     );
427
428                                     if (r == 0) {
429                                         var acn_hash = {}; var acn_list = [];
430                                         for (var i = 0; i < list.length; i++) {
431                                             list[i].isdeleted('1');
432                                             var acn_id = list[i].call_number();
433                                             if ( ! acn_hash[ acn_id ] ) {
434                                                 acn_hash[ acn_id ] = obj.map_acn[ 'acn_' + acn_id ];
435                                                 acn_hash[ acn_id ].copies( [] );
436                                             }
437                                             var temp = acn_hash[ acn_id ].copies();
438                                             temp.push( list[i] );
439                                             acn_hash[ acn_id ].copies( temp );
440                                         }
441                                         for (var i in acn_hash) acn_list.push( acn_hash[i] );
442                                         var robj = obj.network.simple_request(
443                                             'FM_ACN_TREE_UPDATE', 
444                                             [ ses(), acn_list, true ],
445                                             null,
446                                             {
447                                                 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.override'),
448                                                 'overridable_events' : [
449                                                     1208 /* TITLE_LAST_COPY */,
450                                                     1227 /* COPY_DELETE_WARNING */,
451                                                 ]
452                                             }
453                                         );
454                                         if (robj == null) throw(robj);
455                                         if (typeof robj.ilsevent != 'undefined') {
456                                             if ( (robj.ilsevent != 0) && (robj.ilsevent != 1227 /* COPY_DELETE_WARNING */) && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */) ) throw(robj);
457                                         }
458                                         obj.refresh_list();
459                                     }
460
461                                     
462                                 } catch(E) {
463                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.error'),E);
464                                     obj.refresh_list();
465                                 }
466                             }
467                         ],
468                         'cmd_print_spine_labels' : [
469                             ['command'],
470                             function() {
471                                 try {
472                                     JSAN.use('util.functional');
473                                     
474                                     var list = util.functional.filter_list(
475                                         obj.sel_list,
476                                         function (o) {
477                                             return o.split(/_/)[0] == 'acp';
478                                         }
479                                     );
480
481                                     list = util.functional.map_list(
482                                         list,
483                                         function (o) {
484                                             return obj.map_acp[ o ];
485                                         }
486                                     );
487
488                                     obj.data.temp_barcodes_for_labels = util.functional.map_list( list, function(o){return o.barcode();}) ; 
489                                     obj.data.stash('temp_barcodes_for_labels');
490                                     xulG.new_tab(
491                                         xulG.url_prefix( urls.XUL_SPINE_LABEL ),
492                                         { 'tab_name' : document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.tab') },
493                                         {}
494                                     );
495                                 } catch(E) {
496                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.error'),E);
497                                 }
498                             }
499                         ],
500                         'cmd_add_volumes' : [
501                             ['command'],
502                             function() {
503                                 try {
504                                     JSAN.use('util.functional');
505                                     var list = util.functional.filter_list(
506                                         obj.sel_list,
507                                         function (o) {
508                                             return o.split(/_/)[0] == 'aou';
509                                         }
510                                     );
511                                     list = util.functional.map_list(
512                                         list,
513                                         function (o) {
514                                             return o.split(/_/)[1];
515                                         }
516                                     );        
517                                     var edit = 0;
518                                     try {
519                                         edit = obj.network.request(
520                                             api.PERM_MULTI_ORG_CHECK.app,
521                                             api.PERM_MULTI_ORG_CHECK.method,
522                                             [ 
523                                                 ses(), 
524                                                 obj.data.list.au[0].id(), 
525                                                 list,
526                                                 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
527                                             ]
528                                         ).length == 0 ? 1 : 0;
529                                     } catch(E) {
530                                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
531                                     }
532
533                                     if (edit==0) {
534                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.permission_error'));
535                                         return; // no read-only view for this interface
536                                     }
537
538                                     var title = document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.title');
539
540                                     JSAN.use('util.window'); var win = new util.window();
541                                     var w = win.open(
542                                         window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR),
543                                             //+'?doc_id=' + window.escape(obj.docid)
544                                             //+'&ou_ids=' + window.escape( js2JSON(list) ),
545                                         title,
546                                         'chrome,resizable'
547                                     );
548
549                                     w.refresh = function() { obj.refresh_list() };
550                                     w.xulG = { 'doc_id' : obj.docid, 'ou_ids' : list };
551                                 } catch(E) {
552                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.error'),E);
553                                 }
554                             }
555                         ],
556                         'cmd_edit_volumes' : [
557                             ['command'],
558                             function() {
559                                 try {
560                                     JSAN.use('util.functional');
561                                     var volumes = util.functional.map_list(
562                                         util.functional.filter_list(
563                                             obj.sel_list,
564                                             function (o) {
565                                                 return o.split(/_/)[0] == 'acn';
566                                             }
567                                         ),
568                                         function (o) {
569                                             return o.split(/_/)[1];
570                                         }
571                                     );
572                                     volumes = util.functional.map_list(
573                                         volumes,
574                                         function (o) {
575                                             var my_acn = obj.map_acn['acn_' + o];
576                                             return function(r){return r;}(my_acn);
577                                         }
578                                     );
579
580                                     JSAN.use('cat.util'); 
581                                     if ( cat.util.batch_edit_volumes( volumes ) ) {
582                                         obj.refresh_list();
583                                     }
584
585                                 } catch(E) {
586                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.exception'),E);
587                                 }
588                             }
589                         ],
590                         'cmd_delete_volumes' : [
591                             ['command'],
592                             function() {
593                                 try {
594                                     JSAN.use('util.functional');
595
596                                     var list = util.functional.filter_list(
597                                         obj.sel_list,
598                                         function (o) {
599                                             return o.split(/_/)[0] == 'acn';
600                                         }
601                                     );
602
603                                     list = util.functional.map_list(
604                                         list,
605                                         function (o) {
606                                             return JSON2js( js2JSON( obj.map_acn[ 'acn_' + o.split(/_/)[1] ] ) );
607                                         }
608                                     );
609
610                                     var del_prompt;
611                                     if (list.length == 1) {
612                                         del_prompt = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.prompt');
613                                     } else {
614                                         del_prompt = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_volume.prompt.plural', [list.length]);
615                                     }
616
617                                     var r = obj.error.yns_alert(
618                                             del_prompt,
619                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.title'),
620                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.delete'),
621                                             document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.cancel'),
622                                             null,
623                                             document.getElementById('commonStrings').getString('common.confirm')
624                                     );
625
626                                     if (r == 0) {
627                                         for (var i = 0; i < list.length; i++) {
628                                             list[i].isdeleted('1');
629                                         }
630                                         var robj = obj.network.simple_request(
631                                             'FM_ACN_TREE_UPDATE', 
632                                             [ ses(), list, true ],
633                                             null,
634                                             {
635                                                 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.override'),
636                                                 'overridable_events' : [
637                                                 ]
638                                             }
639                                         );
640                                         if (robj == null) throw(robj);
641                                         if (typeof robj.ilsevent != 'undefined') {
642                                             if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
643                                                 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain'));
644                                                 return;
645                                             }
646                                             if (robj.ilsevent != 0) throw(robj);
647                                         }
648                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.success'));
649                                         obj.refresh_list();
650                                     }
651                                 } catch(E) {
652                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.exception'),E);
653                                     obj.refresh_list();
654                                 }
655
656                             }
657                         ],
658                         'cmd_mark_library' : [
659                             ['command'],
660                             function() {
661                                 try {
662                                     var list = util.functional.filter_list(
663                                         obj.sel_list,
664                                         function (o) {
665                                             return o.split(/_/)[0] == 'aou';
666                                         }
667                                     );
668
669                                     list = util.functional.map_list(
670                                         list,
671                                         function (o) {
672                                             return o.split(/_/)[1];
673                                         }
674                                     );
675
676                                     if (list.length == 1) {
677                                         obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid };
678                                         obj.data.stash('marked_library');
679                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.alert'));
680                                     } else {
681                                         obj.error.yns_alert(
682                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.prompt'),
683                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.title'),
684                                                 document.getElementById('commonStrings').getString('common.ok'),
685                                                 null,
686                                                 null,
687                                                 document.getElementById('commonStrings').getString('common.confirm')
688                                                 );
689                                     }
690                                 } catch(E) {
691                                     obj.error.standard_unexpected_error_alert('copy browser -> mark library',E);
692                                 }
693                             }
694                         ],
695
696                         'cmd_mark_volume' : [
697                             ['command'],
698                             function() {
699                                 try {
700                                     var list = util.functional.filter_list(
701                                         obj.sel_list,
702                                         function (o) {
703                                             return o.split(/_/)[0] == 'acn';
704                                         }
705                                     );
706
707                                     list = util.functional.map_list(
708                                         list,
709                                         function (o) {
710                                             return o.split(/_/)[1];
711                                         }
712                                     );
713
714                                     if (list.length == 1) {
715                                         obj.data.marked_volume = list[0];
716                                         obj.data.stash('marked_volume');
717                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.alert'));
718                                     } else {
719                                         obj.error.yns_alert(
720                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.prompt'),
721                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.title'),
722                                                 document.getElementById('commonStrings').getString('common.ok'),
723                                                 null,
724                                                 null,
725                                                 document.getElementById('commonStrings').getString('common.confirm')
726                                                 );
727                                     }
728                                 } catch(E) {
729                                     obj.error.standard_unexpected_error_alert('copy browser -> mark volume',E);
730                                 }
731                             }
732                         ],
733                         'cmd_refresh_list' : [
734                             ['command'],
735                             function() {
736                                 obj.refresh_list();
737                             }
738                         ],
739                         'cmd_transfer_volume' : [
740                             ['command'],
741                             function() {
742                                 try {
743                                     obj.data.stash_retrieve();
744                                     if (!obj.data.marked_library) {
745                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_volume.alert'));
746                                         return;
747                                     }
748                                     
749                                     JSAN.use('util.functional');
750
751                                     var list = util.functional.filter_list(
752                                         obj.sel_list,
753                                         function (o) {
754                                             return o.split(/_/)[0] == 'acn';
755                                         }
756                                     );
757
758                                     list = util.functional.map_list(
759                                         list,
760                                         function (o) {
761                                             return o.split(/_/)[1];
762                                         }
763                                     );
764
765                                     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
766
767                                     var acn_list = util.functional.map_list(
768                                         list,
769                                         function (o) {
770                                             return obj.map_acn[ 'acn_' + o ].label();
771                                         }
772                                     ).join(document.getElementById('commonStrings').getString('common.grouping_string'));
773
774                                     var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
775                                     xml += '<description>';
776                                     xml += document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.transfer.prompt', [acn_list, obj.data.hash.aou[ obj.data.marked_library.lib ].shortname()]);
777                                     xml += '</description>';
778                                     xml += '<hbox><button label="' + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.submit.label') + '" name="fancy_submit"/>';
779                                     xml += '<button label="' 
780                                         + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.label') 
781                                         + '" accesskey="' 
782                                         + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.accesskey') 
783                                         + '" name="fancy_cancel"/></hbox>';
784                                     xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
785                                     xml += '</vbox>';
786                                     JSAN.use('OpenILS.data');
787                                     var data = new OpenILS.data(); data.init({'via':'stash'});
788                                     //data.temp_transfer = xml; data.stash('temp_transfer');
789                                     JSAN.use('util.window'); var win = new util.window();
790                                     var fancy_prompt_data = win.open(
791                                         urls.XUL_FANCY_PROMPT,
792                                         //+ '?xml_in_stash=temp_transfer'
793                                         //+ '&title=' + window.escape('Volume Transfer'),
794                                         'fancy_prompt', 'chrome,resizable,modal,width=500,height=300',
795                                         {
796                                             'xml' : xml,
797                                             'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.title')
798                                         }
799                                     );
800
801                                     if (fancy_prompt_data.fancy_status == 'incomplete') {
802                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.incomplete'));
803                                         return;
804                                     }
805
806                                     var robj = obj.network.simple_request(
807                                         'FM_ACN_TRANSFER', 
808                                         [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'volumes' : list } ],
809                                         null,
810                                         {
811                                             'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.override.failure'),
812                                             'overridable_events' : [
813                                                 1208 /* TITLE_LAST_COPY */,
814                                                 1219 /* COPY_REMOTE_CIRC_LIB */,
815                                             ],
816                                         }
817                                     );
818
819                                     if (typeof robj.ilsevent != 'undefined') {
820                                         if (robj.ilsevent == 1221 /* ORG_CANNOT_HAVE_VOLS */) {
821                                             alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.ineligible_destination'));
822                                         } else {
823                                             throw(robj);
824                                         }
825                                     } else {
826                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.success'));
827                                     }
828
829                                 } catch(E) {
830                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.unexpected_error'),E);
831                                 }
832                                 obj.refresh_list();
833                             }
834                         ],
835
836                         'cmd_transfer_items' : [
837                             ['command'],
838                             function() {
839                                 try {
840                                     obj.data.stash_retrieve();
841                                     if (!obj.data.marked_volume) {
842                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.missing_volume'));
843                                         return;
844                                     }
845                                     
846                                     JSAN.use('util.functional');
847
848                                     var list = util.functional.filter_list(
849                                         obj.sel_list,
850                                         function (o) {
851                                             return o.split(/_/)[0] == 'acp';
852                                         }
853                                     );
854
855                                     list = util.functional.map_list(
856                                         list,
857                                         function (o) {
858                                             return o.split(/_/)[1];
859                                         }
860                                     );
861
862                                     var volume = obj.network.simple_request('FM_ACN_RETRIEVE.authoritative',[ obj.data.marked_volume ]);
863
864                                     JSAN.use('cat.util'); cat.util.transfer_copies( { 
865                                         'copy_ids' : list, 
866                                         'docid' : volume.record(),
867                                         'volume_label' : volume.label(),
868                                         'owning_lib' : volume.owning_lib(),
869                                     } );
870
871                                 } catch(E) {
872                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.unexpected_error'),E);
873                                 }
874                                 obj.refresh_list();
875                             }
876                         ],
877                     }
878                 }
879             );
880
881         } catch(E) {
882             this.error.standard_unexpected_error_alert('cat.copy_browser.controller_init(): ',E);
883         }
884     },
885
886     'depth_menu_init' : function(params) {
887         var obj = this;
888         try {
889             var list = [];
890             var max_depth = 0;
891             for (var i = 0; i < obj.data.list.aout.length; i++) {
892                 var type = obj.data.list.aout[i];
893                 var depth = type.depth();
894                 if ( depth > max_depth) { max_depth = depth; }
895                 if (typeof list[depth] == 'undefined') {
896                     list[depth] = [
897                         type.opac_label(),
898                         type.depth(),
899                         false,
900                         ( type.depth() * 2)
901                     ];
902                 } else {
903                     list[depth][0] += ' / ' + type.opac_label();
904                 }
905             }
906             ml = util.widgets.make_menulist( list, max_depth );
907             ml.setAttribute('id','depth_menu'); document.getElementById('x_depth_menu').appendChild(ml);
908             ml.addEventListener(
909                 'command',
910                 function(ev) {
911                     obj.default_depth = ev.target.value;
912                     if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus(); 
913                     JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
914                     util.widgets.save_attributes(file, { 
915                         'lib_menu' : [ 'value' ],
916                         'depth_menu' : [ 'value' ],
917                         'show_acns' : [ 'checked' ],
918                         'show_acps' : [ 'checked' ]
919                     });
920                 },
921                 false
922             );
923
924             file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
925             util.widgets.load_attributes(file);
926             ml.value = ml.getAttribute('value');
927             if (! ml.value) {
928                 ml.value = max_depth;
929                 ml.setAttribute('value',ml.value);
930             }
931
932             return ml.value;
933         } catch(E) {
934             alert('Error in copy_browser.js, depth_menu_init(): ' + E);
935         }
936     },
937
938     'library_menu_init' : function(params) {
939         var obj = this;
940         try {
941
942             obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
943             if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
944             JSAN.use('util.functional'); 
945             obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
946
947             var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
948
949             JSAN.use('util.file'); JSAN.use('util.widgets');
950
951             var file; var list_data; var ml; 
952
953             file = new util.file('offline_ou_list'); 
954             if (file._file.exists()) {
955                 list_data = file.get_object(); file.close();
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             if (obj.data.hash.aout[ org.ou_type() ].depth() == 0 && ! get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) return;
1252             obj.funcs.push( function() { 
1253                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1254                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1255                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1256             } );
1257             if (org.children()) {
1258                 for (var i = 0; i < org.children().length; i++) {
1259                     var child = org.children()[i];
1260                     if (obj.data.hash.aout[child.ou_type()].depth() <= obj.default_depth
1261                     && orgIsMine(obj.default_lib,child,obj.default_depth)) {
1262                         obj.funcs.push(
1263                             function(o,p) {
1264                                 return function() {
1265                                     obj.append_org(o,p)
1266                                 }
1267                             }(child,org)
1268                         );
1269                     }
1270                 }
1271             } 
1272             if (obj.map_acn[ 'aou_' + org_id ]) {
1273                 for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
1274                     obj.funcs.push(
1275                         function(o,a) {
1276                             return function() {
1277                                 obj.append_acn(o,a);
1278                             }
1279                         }( org, obj.map_acn[ 'aou_' + org_id ][i] )
1280                     );
1281                 }
1282             }
1283             obj.funcs.push( function() { 
1284                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1285                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1286                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1287             } );
1288         } catch(E) {
1289             alert('Error in copy_browser.js, on_select_org(): ' + E);
1290         }
1291     },
1292
1293     'append_org' : function (org,parent_org,params) {
1294         var obj = this;
1295         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1296         obj.error.consoleService.logStringMessage('append_org: org = ' + org.shortname() + ' parent_org = ' + (parent_org ? parent_org.shortname() : '') + ' params = ' + js2JSON(params) + '\n');
1297         try {
1298             if (obj.map_tree[ 'aou_' + org.id() ]) {
1299                 var x = obj.map_tree[ 'aou_' + org.id() ];
1300                 if (params) {
1301                     for (var i in params) {
1302                         x.setAttribute(i,params[i]);
1303                     }
1304                 }
1305                 return x;
1306             }
1307
1308             var data = {
1309                 'row' : {
1310                     'my' : {
1311                         'aou' : org,
1312                     }
1313                 },
1314                 'skip_all_columns_except' : [0,1,2],
1315                 'retrieve_id' : 'aou_' + org.id(),
1316                 'to_bottom' : true,
1317                 'no_auto_select' : true,
1318             };
1319         
1320             var acn_tree_list;
1321             if ( obj.org_ids.indexOf( Number( org.id() ) ) == -1 ) {
1322                 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) {
1323                     data.row.my.volume_count = '0';
1324                     data.row.my.copy_count = '<0>';
1325                 } else {
1326                     data.row.my.volume_count = '';
1327                     data.row.my.copy_count = '';
1328                 }
1329             } else {
1330                 var v_count = 0; var c_count = 0;
1331                 acn_tree_list = obj.network.simple_request(
1332                     'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS.authoritative',
1333                     [ ses(), obj.docid, [ org.id() ] ]
1334                 );
1335                 for (var i = 0; i < acn_tree_list.length; i++) {
1336                     v_count++;
1337                     obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
1338                     var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
1339                     for (var j = 0; j < copies.length; j++) {
1340                         obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
1341                     }
1342                 }
1343                 data.row.my.volume_count = v_count;
1344                 data.row.my.copy_count = '<' + c_count + '>';
1345             }
1346             if (parent_org) {
1347                 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1348             }
1349             var nparams = obj.list.append(data);
1350             var node = nparams.my_node;
1351             if (params) {
1352                 for (var i in params) {
1353                     node.setAttribute(i,params[i]);
1354                 }
1355             }
1356             obj.map_tree[ 'aou_' + org.id() ] = node;
1357
1358             if (org.children()) {
1359                 node.setAttribute('container','true');
1360             }
1361
1362             if (parent_org) {
1363                 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1364                     data.node.setAttribute('open','true');
1365                 }
1366             } else {
1367                 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1368             }
1369
1370             if (acn_tree_list) {
1371                 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
1372                 node.setAttribute('container','true');
1373             }
1374
1375             if (document.getElementById('show_acns').checked) {
1376                 if (! ( obj.data.hash.aout[ org.ou_type() ].depth() == 0 && ! get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) )) {
1377                     node.setAttribute('open','true');
1378                     obj.funcs.push( function() { obj.on_select_org( org.id() ); } );
1379                 }
1380             }
1381
1382         } catch(E) {
1383             dump(E+'\n');
1384             alert(E);
1385         }
1386     },
1387
1388     'append_acn' : function( org, acn_tree, params ) {
1389         var obj = this;
1390         try {
1391             if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
1392                 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
1393                 if (params) {
1394                     for (var i in params) {
1395                         x.setAttribute(i,params[i]);
1396                     }
1397                 }
1398                 return x;
1399             }
1400
1401             var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1402             var data = {
1403                 'row' : {
1404                     'my' : {
1405                         'aou' : org,
1406                         'acn' : acn_tree,
1407                         'volume_count' : '',
1408                         'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
1409                     }
1410                 },
1411                 'skip_all_columns_except' : [0,1,2],
1412                 'retrieve_id' : 'acn_' + acn_tree.id(),
1413                 'node' : parent_node,
1414                 'to_bottom' : true,
1415                 'no_auto_select' : true,
1416             };
1417             var nparams = obj.list.append(data);
1418             var node = nparams.my_node;
1419             obj.map_tree[ 'acn_' + acn_tree.id() ] =  node;
1420             if (params) {
1421                 for (var i in params) {
1422                     node.setAttribute(i,params[i]);
1423                 }
1424             }
1425             if (acn_tree.copies()) {
1426                 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
1427                 node.setAttribute('container','true');
1428             }
1429             if (document.getElementById('show_acps').checked) {
1430                 node.setAttribute('open','true');
1431                 obj.funcs.push( function() { obj.on_select_acn( acn_tree.id() ); } );
1432             }
1433
1434         } catch(E) {
1435             dump(E+'\n');
1436             alert(E);
1437         }
1438     },
1439
1440     'append_acp' : function( acp_item, acn_tree, params ) {
1441         var obj = this;
1442         try {
1443             if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
1444                 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
1445                 if (params) {
1446                     for (var i in params) {
1447                         x.setAttribute(i,params[i]);
1448                     }
1449                 }
1450                 return x;
1451             }
1452
1453             var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
1454             var data = {
1455                 'row' : {
1456                     'my' : {
1457                         'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
1458                         'acn' : acn_tree,
1459                         'acp' : acp_item,
1460                         'volume_count' : '',
1461                         'copy_count' : '',
1462                     }
1463                 },
1464                 'retrieve_id' : 'acp_' + acp_item.id(),
1465                 'node' : parent_node,
1466                 'to_bottom' : true,
1467                 'no_auto_select' : true,
1468             };
1469             var nparams = obj.list.append(data);
1470             var node = nparams.my_node;
1471             obj.map_tree[ 'acp_' + acp_item.id() ] =  node;
1472             if (params) {
1473                 for (var i in params) {
1474                     node.setAttribute(i,params[i]);
1475                 }
1476             }
1477
1478         } catch(E) {
1479             dump(E+'\n');
1480             alert(E);
1481         }
1482     },
1483
1484     'list_init' : function( params ) {
1485
1486         try {
1487             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1488             var obj = this;
1489             
1490             JSAN.use('circ.util');
1491             var columns = [
1492                 {
1493                     'id' : 'tree_location',
1494                     'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.tree_location'),
1495                     'flex' : 1, 'primary' : true, 'hidden' : false, 
1496                     'render' : function(my) { return my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"; },
1497                 },
1498                 {
1499                     'id' : 'volume_count',
1500                     'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.volume_count'),
1501                     'flex' : 0, 'primary' : false, 'hidden' : false, 
1502                     'render' : function(my) { return my.volume_count; },
1503                 },
1504                 {
1505                     'id' : 'copy_count',
1506                     'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.copy_count'),
1507                     'flex' : 0,
1508                     'primary' : false, 'hidden' : false, 
1509                     'render' : function(my) { return my.copy_count; },
1510                 },
1511             ].concat(
1512                 circ.util.columns( 
1513                     { 
1514                         'location' : { 'hidden' : false },
1515                         'circ_lib' : { 'hidden' : false },
1516                         'owning_lib' : { 'hidden' : false },
1517                         'call_number' : { 'hidden' : false },
1518                         'due_date' : { 'hidden' : false },
1519                         'acp_status' : { 'hidden' : false },
1520                     },
1521                     {
1522                         'just_these' : [
1523                             'due_date',
1524                             'owning_lib',
1525                             'circ_lib',
1526                             'call_number',
1527                             'copy_number',
1528                             'location',
1529                             'barcode',
1530                             'loan_duration',
1531                             'fine_level',
1532                             'circulate',
1533                             'holdable',
1534                             'opac_visible',
1535                             'ref',
1536                             'deposit',
1537                             'deposit_amount',
1538                             'price',
1539                             'circ_as_type',
1540                             'circ_modifier',
1541                             'acp_status',
1542                             'alert_message',
1543                             'acp_mint_condition',
1544                             'acp_id'
1545                         ]
1546                     }
1547                 )
1548             );
1549             JSAN.use('util.list'); obj.list = new util.list('copy_tree');
1550             obj.list.init(
1551                 {
1552                     'no_auto_select' : true,
1553                     'columns' : columns,
1554                     'map_row_to_columns' : circ.util.std_map_row_to_columns(' '),
1555                     'retrieve_row' : function(params) {
1556
1557                         var row = params.row;
1558
1559                     /*    
1560                         if (!row.my.mvr) obj.funcs.push(
1561                             function() {
1562
1563                                 row.my.mvr = obj.network.request(
1564                                     api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
1565                                     api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
1566                                     [ row.my.circ.target_copy() ]
1567                                 );
1568
1569                             }
1570                         );
1571                         if (!row.my.acp) {
1572                             obj.funcs.push(    
1573                                 function() {
1574
1575                                     row.my.acp = obj.network.request(
1576                                         api.FM_ACP_RETRIEVE.app,
1577                                         api.FM_ACP_RETRIEVE.method,
1578                                         [ row.my.circ.target_copy() ]
1579                                     );
1580
1581                                     params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1582
1583                                 }
1584                             );
1585                         } else {
1586                             params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1587                         }
1588                     */
1589                         obj.funcs.push(
1590                             function() {
1591
1592                                 if (typeof params.on_retrieve == 'function') {
1593                                     params.on_retrieve(row);
1594                                 }
1595
1596                             }
1597                         );
1598
1599                         return row;
1600                     },
1601                     'on_click' : function(ev) {
1602                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1603                         var row = {}; var col = {}; var nobj = {};
1604                         obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj); 
1605                         if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
1606                         var node = obj.list.node.contentView.getItemAtIndex(row.value);
1607                         var list = [ node.getAttribute('retrieve_id') ];
1608                         if (typeof obj.on_select == 'function') {
1609                             obj.on_select(list,true);
1610                         }
1611                         if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1612                             window.xulG.on_select(list);
1613                         }
1614                     },
1615                     'on_select' : function(ev) {
1616                         JSAN.use('util.functional');
1617                         var sel = obj.list.retrieve_selection();
1618                         obj.controller.view.sel_clip.disabled = sel.length < 1;
1619                         obj.sel_list = util.functional.map_list(
1620                             sel,
1621                             function(o) { return o.getAttribute('retrieve_id'); }
1622                         );
1623                         obj.toggle_actions();
1624                         if (typeof obj.on_select == 'function') {
1625                             obj.on_select(obj.sel_list);
1626                         }
1627                         if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1628                             window.xulG.on_select(obj.sel_list);
1629                         }
1630                     },
1631                 }
1632             );
1633
1634         } catch(E) {
1635             this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
1636             alert(E);
1637         }
1638     },
1639
1640     'toggle_actions' : function() {
1641         var obj = this;
1642         try {
1643             var found_aou = false; var found_acn = false; var found_acp = false;
1644             var found_aou_with_can_have_vols = false;
1645             var sel_copy_libs = {};
1646             for (var i = 0; i < obj.sel_list.length; i++) {
1647                 var type = obj.sel_list[i].split(/_/)[0];
1648                 switch(type) {
1649                     case 'aou' : 
1650                         found_aou = true; 
1651                         var org = obj.data.hash.aou[ obj.sel_list[i].split(/_/)[1] ];
1652                         if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) found_aou_with_can_have_vols = true;
1653                     break;
1654                     case 'acn' : found_acn = true; break;
1655                     case 'acp' :
1656                         found_acp = true;
1657                         sel_copy_libs[
1658                             obj.map_acn[
1659                                 "acn_" +
1660                                 obj.map_acp[obj.sel_list[i]].call_number()
1661                             ].owning_lib()
1662                         ] = true;
1663                         break;
1664                 }
1665             }
1666             obj.controller.view.cmd_add_items.setAttribute('disabled','true');
1667             obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','true');
1668             obj.controller.view.cmd_edit_items.setAttribute('disabled','true');
1669             obj.controller.view.cmd_replace_barcode.setAttribute('disabled','true');
1670             obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
1671             obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','true');
1672             obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
1673             obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1674             obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
1675             obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
1676             obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
1677             obj.controller.view.cmd_transfer_volume.setAttribute('disabled','true');
1678             obj.controller.view.cmd_transfer_items.setAttribute('disabled','true');
1679             obj.controller.view.sel_copy_details.setAttribute('disabled','true');
1680             obj.controller.view.cmd_create_brt.setAttribute('disabled','true');
1681             obj.controller.view.cmd_book_item_now.setAttribute('disabled','true');
1682             obj.controller.view.sel_patron.setAttribute('disabled','true');
1683             obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
1684             obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
1685             if (found_aou && found_aou_with_can_have_vols) {
1686                 obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
1687                 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1688             }
1689             if (found_acn) {
1690                 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
1691                 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
1692                 obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
1693                 obj.controller.view.cmd_add_items.setAttribute('disabled','false');
1694                 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','false');
1695             }
1696             if (found_acp) {
1697                 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
1698                 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
1699                 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','false');
1700                 obj.controller.view.cmd_edit_items.setAttribute('disabled','false');
1701                 obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
1702                 obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
1703                 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','false');
1704                 obj.controller.view.cmd_transfer_items.setAttribute('disabled','false');
1705                 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
1706                 obj.controller.view.cmd_create_brt.setAttribute('disabled','false');
1707                 obj.controller.view.sel_patron.setAttribute('disabled','false');
1708
1709                 var L = 0; for (var k in sel_copy_libs) L++;
1710                 if (L < 2) {
1711                     obj.controller.view.cmd_book_item_now.setAttribute('disabled','false');
1712                 }
1713             }
1714         } catch(E) {
1715             obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.actions.error'),E);
1716         }
1717     },
1718
1719     'refresh_list' : function() { 
1720         try {
1721             var obj = this;
1722             obj.list.clear();
1723             obj.map_tree = {};
1724             obj.map_acn = {};
1725             obj.map_acp = {};
1726             obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
1727             if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
1728             JSAN.use('util.functional'); 
1729             obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
1730             obj.show_my_libs( obj.default_lib.id() );
1731             // FIXME - we get a null from the copy_count call if we call it too quickly here
1732             setTimeout( function() { obj.show_consortial_count(); }, 2000 );
1733         } catch(E) {
1734             this.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.refresh_list.error'),E);
1735         }
1736     },
1737 }
1738
1739 dump('exiting cat.copy_browser.js\n');