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