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