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