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