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