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