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