]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_browser.js
Merge branch 'master' of git.evergreen-ils.org:Evergreen into dbs/unnest_master
[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) {
687                                         for (var i = 0; i < list.length; i++) {
688                                             list[i].isdeleted('1');
689                                         }
690                                         var robj = obj.network.simple_request(
691                                             'FM_ACN_TREE_UPDATE', 
692                                             [ ses(), list, true ],
693                                             null,
694                                             {
695                                                 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.override'),
696                                                 'overridable_events' : [
697                                                 ]
698                                             }
699                                         );
700                                         if (robj == null) throw(robj);
701                                         if (typeof robj.ilsevent != 'undefined') {
702                                             if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
703                                                 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain'));
704                                                 return;
705                                             }
706                                             if (robj.ilsevent != 0) throw(robj);
707                                         }
708                                         obj.refresh_list();
709                                     }
710                                 } catch(E) {
711                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.exception'),E);
712                                     obj.refresh_list();
713                                 }
714
715                             }
716                         ],
717                         'cmd_mark_library' : [
718                             ['command'],
719                             function() {
720                                 try {
721                                     var list = util.functional.filter_list(
722                                         obj.sel_list,
723                                         function (o) {
724                                             return o.split(/_/)[0] == 'aou';
725                                         }
726                                     );
727
728                                     list = util.functional.map_list(
729                                         list,
730                                         function (o) {
731                                             return o.split(/_/)[1];
732                                         }
733                                     );
734
735                                     if (list.length == 1) {
736                                         obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid };
737                                         obj.data.stash('marked_library');
738                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.alert'));
739                                     } else {
740                                         obj.error.yns_alert(
741                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.prompt'),
742                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.title'),
743                                                 document.getElementById('commonStrings').getString('common.ok'),
744                                                 null,
745                                                 null,
746                                                 document.getElementById('commonStrings').getString('common.confirm')
747                                                 );
748                                     }
749                                 } catch(E) {
750                                     obj.error.standard_unexpected_error_alert('copy browser -> mark library',E);
751                                 }
752                             }
753                         ],
754
755                         'cmd_mark_volume' : [
756                             ['command'],
757                             function() {
758                                 try {
759                                     var list = util.functional.filter_list(
760                                         obj.sel_list,
761                                         function (o) {
762                                             return o.split(/_/)[0] == 'acn';
763                                         }
764                                     );
765
766                                     list = util.functional.map_list(
767                                         list,
768                                         function (o) {
769                                             return o.split(/_/)[1];
770                                         }
771                                     );
772
773                                     if (list.length == 1) {
774                                         obj.data.marked_volume = list[0];
775                                         obj.data.stash('marked_volume');
776                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.alert'));
777                                     } else {
778                                         obj.error.yns_alert(
779                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.prompt'),
780                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.title'),
781                                                 document.getElementById('commonStrings').getString('common.ok'),
782                                                 null,
783                                                 null,
784                                                 document.getElementById('commonStrings').getString('common.confirm')
785                                                 );
786                                     }
787                                 } catch(E) {
788                                     obj.error.standard_unexpected_error_alert('copy browser -> mark volume',E);
789                                 }
790                             }
791                         ],
792                         'cmd_refresh_list' : [
793                             ['command'],
794                             function() {
795                                 obj.refresh_list();
796                             }
797                         ],
798                         'cmd_transfer_volume' : [
799                             ['command'],
800                             function() {
801                                 try {
802                                     obj.data.stash_retrieve();
803                                     if (!obj.data.marked_library) {
804                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_volume.alert'));
805                                         return;
806                                     }
807                                     
808                                     JSAN.use('util.functional');
809
810                                     var list = util.functional.filter_list(
811                                         obj.sel_list,
812                                         function (o) {
813                                             return o.split(/_/)[0] == 'acn';
814                                         }
815                                     );
816
817                                     list = util.functional.map_list(
818                                         list,
819                                         function (o) {
820                                             return o.split(/_/)[1];
821                                         }
822                                     );
823
824                                     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
825
826                                     var acn_list = util.functional.map_list(
827                                         list,
828                                         function (o) {
829                                             return obj.map_acn[ 'acn_' + o ].label();
830                                         }
831                                     ).join(document.getElementById('commonStrings').getString('common.grouping_string'));
832
833                                     var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
834                                     xml += '<description>';
835                                     xml += document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.transfer.prompt', [acn_list, obj.data.hash.aou[ obj.data.marked_library.lib ].shortname()]);
836                                     xml += '</description>';
837                                     xml += '<hbox><button label="' + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.submit.label') + '" name="fancy_submit"/>';
838                                     xml += '<button label="' 
839                                         + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.label') 
840                                         + '" accesskey="' 
841                                         + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.accesskey') 
842                                         + '" name="fancy_cancel"/></hbox>';
843                                     xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
844                                     xml += '</vbox>';
845                                     JSAN.use('OpenILS.data');
846                                     var data = new OpenILS.data(); data.init({'via':'stash'});
847                                     //data.temp_transfer = xml; data.stash('temp_transfer');
848                                     JSAN.use('util.window'); var win = new util.window();
849                                     var fancy_prompt_data = win.open(
850                                         urls.XUL_FANCY_PROMPT,
851                                         //+ '?xml_in_stash=temp_transfer'
852                                         //+ '&title=' + window.escape('Volume Transfer'),
853                                         'fancy_prompt', 'chrome,resizable,modal,width=500,height=300',
854                                         {
855                                             'xml' : xml,
856                                             'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.title')
857                                         }
858                                     );
859
860                                     if (fancy_prompt_data.fancy_status == 'incomplete') {
861                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.incomplete'));
862                                         return;
863                                     }
864
865                                     var robj = obj.network.simple_request(
866                                         'FM_ACN_TRANSFER', 
867                                         [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'volumes' : list } ],
868                                         null,
869                                         {
870                                             'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.override.failure'),
871                                             'overridable_events' : [
872                                                 1208 /* TITLE_LAST_COPY */,
873                                                 1219 /* COPY_REMOTE_CIRC_LIB */,
874                                             ],
875                                         }
876                                     );
877
878                                     if (typeof robj.ilsevent != 'undefined') {
879                                         if (robj.ilsevent == 1221 /* ORG_CANNOT_HAVE_VOLS */) {
880                                             alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.ineligible_destination'));
881                                         } else {
882                                             throw(robj);
883                                         }
884                                     } else {
885                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.success'));
886                                     }
887
888                                 } catch(E) {
889                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.unexpected_error'),E);
890                                 }
891                                 obj.refresh_list();
892                             }
893                         ],
894
895                         'cmd_transfer_items' : [
896                             ['command'],
897                             function() {
898                                 try {
899                                     obj.data.stash_retrieve();
900                                     if (!obj.data.marked_volume) {
901                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.missing_volume'));
902                                         return;
903                                     }
904                                     
905                                     JSAN.use('util.functional');
906
907                                     var list = util.functional.filter_list(
908                                         obj.sel_list,
909                                         function (o) {
910                                             return o.split(/_/)[0] == 'acp';
911                                         }
912                                     );
913
914                                     list = util.functional.map_list(
915                                         list,
916                                         function (o) {
917                                             return o.split(/_/)[1];
918                                         }
919                                     );
920
921                                     var volume = obj.network.simple_request('FM_ACN_RETRIEVE.authoritative',[ obj.data.marked_volume ]);
922
923                                     JSAN.use('cat.util'); cat.util.transfer_copies( { 
924                                         'copy_ids' : list, 
925                                         'docid' : volume.record(),
926                                         'volume_label' : volume.label(),
927                                         'owning_lib' : volume.owning_lib(),
928                                     } );
929
930                                 } catch(E) {
931                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.unexpected_error'),E);
932                                 }
933                                 obj.refresh_list();
934                             }
935                         ],
936
937                         'cmd_link_as_multi_bib' : [
938                             ['command'],
939                             function() {
940                                 try {
941                                     obj.data.stash_retrieve();
942                                     if (!obj.data.marked_multi_home_record) {
943                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.link_as_multi_bib.missing_bib'));
944                                         return;
945                                     }
946
947                                     JSAN.use('util.functional');
948
949                                     var list = util.functional.filter_list(
950                                         obj.sel_list,
951                                         function (o) {
952                                             return o.split(/_/)[0] == 'acp';
953                                         }
954                                     );
955
956                                     list = util.functional.map_list(
957                                         list,
958                                         function (o) {
959                                             return obj.map_acp[ o ].barcode();
960                                         }
961                                     );
962
963                                     xulG.new_tab(
964                                         window.xulG.url_prefix(urls.MANAGE_MULTI_HOME_ITEMS),
965                                         {},
966                                         { 'docid' : obj.data.marked_multi_home_record, 'barcodes' : list }
967                                     );
968
969                                 } catch(E) {
970                                     alert('Error in copy_browser.js, cmd_link_as_multi_bib: ' + E);
971                                 }
972                                 obj.refresh_list();
973                             }
974                         ]
975                     }
976                 }
977             );
978
979         } catch(E) {
980             this.error.standard_unexpected_error_alert('cat.copy_browser.controller_init(): ',E);
981         }
982     },
983
984     'depth_menu_init' : function(params) {
985         var obj = this;
986         try {
987             var list = [];
988             var max_depth = 0;
989             for (var i = 0; i < obj.data.list.aout.length; i++) {
990                 var type = obj.data.list.aout[i];
991                 var depth = type.depth();
992                 if ( depth > max_depth) { max_depth = depth; }
993                 if (typeof list[depth] == 'undefined') {
994                     list[depth] = [
995                         type.opac_label(),
996                         type.depth(),
997                         false,
998                         ( type.depth() * 2)
999                     ];
1000                 } else {
1001                     list[depth][0] += ' / ' + type.opac_label();
1002                 }
1003             }
1004             ml = util.widgets.make_menulist( list, max_depth );
1005             ml.setAttribute('id','depth_menu'); document.getElementById('x_depth_menu').appendChild(ml);
1006             ml.addEventListener(
1007                 'command',
1008                 function(ev) {
1009                     obj.default_depth = ev.target.value;
1010                     if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus(); 
1011                     JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
1012                     util.widgets.save_attributes(file, { 
1013                         'lib_menu' : [ 'value' ],
1014                         'depth_menu' : [ 'value' ],
1015                         'show_acns' : [ 'checked' ],
1016                         'show_acps' : [ 'checked' ]
1017                     });
1018                 },
1019                 false
1020             );
1021
1022             file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
1023             util.widgets.load_attributes(file);
1024             ml.value = ml.getAttribute('value');
1025             if (! ml.value) {
1026                 ml.value = max_depth;
1027                 ml.setAttribute('value',ml.value);
1028             }
1029
1030             return ml.value;
1031         } catch(E) {
1032             alert('Error in copy_browser.js, depth_menu_init(): ' + E);
1033         }
1034     },
1035
1036     'library_menu_init' : function(params) {
1037         var obj = this;
1038         try {
1039
1040             obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
1041             if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
1042             JSAN.use('util.functional'); 
1043             obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
1044
1045             var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1046
1047             JSAN.use('util.file'); JSAN.use('util.widgets');
1048
1049             var file; var list_data; var ml; 
1050
1051             file = new util.file('offline_ou_list'); 
1052             if (file._file.exists()) {
1053                 list_data = file.get_object(); file.close();
1054                 for (var i = 0; i < list_data[0].length; i++) { // make sure all entries are enabled
1055                     list_data[0][i][2] = false;
1056                 }
1057                 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
1058                 ml.setAttribute('id','lib_menu'); document.getElementById('x_lib_menu').appendChild(ml);
1059                 for (var i = 0; i < obj.org_ids.length; i++) {
1060                     ml.getElementsByAttribute('value',obj.org_ids[i])[0].setAttribute('class','has_copies');
1061                 }
1062                 ml.firstChild.addEventListener(
1063                     'popupshown',
1064                     function(ev) {
1065                         document.getElementById('legend').setAttribute('hidden','false');
1066                     },
1067                     false
1068                 );
1069                 ml.firstChild.addEventListener(
1070                     'popuphidden',
1071                     function(ev) {
1072                         document.getElementById('legend').setAttribute('hidden','true');
1073                     },
1074                     false
1075                 );
1076                 ml.addEventListener(
1077                     'command',
1078                     function(ev) {
1079                         obj.default_lib = obj.data.hash.aou[ ev.target.value ];
1080                         if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus(); 
1081                         JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
1082                         util.widgets.save_attributes(file, { 
1083                             'lib_menu' : [ 'value' ],
1084                             'depth_menu' : [ 'value' ],
1085                             'show_acns' : [ 'checked' ],
1086                             'show_acps' : [ 'checked' ]
1087                         });
1088                         obj.refresh_list();
1089                     },
1090                     false
1091                 );
1092             } else {
1093                 throw(document.getElementById('catStrings').getString('staff.cat.copy_browser.missing_library') + '\n');
1094             }
1095
1096             file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
1097             util.widgets.load_attributes(file);
1098             ml.value = ml.getAttribute('value');
1099             if (! ml.value) {
1100                 ml.value = org.id();
1101                 ml.setAttribute('value',ml.value);
1102             }
1103
1104             return ml.value;
1105
1106         } catch(E) {
1107             this.error.standard_unexpected_error_alert('cat.copy_browser.library_menu_init(): ',E);
1108         }
1109     },
1110
1111     'show_consortial_count' : function() {
1112         var obj = this;
1113         try {
1114             obj.network.simple_request('FM_ACP_COUNT.authoritative',[ obj.data.tree.aou.id(), obj.docid ],function(req){ 
1115                 try {
1116                     var robj = req.getResultObject();
1117                     var x = document.getElementById('consortial_total');
1118                     if (x) x.setAttribute('value',robj[0].count);
1119                     x = document.getElementById('consortial_available');
1120                     if (x) x.setAttribute('value',robj[0].available);
1121                 } catch(E) {
1122                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.consortial_copy_count.error'),E);
1123                 }
1124             });
1125         } catch(E) {
1126             this.error.standard_unexpected_error_alert('cat.copy_browser.show_consortial_count: ',E);
1127         }
1128     },
1129
1130     'show_my_libs' : function(org) {
1131         var obj = this;
1132         try {
1133             if (!org) {
1134                 org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1135             } else {
1136                 if (typeof org != 'object') org = obj.data.hash.aou[ org ];
1137             }
1138             obj.show_libs( org, false );
1139 /*        
1140             var p_org = obj.data.hash.aou[ org.parent_ou() ];
1141             if (p_org) {
1142                 obj.funcs.push( function() { 
1143                     document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1144                     document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1145                     document.getElementById('lib_menu').setAttribute('disabled','true'); 
1146                 } );
1147                 for (var i = 0; i < p_org.children().length; i++) {
1148                     obj.funcs.push(
1149                         function(o) {
1150                             return function() {
1151                                 obj.show_libs( o, false );
1152                             }
1153                         }( p_org.children()[i] )
1154                     );
1155                 }
1156                 obj.funcs.push( function() { 
1157                     document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1158                     document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1159                     document.getElementById('lib_menu').setAttribute('disabled','false'); 
1160                 } );
1161             }
1162 */
1163         } catch(E) {
1164             alert(E);
1165         }
1166     },
1167
1168     'show_all_libs' : function() {
1169         var obj = this;
1170         try {
1171             obj.show_my_libs();
1172
1173             obj.show_libs( obj.data.tree.aou );
1174
1175             obj.funcs.push( function() { 
1176                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1177                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1178                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1179             } );
1180
1181             for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
1182                 var child = obj.data.tree.aou.children()[i];
1183                 if (obj.data.hash.aout[child.ou_type()].depth() <= obj.default_depth
1184                 && orgIsMine(obj.default_lib,child,obj.default_depth)) {
1185                     obj.funcs.push(
1186                         function(o) {
1187                             return function() {
1188                                 obj.show_libs( o );
1189                             }
1190                         }( child )
1191                     );
1192                 }
1193             }
1194             obj.funcs.push( function() { 
1195                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1196                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1197                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1198             } );
1199
1200         } catch(E) {
1201             alert(E);
1202         }
1203     },
1204
1205     'show_libs_with_copies' : function() {
1206         var obj = this;
1207         try {
1208             JSAN.use('util.functional');
1209
1210             var orgs = util.functional.map_list(
1211                 obj.org_ids,
1212                 function(id) { return obj.data.hash.aou[id]; }
1213             ).sort(
1214                 function( a, b ) {
1215                     if (a.shortname() < b.shortname()) return -1;
1216                     if (a.shortname() > b.shortname()) return 1;
1217                     return 0;
1218                 }
1219             );
1220             obj.funcs.push( function() { 
1221                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1222                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1223                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1224             } );
1225
1226             for (var i = 0; i < orgs.length; i++) {
1227                 obj.funcs.push(
1228                     function(o) {
1229                         return function() {
1230                             obj.show_libs(o,false);
1231                         }
1232                     }( orgs[i] )
1233                 );
1234             }
1235             obj.funcs.push( function() { 
1236                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1237                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1238                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1239             } );
1240
1241         } catch(E) {
1242             alert(E);
1243         }
1244     },
1245
1246     'show_libs' : function(start_aou,show_open) {
1247         var obj = this;
1248         try {
1249             if (!start_aou) throw('show_libs: Need a start_aou');
1250             JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1251             JSAN.use('util.functional'); 
1252
1253             var parents = [];
1254             var temp_aou = start_aou;
1255             while ( temp_aou.parent_ou() ) {
1256                 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
1257                 parents.push( temp_aou );
1258             }
1259             parents.reverse();
1260
1261             for (var i = 0; i < parents.length; i++) {
1262                 obj.funcs.push(
1263                     function(o,p) {
1264                         return function() { 
1265                             obj.append_org(o,p,{'container':'true','open':'true'}); 
1266                         };
1267                     }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
1268                 );
1269             }
1270
1271             obj.funcs.push(
1272                 function(o,p) {
1273                     return function() { obj.append_org(o,p); };
1274                 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
1275             );
1276
1277             obj.funcs.push(
1278                 function() {
1279                     if (start_aou.children()) {
1280                         var x = obj.map_tree[ 'aou_' + start_aou.id() ];
1281                         x.setAttribute('container','true');
1282                         if (show_open) x.setAttribute('open','true');
1283                         for (var i = 0; i < start_aou.children().length; i++) {
1284                             var child = start_aou.children()[i];
1285                             if (obj.data.hash.aout[child.ou_type()].depth() <= obj.default_depth
1286                             && orgIsMine(obj.default_lib,child,obj.default_depth)) {
1287                                 obj.funcs.push(
1288                                     function(o,p) {
1289                                         return function() { obj.append_org(o,p); };
1290                                     }( child, start_aou )
1291                                 );
1292                             }
1293                         }
1294                     }
1295                 }
1296             );
1297
1298         } catch(E) {
1299             alert(E);
1300         }
1301     },
1302
1303     'on_select' : function(list,twisty) {
1304         var obj = this;
1305         for (var i = 0; i < list.length; i++) {
1306             var node = obj.map_tree[ list[i] ];
1307             //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
1308             var row_type = list[i].split('_')[0];
1309             var id = list[i].split('_')[1];
1310             switch(row_type) {
1311                 case 'aou' : obj.on_select_org(id,twisty); break;
1312                 case 'acn' : obj.on_select_acn(id,twisty); break;
1313                 default: break;
1314             }
1315         }
1316     },
1317
1318     'on_select_acn' : function(acn_id,twisty) {
1319         var obj = this;
1320         try {
1321             var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
1322             obj.funcs.push( function() { 
1323                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1324                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1325                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1326             } );
1327             if (acn_tree.copies()) {
1328                 for (var i = 0; i < acn_tree.copies().length; i++) {
1329                     obj.funcs.push(
1330                         function(c,a) {
1331                             return function() {
1332                                 obj.append_acp(c,a);
1333                             }
1334                         }( acn_tree.copies()[i], acn_tree )
1335                     )
1336                 }
1337             }
1338             obj.funcs.push( function() { 
1339                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1340                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1341                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1342             } );
1343         } catch(E) {
1344             alert(E);
1345         }
1346     },
1347
1348     'on_select_org' : function(org_id,twisty) {
1349         var obj = this;
1350         try {
1351             var org = obj.data.hash.aou[ org_id ];
1352             obj.funcs.push( function() { 
1353                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1354                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1355                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1356             } );
1357             if (org.children()) {
1358                 for (var i = 0; i < org.children().length; i++) {
1359                     var child = org.children()[i];
1360                     if (obj.data.hash.aout[child.ou_type()].depth() <= obj.default_depth
1361                     && orgIsMine(obj.default_lib,child,obj.default_depth)) {
1362                         obj.funcs.push(
1363                             function(o,p) {
1364                                 return function() {
1365                                     obj.append_org(o,p)
1366                                 }
1367                             }(child,org)
1368                         );
1369                     }
1370                 }
1371             } 
1372             if (obj.map_acn[ 'aou_' + org_id ]) {
1373                 for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
1374                     obj.funcs.push(
1375                         function(o,a) {
1376                             return function() {
1377                                 obj.append_acn(o,a);
1378                             }
1379                         }( org, obj.map_acn[ 'aou_' + org_id ][i] )
1380                     );
1381                 }
1382             }
1383             obj.funcs.push( function() { 
1384                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1385                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1386                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1387             } );
1388         } catch(E) {
1389             alert('Error in copy_browser.js, on_select_org(): ' + E);
1390         }
1391     },
1392
1393     'append_org' : function (org,parent_org,params) {
1394         var obj = this;
1395         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1396         obj.error.consoleService.logStringMessage('append_org: org = ' + org.shortname() + ' parent_org = ' + (parent_org ? parent_org.shortname() : '') + ' params = ' + js2JSON(params) + '\n');
1397         try {
1398             if (obj.map_tree[ 'aou_' + org.id() ]) {
1399                 var x = obj.map_tree[ 'aou_' + org.id() ];
1400                 if (params) {
1401                     for (var i in params) {
1402                         x.setAttribute(i,params[i]);
1403                     }
1404                 }
1405                 return x;
1406             }
1407
1408             var data = {
1409                 'row' : {
1410                     'my' : {
1411                         'aou' : org,
1412                     }
1413                 },
1414                 'skip_all_columns_except' : [0,1,2],
1415                 'retrieve_id' : 'aou_' + org.id(),
1416                 'to_bottom' : true,
1417                 'no_auto_select' : true,
1418             };
1419         
1420             var acn_tree_list;
1421             if ( obj.org_ids.indexOf( Number( org.id() ) ) == -1 ) {
1422                 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) {
1423                     data.row.my.volume_count = '0';
1424                     data.row.my.copy_count = '<0>';
1425                 } else {
1426                     data.row.my.volume_count = '';
1427                     data.row.my.copy_count = '';
1428                 }
1429             } else {
1430                 var v_count = 0; var c_count = 0;
1431                 acn_tree_list = obj.network.simple_request(
1432                     'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS.authoritative',
1433                     [ ses(), obj.docid, [ org.id() ] ]
1434                 );
1435                 for (var i = 0; i < acn_tree_list.length; i++) {
1436                     v_count++;
1437                     obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
1438                     var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
1439                     for (var j = 0; j < copies.length; j++) {
1440                         obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
1441                     }
1442                 }
1443                 data.row.my.volume_count = v_count;
1444                 data.row.my.copy_count = '<' + c_count + '>';
1445             }
1446             if (parent_org) {
1447                 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1448             }
1449             var nparams = obj.list.append(data);
1450             var node = nparams.my_node;
1451             if (params) {
1452                 for (var i in params) {
1453                     node.setAttribute(i,params[i]);
1454                 }
1455             }
1456             obj.map_tree[ 'aou_' + org.id() ] = node;
1457
1458             if (org.children()) {
1459                 node.setAttribute('container','true');
1460             }
1461
1462             if (parent_org) {
1463                 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1464                     data.node.setAttribute('open','true');
1465                 }
1466             } else {
1467                 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1468             }
1469
1470             if (acn_tree_list) {
1471                 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
1472                 node.setAttribute('container','true');
1473             }
1474
1475             if (document.getElementById('show_acns').checked) {
1476                 node.setAttribute('open','true');
1477                 obj.funcs.push( function() { obj.on_select_org( org.id() ); } );
1478             }
1479
1480         } catch(E) {
1481             dump(E+'\n');
1482             alert(E);
1483         }
1484     },
1485
1486     'append_acn' : function( org, acn_tree, params ) {
1487         var obj = this;
1488         try {
1489             if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
1490                 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
1491                 if (params) {
1492                     for (var i in params) {
1493                         x.setAttribute(i,params[i]);
1494                     }
1495                 }
1496                 return x;
1497             }
1498
1499             var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1500             var data = {
1501                 'row' : {
1502                     'my' : {
1503                         'aou' : org,
1504                         'acn' : acn_tree,
1505                         'volume_count' : '',
1506                         'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
1507                     }
1508                 },
1509                 'skip_all_columns_except' : [0,1,2],
1510                 'retrieve_id' : 'acn_' + acn_tree.id(),
1511                 'node' : parent_node,
1512                 'to_bottom' : true,
1513                 'no_auto_select' : true,
1514             };
1515             var nparams = obj.list.append(data);
1516             var node = nparams.my_node;
1517             obj.map_tree[ 'acn_' + acn_tree.id() ] =  node;
1518             if (params) {
1519                 for (var i in params) {
1520                     node.setAttribute(i,params[i]);
1521                 }
1522             }
1523             if (acn_tree.copies()) {
1524                 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
1525                 node.setAttribute('container','true');
1526             }
1527             if (document.getElementById('show_acps').checked) {
1528                 node.setAttribute('open','true');
1529                 obj.funcs.push( function() { obj.on_select_acn( acn_tree.id() ); } );
1530             }
1531
1532         } catch(E) {
1533             dump(E+'\n');
1534             alert(E);
1535         }
1536     },
1537
1538     'append_acp' : function( acp_item, acn_tree, params ) {
1539         var obj = this;
1540         try {
1541             if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
1542                 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
1543                 if (params) {
1544                     for (var i in params) {
1545                         x.setAttribute(i,params[i]);
1546                     }
1547                 }
1548                 return x;
1549             }
1550
1551             var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
1552             var data = {
1553                 'row' : {
1554                     'my' : {
1555                         'doc_id' : obj.docid,
1556                         'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
1557                         'acn' : acn_tree,
1558                         'acp' : acp_item,
1559                         'circ' :
1560                             acp_item.circulations() 
1561                             ? (
1562                                 acp_item.circulations().length > 0
1563                                 ? acp_item.circulations()[0]
1564                                 : null
1565                             ) 
1566                             : null,
1567                         'volume_count' : '',
1568                         'copy_count' : '',
1569                     }
1570                 },
1571                 'retrieve_id' : 'acp_' + acp_item.id(),
1572                 'node' : parent_node,
1573                 'to_bottom' : true,
1574                 'no_auto_select' : true,
1575             };
1576             var nparams = obj.list.append(data);
1577             var node = nparams.my_node;
1578             obj.map_tree[ 'acp_' + acp_item.id() ] =  node;
1579             if (params) {
1580                 for (var i in params) {
1581                     node.setAttribute(i,params[i]);
1582                 }
1583             }
1584
1585         } catch(E) {
1586             dump(E+'\n');
1587             alert(E);
1588         }
1589     },
1590
1591     'list_init' : function( params ) {
1592
1593         try {
1594             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1595             var obj = this;
1596             
1597             JSAN.use('circ.util');
1598             var columns = [
1599                 {
1600                     'id' : 'tree_location',
1601                     'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.tree_location'),
1602                     'flex' : 1, 'primary' : true, 'hidden' : false, 
1603                     'render' : function(my) { return my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"; },
1604                 },
1605                 {
1606                     'id' : 'volume_count',
1607                     'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.volume_count'),
1608                     'flex' : 0, 'primary' : false, 'hidden' : false, 
1609                     'render' : function(my) { return my.volume_count; },
1610                 },
1611                 {
1612                     'id' : 'copy_count',
1613                     'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.copy_count'),
1614                     'flex' : 0,
1615                     'primary' : false, 'hidden' : false, 
1616                     'render' : function(my) { return my.copy_count; },
1617                 },
1618             ].concat(
1619                 circ.util.columns( 
1620                     { 
1621                         'location' : { 'hidden' : false },
1622                         'circ_lib' : { 'hidden' : false },
1623                         'owning_lib' : { 'hidden' : false },
1624                         'call_number' : { 'hidden' : false },
1625                         'parts' : { 'hidden' : false },
1626                         'due_date' : { 'hidden' : false },
1627                         'acp_status' : { 'hidden' : false },
1628                     },
1629                     {
1630                         'just_these' : [
1631                             'due_date',
1632                             'owning_lib',
1633                             'circ_lib',
1634                             'label_class',
1635                             'prefix',
1636                             'call_number',
1637                             'suffix',
1638                             'copy_number',
1639                             'parts',
1640                             'location',
1641                             'barcode',
1642                             'loan_duration',
1643                             'fine_level',
1644                             'circulate',
1645                             'holdable',
1646                             'opac_visible',
1647                             'ref',
1648                             'deposit',
1649                             'deposit_amount',
1650                             'price',
1651                             'circ_as_type',
1652                             'circ_modifier',
1653                             'acp_status',
1654                             'alert_message',
1655                             'acp_mint_condition',
1656                             'acp_id'
1657                         ]
1658                     }
1659                 )
1660             );
1661             JSAN.use('util.list'); obj.list = new util.list('copy_tree');
1662             obj.list.init(
1663                 {
1664                     'no_auto_select' : true,
1665                     'columns' : columns,
1666                     'map_row_to_columns' : circ.util.std_map_row_to_columns(' '),
1667                     'retrieve_row' : function(params) {
1668
1669                         var row = params.row;
1670
1671                     /*    
1672                         if (!row.my.mvr) obj.funcs.push(
1673                             function() {
1674
1675                                 row.my.mvr = obj.network.request(
1676                                     api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
1677                                     api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
1678                                     [ row.my.circ.target_copy() ]
1679                                 );
1680
1681                             }
1682                         );
1683                         if (!row.my.acp) {
1684                             obj.funcs.push(    
1685                                 function() {
1686
1687                                     row.my.acp = obj.network.request(
1688                                         api.FM_ACP_RETRIEVE.app,
1689                                         api.FM_ACP_RETRIEVE.method,
1690                                         [ row.my.circ.target_copy() ]
1691                                     );
1692
1693                                     params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1694
1695                                 }
1696                             );
1697                         } else {
1698                             params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1699                         }
1700                     */
1701                         obj.funcs.push(
1702                             function() {
1703
1704                                 if (typeof params.on_retrieve == 'function') {
1705                                     params.on_retrieve(row);
1706                                 }
1707
1708                             }
1709                         );
1710
1711                         return row;
1712                     },
1713                     'on_click' : function(ev) {
1714                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1715                         var row = {}; var col = {}; var nobj = {};
1716                         obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj); 
1717                         if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
1718                         var node = obj.list.node.contentView.getItemAtIndex(row.value);
1719                         var list = [ node.getAttribute('retrieve_id') ];
1720                         if (typeof obj.on_select == 'function') {
1721                             obj.on_select(list,true);
1722                         }
1723                         if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1724                             window.xulG.on_select(list);
1725                         }
1726                     },
1727                     'on_select' : function(ev) {
1728                         JSAN.use('util.functional');
1729                         var sel = obj.list.retrieve_selection();
1730                         obj.controller.view.sel_clip.disabled = sel.length < 1;
1731                         obj.sel_list = util.functional.map_list(
1732                             sel,
1733                             function(o) { return o.getAttribute('retrieve_id'); }
1734                         );
1735                         obj.toggle_actions();
1736                         if (typeof obj.on_select == 'function') {
1737                             obj.on_select(obj.sel_list);
1738                         }
1739                         if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1740                             window.xulG.on_select(obj.sel_list);
1741                         }
1742                     },
1743                 }
1744             );
1745
1746         } catch(E) {
1747             this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
1748             alert(E);
1749         }
1750     },
1751
1752     'toggle_actions' : function() {
1753         var obj = this;
1754         try {
1755             var found_aou = false; var found_acn = false; var found_acp = false;
1756             var found_aou_with_can_have_vols = false;
1757             var sel_copy_libs = {};
1758             for (var i = 0; i < obj.sel_list.length; i++) {
1759                 var type = obj.sel_list[i].split(/_/)[0];
1760                 switch(type) {
1761                     case 'aou' : 
1762                         found_aou = true; 
1763                         var org = obj.data.hash.aou[ obj.sel_list[i].split(/_/)[1] ];
1764                         if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) found_aou_with_can_have_vols = true;
1765                     break;
1766                     case 'acn' : found_acn = true; break;
1767                     case 'acp' :
1768                         found_acp = true;
1769                         sel_copy_libs[
1770                             obj.map_acn[
1771                                 "acn_" +
1772                                 obj.map_acp[obj.sel_list[i]].call_number()
1773                             ].owning_lib()
1774                         ] = true;
1775                         break;
1776                 }
1777             }
1778             obj.controller.view.cmd_add_items.setAttribute('disabled','true');
1779             obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','true');
1780             obj.controller.view.cmd_edit_items.setAttribute('disabled','true');
1781             obj.controller.view.cmd_replace_barcode.setAttribute('disabled','true');
1782             obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
1783             obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','true');
1784             obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
1785             obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1786             obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
1787             obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
1788             obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
1789             obj.controller.view.cmd_transfer_volume.setAttribute('disabled','true');
1790             obj.controller.view.cmd_transfer_items.setAttribute('disabled','true');
1791             obj.controller.view.sel_copy_details.setAttribute('disabled','true');
1792             obj.controller.view.cmd_create_brt.setAttribute('disabled','true');
1793             obj.controller.view.cmd_book_item_now.setAttribute('disabled','true');
1794             obj.controller.view.sel_patron.setAttribute('disabled','true');
1795             obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
1796             obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
1797             if (found_aou && found_aou_with_can_have_vols) {
1798                 obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
1799                 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1800             }
1801             if (found_acn) {
1802                 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
1803                 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
1804                 obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
1805                 obj.controller.view.cmd_add_items.setAttribute('disabled','false');
1806                 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','false');
1807             }
1808             if (found_acp) {
1809                 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
1810                 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
1811                 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','false');
1812                 obj.controller.view.cmd_edit_items.setAttribute('disabled','false');
1813                 obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
1814                 obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
1815                 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','false');
1816                 obj.controller.view.cmd_transfer_items.setAttribute('disabled','false');
1817                 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
1818                 obj.controller.view.cmd_create_brt.setAttribute('disabled','false');
1819                 obj.controller.view.sel_patron.setAttribute('disabled','false');
1820
1821                 var L = 0; for (var k in sel_copy_libs) L++;
1822                 if (L < 2) {
1823                     obj.controller.view.cmd_book_item_now.setAttribute('disabled','false');
1824                 }
1825             }
1826         } catch(E) {
1827             obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.actions.error'),E);
1828         }
1829     },
1830
1831     'refresh_list' : function() { 
1832         try {
1833             var obj = this;
1834             obj.list.clear();
1835             obj.map_tree = {};
1836             obj.map_acn = {};
1837             obj.map_acp = {};
1838             obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
1839             if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
1840             JSAN.use('util.functional'); 
1841             obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
1842             obj.show_my_libs( obj.default_lib.id() );
1843             // FIXME - we get a null from the copy_count call if we call it too quickly here
1844             setTimeout( function() { obj.show_consortial_count(); }, 2000 );
1845         } catch(E) {
1846             this.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.refresh_list.error'),E);
1847         }
1848     },
1849 }
1850
1851 dump('exiting cat.copy_browser.js\n');