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