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