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