]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_browser.js
due dates in various item lists
[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                                                                 } catch(E) {
209                                                                         obj.error.standard_unexpected_error_alert('copy browser -> add copies',E);
210                                                                 }
211                                                         }
212                                                 ],
213                                                 'cmd_add_items_to_buckets' : [
214                                                         ['command'],
215                                                         function() {
216                                                                 try {
217                                                                         JSAN.use('util.functional');
218
219                                                                         var list = util.functional.filter_list(
220                                                                                 obj.sel_list,
221                                                                                 function (o) {
222                                                                                         return o.split(/_/)[0] == 'acp';
223                                                                                 }
224                                                                         );
225
226                                                                         list = util.functional.map_list(
227                                                                                 list,
228                                                                                 function (o) {
229                                                                                         return o.split(/_/)[1];
230                                                                                 }
231                                                                         );
232                                                                 
233                                                                         JSAN.use('cat.util');
234                                                                         cat.util.add_copies_to_bucket( list );
235
236                                                                 } catch(E) {
237                                                                         obj.error.standard_unexpected_error_alert('copy browser -> add copies to bucket',E);
238                                                                 }
239                                                         }
240                                                 ],
241                                                 'cmd_edit_items' : [
242                                                         ['command'],
243                                                         function() {
244                                                                 try {
245                                                                         JSAN.use('util.functional');
246
247                                                                         var list = util.functional.filter_list(
248                                                                                 obj.sel_list,
249                                                                                 function (o) {
250                                                                                         return o.split(/_/)[0] == 'acp';
251                                                                                 }
252                                                                         );
253
254                                                                         list = util.functional.map_list(
255                                                                                 list,
256                                                                                 function (o) {
257                                                                                         return o.split(/_/)[1];
258                                                                                 }
259                                                                         );
260
261                                                                         var edit = 0;
262                                                                         try {
263                                                                                 edit = obj.network.request(
264                                                                                         api.PERM_MULTI_ORG_CHECK.app,
265                                                                                         api.PERM_MULTI_ORG_CHECK.method,
266                                                                                         [ 
267                                                                                                 ses(), 
268                                                                                                 obj.data.list.au[0].id(), 
269                                                                                                 util.functional.map_list(
270                                                                                                         list,
271                                                                                                         function (o) {
272                                                                                                                 return obj.map_acn[ 'acn_' + obj.map_acp[ 'acp_' + o ].call_number() ].owning_lib();
273                                                                                                         }
274                                                                                                 ),
275                                                                                                 [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
276                                                                                         ]
277                                                                                 ).length == 0 ? 1 : 0;
278                                                                         } catch(E) {
279                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
280                                                                         }
281
282                                                                         JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
283
284                                                                 } catch(E) {
285                                                                         obj.error.standard_unexpected_error_alert('Copy Browser -> Edit Items',E);
286                                                                 }
287                                                         }
288                                                 ],
289                                                 'cmd_delete_items' : [
290                                                         ['command'],
291                                                         function() {
292                                                                 try {
293                                                                         JSAN.use('util.functional');
294
295                                                                         var list = util.functional.filter_list(
296                                                                                 obj.sel_list,
297                                                                                 function (o) {
298                                                                                         return o.split(/_/)[0] == 'acp';
299                                                                                 }
300                                                                         );
301
302                                                                         list = util.functional.map_list(
303                                                                                 list,
304                                                                                 function (o) {
305                                                                                         return JSON2js( js2JSON( obj.map_acp[ 'acp_' + o.split(/_/)[1] ] ) );
306                                                                                 }
307                                                                         );
308
309                                                                         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');
310
311                                                                         if (r == 0) {
312                                                                                 var acn_hash = {}; var acn_list = [];
313                                                                                 for (var i = 0; i < list.length; i++) {
314                                                                                         list[i].isdeleted('1');
315                                                                                         var acn_id = list[i].call_number();
316                                                                                         if ( ! acn_hash[ acn_id ] ) {
317                                                                                                 acn_hash[ acn_id ] = obj.map_acn[ 'acn_' + acn_id ];
318                                                                                                 acn_hash[ acn_id ].copies( [] );
319                                                                                         }
320                                                                                         var temp = acn_hash[ acn_id ].copies();
321                                                                                         temp.push( list[i] );
322                                                                                         acn_hash[ acn_id ].copies( temp );
323                                                                                 }
324                                                                                 for (var i in acn_hash) acn_list.push( acn_hash[i] );
325                                                                                 var robj = obj.network.simple_request(
326                                                                                         'FM_ACN_TREE_UPDATE', 
327                                                                                         [ ses(), acn_list, true ],
328                                                                                         null,
329                                                                                         {
330                                                                                                 'title' : 'Override Delete Failure?',
331                                                                                                 'overridable_events' : [
332                                                                                                         1208 /* TITLE_LAST_COPY */
333                                                                                                 ]
334                                                                                         }
335                                                                                 );
336                                                                                 if (robj == null) throw(robj);
337                                                                                 if (typeof robj.ilsevent != 'undefined') {
338                                                                                         if ( (robj.ilsevent != 0) && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */) ) throw(robj);
339                                                                                 }
340                                                                                 obj.refresh_list();
341                                                                         }
342
343                                                                         
344                                                                 } catch(E) {
345                                                                         obj.error.standard_unexpected_error_alert('copy browser -> delete items',E);
346                                                                         obj.refresh_list();
347                                                                 }
348                                                         }
349                                                 ],
350                                                 'cmd_print_spine_labels' : [
351                                                         ['command'],
352                                                         function() {
353                                                                 try {
354                                                                         JSAN.use('util.functional');
355                                                                         
356                                                                         var list = util.functional.filter_list(
357                                                                                 obj.sel_list,
358                                                                                 function (o) {
359                                                                                         return o.split(/_/)[0] == 'acp';
360                                                                                 }
361                                                                         );
362
363                                                                         list = util.functional.map_list(
364                                                                                 list,
365                                                                                 function (o) {
366                                                                                         return obj.map_acp[ o ];
367                                                                                 }
368                                                                         );
369
370                                                                         obj.data.temp_barcodes_for_labels = util.functional.map_list( list, function(o){return o.barcode();}) ; 
371                                                                         obj.data.stash('temp_barcodes_for_labels');
372                                                                         xulG.new_tab(
373                                                                                 xulG.url_prefix( urls.XUL_SPINE_LABEL ),
374                                                                                 { 'tab_name' : 'Spine Labels' },
375                                                                                 {}
376                                                                         );
377                                                                 } catch(E) {
378                                                                         obj.error.standard_unexpected_error_alert('copy browser -> Spine Labels',E);
379                                                                 }
380                                                         }
381                                                 ],
382                                                 'cmd_add_volumes' : [
383                                                         ['command'],
384                                                         function() {
385                                                                 try {
386                                                                         JSAN.use('util.functional');
387                                                                         var list = util.functional.filter_list(
388                                                                                 obj.sel_list,
389                                                                                 function (o) {
390                                                                                         return o.split(/_/)[0] == 'aou';
391                                                                                 }
392                                                                         );
393                                                                         list = util.functional.map_list(
394                                                                                 list,
395                                                                                 function (o) {
396                                                                                         return o.split(/_/)[1];
397                                                                                 }
398                                                                         );              
399                                                                         var edit = 0;
400                                                                         try {
401                                                                                 edit = obj.network.request(
402                                                                                         api.PERM_MULTI_ORG_CHECK.app,
403                                                                                         api.PERM_MULTI_ORG_CHECK.method,
404                                                                                         [ 
405                                                                                                 ses(), 
406                                                                                                 obj.data.list.au[0].id(), 
407                                                                                                 list,
408                                                                                                 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
409                                                                                         ]
410                                                                                 ).length == 0 ? 1 : 0;
411                                                                         } catch(E) {
412                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
413                                                                         }
414
415                                                                         if (edit==0) {
416                                                                                 alert("You don't have permission to add volumes to that library.");
417                                                                                 return; // no read-only view for this interface
418                                                                         }
419
420                                                                         var title = 'Add Volume/Item';
421
422                                                                         JSAN.use('util.window'); var win = new util.window();
423                                                                         var w = win.open(
424                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
425                                                                                         +'?doc_id=' + window.escape(obj.docid)
426                                                                                         +'&ou_ids=' + window.escape( js2JSON(list) ),
427                                                                                 title,
428                                                                                 'chrome,resizable'
429                                                                         );
430
431                                                                         w.refresh = function() { obj.refresh_list() };
432                                                                 } catch(E) {
433                                                                         obj.error.standard_unexpected_error_alert('copy browser -> add volumes',E);
434                                                                 }
435                                                         }
436                                                 ],
437                                                 'cmd_edit_volumes' : [
438                                                         ['command'],
439                                                         function() {
440                                                                 try {
441                                                                         JSAN.use('util.functional');
442                                                                         var list = util.functional.map_list(
443                                                                                 util.functional.filter_list(
444                                                                                         obj.sel_list,
445                                                                                         function (o) {
446                                                                                                 return o.split(/_/)[0] == 'acn';
447                                                                                         }
448                                                                                 ),
449                                                                                 function (o) {
450                                                                                         return o.split(/_/)[1];
451                                                                                 }
452                                                                         );
453                                                                         if (list.length == 0) return;
454
455                                                                         var edit = 0;
456                                                                         try {
457                                                                                 edit = obj.network.request(
458                                                                                         api.PERM_MULTI_ORG_CHECK.app,
459                                                                                         api.PERM_MULTI_ORG_CHECK.method,
460                                                                                         [ 
461                                                                                                 ses(), 
462                                                                                                 obj.data.list.au[0].id(), 
463                                                                                                 util.functional.map_list(
464                                                                                                         list,
465                                                                                                         function (o) {
466                                                                                                                 return obj.map_acn[ 'acn_' + o ].owning_lib();
467                                                                                                         }
468                                                                                                 ),
469                                                                                                 [ 'UPDATE_VOLUME' ]
470                                                                                         ]
471                                                                                 ).length == 0 ? 1 : 0;
472                                                                         } catch(E) {
473                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
474                                                                         }
475
476                                                                         if (edit==0) {
477                                                                                 alert("You don't have permission to edit this volume.");
478                                                                                 return; // no read-only view for this interface
479                                                                         }
480
481                                                                         list = util.functional.map_list(
482                                                                                 list,
483                                                                                 function (o) {
484                                                                                         var my_acn = obj.map_acn['acn_' + o];
485                                                                                         return function(r){return r;}(my_acn);
486                                                                                 }
487                                                                         );
488
489                                                                         var title = list.length == 1 ? 'Volume' : 'Volumes';
490
491                                                                         JSAN.use('util.window'); var win = new util.window();
492                                                                         obj.data.volumes_temp = js2JSON( list );
493                                                                         obj.data.stash('volumes_temp');
494                                                                         var w = win.open(
495                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
496                                                                                 title,
497                                                                                 'chrome,modal,resizable'
498                                                                         );
499
500                                                                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
501                                                                         obj.data.stash_retrieve();
502                                                                         var volumes = JSON2js( obj.data.volumes_temp );
503                                                                         obj.error.sdump('D_CAT','in browse, obj.data.temp =\n' + obj.data.temp);
504                                                                         if (volumes=='') return;
505                                                                 
506                                                                         volumes = util.functional.filter_list(
507                                                                                 volumes,
508                                                                                 function (o) {
509                                                                                         return o.ischanged() == '1';
510                                                                                 }
511                                                                         );
512
513                                                                         volumes = util.functional.map_list(
514                                                                                 volumes,
515                                                                                 function (o) {
516                                                                                         o.record( obj.docid ); // staff client 2 did not do this.  Does it matter?
517                                                                                         return o;
518                                                                                 }
519                                                                         );
520
521                                                                         if (volumes.length == 0) return;
522
523                                                                         try {
524                                                                                 var r = obj.network.request(
525                                                                                         api.FM_ACN_TREE_UPDATE.app,
526                                                                                         api.FM_ACN_TREE_UPDATE.method,
527                                                                                         [ ses(), volumes, true ]
528                                                                                 );
529                                                                                 if (typeof r.ilsevent != 'undefined') throw(r);
530                                                                         } catch(E) {
531                                                                                 obj.error.standard_unexpected_error_alert('volume update error: ',E);
532                                                                         }
533                                                                         obj.refresh_list();
534
535                                                                 } catch(E) {
536                                                                         obj.error.standard_unexpected_error_alert('Copy Browser -> Volume Edit',E);
537                                                                 }
538                                                         }
539                                                 ],
540                                                 'cmd_delete_volumes' : [
541                                                         ['command'],
542                                                         function() {
543                                                                 try {
544                                                                         JSAN.use('util.functional');
545
546                                                                         var list = util.functional.filter_list(
547                                                                                 obj.sel_list,
548                                                                                 function (o) {
549                                                                                         return o.split(/_/)[0] == 'acn';
550                                                                                 }
551                                                                         );
552
553                                                                         list = util.functional.map_list(
554                                                                                 list,
555                                                                                 function (o) {
556                                                                                         return JSON2js( js2JSON( obj.map_acn[ 'acn_' + o.split(/_/)[1] ] ) );
557                                                                                 }
558                                                                         );
559
560                                                                         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');
561
562                                                                         if (r == 0) {
563                                                                                 for (var i = 0; i < list.length; i++) {
564                                                                                         list[i].isdeleted('1');
565                                                                                 }
566                                                                                 var robj = obj.network.simple_request(
567                                                                                         'FM_ACN_TREE_UPDATE', 
568                                                                                         [ ses(), list, true ],
569                                                                                         null,
570                                                                                         {
571                                                                                                 'title' : 'Override Delete Failure?',
572                                                                                                 'overridable_events' : [
573                                                                                                 ]
574                                                                                         }
575                                                                                 );
576                                                                                 if (robj == null) throw(robj);
577                                                                                 if (typeof robj.ilsevent != 'undefined') {
578                                                                                         if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
579                                                                                                 alert('You must delete all the copies on the volume before you may delete the volume itself.');
580                                                                                                 return;
581                                                                                         }
582                                                                                         if (robj.ilsevent != 0) throw(robj);
583                                                                                 }
584                                                                                 obj.refresh_list();
585                                                                         }
586                                                                 } catch(E) {
587                                                                         obj.error.standard_unexpected_error_alert('copy browser -> delete volumes',E);
588                                                                         obj.refresh_list();
589                                                                 }
590
591                                                         }
592                                                 ],
593                                                 'cmd_mark_library' : [
594                                                         ['command'],
595                                                         function() {
596                                                                 try {
597                                                                         var list = util.functional.filter_list(
598                                                                                 obj.sel_list,
599                                                                                 function (o) {
600                                                                                         return o.split(/_/)[0] == 'aou';
601                                                                                 }
602                                                                         );
603
604                                                                         list = util.functional.map_list(
605                                                                                 list,
606                                                                                 function (o) {
607                                                                                         return o.split(/_/)[1];
608                                                                                 }
609                                                                         );
610
611                                                                         if (list.length == 1) {
612                                                                                 obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid };
613                                                                                 obj.data.stash('marked_library');
614                                                                                 alert('Library + Record marked as Volume Transfer Destination');
615                                                                         } else {
616                                                                                 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');
617                                                                         }
618                                                                 } catch(E) {
619                                                                         obj.error.standard_unexpected_error_alert('copy browser -> mark library',E);
620                                                                 }
621                                                         }
622                                                 ],
623
624                                                 'cmd_mark_volume' : [
625                                                         ['command'],
626                                                         function() {
627                                                                 try {
628                                                                         var list = util.functional.filter_list(
629                                                                                 obj.sel_list,
630                                                                                 function (o) {
631                                                                                         return o.split(/_/)[0] == 'acn';
632                                                                                 }
633                                                                         );
634
635                                                                         list = util.functional.map_list(
636                                                                                 list,
637                                                                                 function (o) {
638                                                                                         return o.split(/_/)[1];
639                                                                                 }
640                                                                         );
641
642                                                                         if (list.length == 1) {
643                                                                                 obj.data.marked_volume = list[0];
644                                                                                 obj.data.stash('marked_volume');
645                                                                                 alert('Volume marked as Item Transfer Destination');
646                                                                         } else {
647                                                                                 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');
648                                                                         }
649                                                                 } catch(E) {
650                                                                         obj.error.standard_unexpected_error_alert('copy browser -> mark volume',E);
651                                                                 }
652                                                         }
653                                                 ],
654                                                 'cmd_refresh_list' : [
655                                                         ['command'],
656                                                         function() {
657                                                                 obj.refresh_list();
658                                                         }
659                                                 ],
660                                                 'cmd_transfer_volume' : [
661                                                         ['command'],
662                                                         function() {
663                                                                 try {
664                                                                         obj.data.stash_retrieve();
665                                                                         if (!obj.data.marked_library) {
666                                                                                 alert('Please mark a library as the destination from within holdings maintenance and then try this again.');
667                                                                                 return;
668                                                                         }
669                                                                         
670                                                                         JSAN.use('util.functional');
671
672                                                                         var list = util.functional.filter_list(
673                                                                                 obj.sel_list,
674                                                                                 function (o) {
675                                                                                         return o.split(/_/)[0] == 'acn';
676                                                                                 }
677                                                                         );
678
679                                                                         list = util.functional.map_list(
680                                                                                 list,
681                                                                                 function (o) {
682                                                                                         return o.split(/_/)[1];
683                                                                                 }
684                                                                         );
685
686                                                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
687                                                                         var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
688                                                                         xml += '<description>Transfer volumes ';
689
690                                                                         xml += util.functional.map_list(
691                                                                                 list,
692                                                                                 function (o) {
693                                                                                         return obj.map_acn[ 'acn_' + o ].label();
694                                                                                 }
695                                                                         ).join(", ");
696
697                                                                         xml += ' to library ' + obj.data.hash.aou[ obj.data.marked_library.lib ].shortname();
698                                                                         xml += ' on the following record?</description>';
699                                                                         xml += '<hbox><button label="Transfer" name="fancy_submit"/>';
700                                                                         xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
701                                                                         xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
702                                                                         xml += '</vbox>';
703                                                                         obj.data.temp_transfer = xml; obj.data.stash('temp_transfer');
704                                                                         window.open(
705                                                                                 urls.XUL_FANCY_PROMPT
706                                                                                 + '?xml_in_stash=temp_transfer'
707                                                                                 + '&title=' + window.escape('Volume Transfer'),
708                                                                                 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300'
709                                                                         );
710                                                                         JSAN.use('OpenILS.data');
711                                                                         var data = new OpenILS.data(); data.init({'via':'stash'});
712                                                                         if (data.fancy_prompt_data == '') { alert('Transfer Aborted'); return; }
713
714                                                                         var robj = obj.network.simple_request(
715                                                                                 'FM_ACN_TRANSFER', 
716                                                                                 [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'volumes' : list } ],
717                                                                                 null,
718                                                                                 {
719                                                                                         'title' : 'Override Volume Transfer Failure?',
720                                                                                         'overridable_events' : [
721                                                                                                 1208 /* TITLE_LAST_COPY */,
722                                                                                                 1219 /* COPY_REMOTE_CIRC_LIB */,
723                                                                                         ],
724                                                                                 }
725                                                                         );
726
727                                                                         if (typeof robj.ilsevent != 'undefined') {
728                                                                                 if (robj.ilsevent == 1221 /* ORG_CANNOT_HAVE_VOLS */) {
729                                                                                         alert('That destination cannot have volumes.');
730                                                                                 } else {
731                                                                                         throw(robj);
732                                                                                 }
733                                                                         } else {
734                                                                                 alert('Volumes transferred.');
735                                                                         }
736
737                                                                 } catch(E) {
738                                                                         obj.error.standard_unexpected_error_alert('All volumes not likely transferred.',E);
739                                                                 }
740                                                                 obj.refresh_list();
741                                                         }
742                                                 ],
743
744                                                 'cmd_transfer_items' : [
745                                                         ['command'],
746                                                         function() {
747                                                                 try {
748                                                                         obj.data.stash_retrieve();
749                                                                         if (!obj.data.marked_volume) {
750                                                                                 alert('Please mark a volume as the destination from within holdings maintenance and then try this again.');
751                                                                                 return;
752                                                                         }
753                                                                         
754                                                                         JSAN.use('util.functional');
755
756                                                                         var list = util.functional.filter_list(
757                                                                                 obj.sel_list,
758                                                                                 function (o) {
759                                                                                         return o.split(/_/)[0] == 'acp';
760                                                                                 }
761                                                                         );
762
763                                                                         list = util.functional.map_list(
764                                                                                 list,
765                                                                                 function (o) {
766                                                                                         return o.split(/_/)[1];
767                                                                                 }
768                                                                         );
769
770                                                                         var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
771
772                                                                         JSAN.use('cat.util'); cat.util.transfer_copies( { 
773                                                                                 'copy_ids' : list, 
774                                                                                 'docid' : volume.record(),
775                                                                                 'volume_label' : volume.label(),
776                                                                                 'owning_lib' : volume.owning_lib(),
777                                                                         } );
778
779                                                                 } catch(E) {
780                                                                         obj.error.standard_unexpected_error_alert('All copies not likely transferred.',E);
781                                                                 }
782                                                                 obj.refresh_list();
783                                                         }
784                                                 ],
785                                         }
786                                 }
787                         );
788
789                         obj.list_init(params);
790
791                         obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
792
793                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
794                         obj.show_libs( org );
795
796                         obj.show_my_libs();
797
798                 } catch(E) {
799                         this.error.sdump('D_ERROR','cat.copy_browser.init: ' + E + '\n');
800                 }
801         },
802
803         'show_my_libs' : function() {
804                 var obj = this;
805                 try {
806                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
807                         obj.show_libs( org, true );
808                 
809                         var p_org = obj.data.hash.aou[ org.parent_ou() ];
810                         if (p_org) {
811                                 JSAN.use('util.exec'); var exec = new util.exec();
812                                 var funcs = [];
813                                 for (var i = 0; i < p_org.children().length; i++) {
814                                         funcs.push(
815                                                 function(o) {
816                                                         return function() {
817                                                                 obj.show_libs( o, true );
818                                                         }
819                                                 }( p_org.children()[i] )
820                                         );
821                                 }
822                                 exec.chain( funcs );
823                         }
824                 } catch(E) {
825                         alert(E);
826                 }
827         },
828
829         'show_all_libs' : function() {
830                 var obj = this;
831                 try {
832                         obj.show_my_libs();
833
834                         obj.show_libs( obj.data.tree.aou );
835
836                         JSAN.use('util.exec'); var exec = new util.exec();
837                         var funcs = [];
838                         for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
839                                 funcs.push(
840                                         function(o) {
841                                                 return function() {
842                                                         obj.show_libs( o );
843                                                 }
844                                         }( obj.data.tree.aou.children()[i] )
845                                 );
846                         }
847                         exec.chain( funcs );
848                 } catch(E) {
849                         alert(E);
850                 }
851         },
852
853         'show_libs_with_copies' : function() {
854                 var obj = this;
855                 try {
856                         JSAN.use('util.exec'); var exec = new util.exec();
857                         JSAN.use('util.functional');
858
859                         var orgs = util.functional.map_list(
860                                 obj.org_ids,
861                                 function(id) { return obj.data.hash.aou[id]; }
862                         ).sort(
863                                 function( a, b ) {
864                                         if (a.shortname() < b.shortname()) return -1;
865                                         if (a.shortname() > b.shortname()) return 1;
866                                         return 0;
867                                 }
868                         );
869                         var funcs = [];
870                         for (var i = 0; i < orgs.length; i++) {
871                                 funcs.push(
872                                         function(o) {
873                                                 return function() {
874                                                         obj.show_libs(o,true);
875                                                 }
876                                         }( orgs[i] )
877                                 );
878                         }
879                         exec.chain( funcs );
880                 } catch(E) {
881                         alert(E);
882                 }
883         },
884
885         'show_libs' : function(start_aou,show_open) {
886                 var obj = this;
887                 try {
888                         if (!start_aou) throw('show_libs: Need a start_aou');
889                         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
890                         JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
891
892                         var funcs = [];
893
894                         var parents = [];
895                         var temp_aou = start_aou;
896                         while ( temp_aou.parent_ou() ) {
897                                 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
898                                 parents.push( temp_aou );
899                         }
900                         parents.reverse();
901
902                         for (var i = 0; i < parents.length; i++) {
903                                 funcs.push(
904                                         function(o,p) {
905                                                 return function() { 
906                                                         if (show_open) {
907                                                                 obj.append_org(o,p,{'container':'true','open':'true'}); 
908                                                         } else {
909                                                                 obj.append_org(o,p,{'container':'true'}); 
910                                                         }
911                                                 };
912                                         }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
913                                 );
914                         }
915
916                         funcs.push(
917                                 function(o,p) {
918                                         return function() { obj.append_org(o,p); };
919                                 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
920                         );
921
922                         funcs.push(
923                                 function() {
924                                         if (start_aou.children()) {
925                                                 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
926                                                 x.setAttribute('container','true');
927                                                 if (show_open) x.setAttribute('open','true');
928                                                 for (var i = 0; i < start_aou.children().length; i++) {
929                                                         funcs.push(
930                                                                 function(o,p) {
931                                                                         return function() { obj.append_org(o,p); };
932                                                                 }( start_aou.children()[i], start_aou )
933                                                         );
934                                                 }
935                                         }
936                                 }
937                         );
938
939                         exec.chain( funcs );
940
941                 } catch(E) {
942                         alert(E);
943                 }
944         },
945
946         'on_select' : function(list,twisty) {
947                 var obj = this;
948                 for (var i = 0; i < list.length; i++) {
949                         var node = obj.map_tree[ list[i] ];
950                         //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
951                         var row_type = list[i].split('_')[0];
952                         var id = list[i].split('_')[1];
953                         switch(row_type) {
954                                 case 'aou' : obj.on_select_org(id,twisty); break;
955                                 case 'acn' : obj.on_select_acn(id,twisty); break;
956                                 default: break;
957                         }
958                 }
959         },
960
961         'on_select_acn' : function(acn_id,twisty) {
962                 var obj = this;
963                 try {
964                         var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
965                         var funcs = [];
966                         if (acn_tree.copies()) {
967                                 for (var i = 0; i < acn_tree.copies().length; i++) {
968                                         funcs.push(
969                                                 function(c,a) {
970                                                         return function() {
971                                                                 obj.append_acp(c,a);
972                                                         }
973                                                 }( acn_tree.copies()[i], acn_tree )
974                                         )
975                                 }
976                         }
977                         JSAN.use('util.exec'); var exec = new util.exec();
978                         exec.chain( funcs );
979                 } catch(E) {
980                         alert(E);
981                 }
982         },
983
984         'on_select_org' : function(org_id,twisty) {
985                 var obj = this;
986                 var org = obj.data.hash.aou[ org_id ];
987                 var funcs = [];
988                 if (org.children()) {
989                         for (var i = 0; i < org.children().length; i++) {
990                                 funcs.push(
991                                         function(o,p) {
992                                                 return function() {
993                                                         obj.append_org(o,p)
994                                                 }
995                                         }(org.children()[i],org)
996                                 );
997                         }
998                 } 
999                 if (obj.map_acn[ 'aou_' + org_id ]) {
1000                         for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
1001                                 funcs.push(
1002                                         function(o,a) {
1003                                                 return function() {
1004                                                         obj.append_acn(o,a);
1005                                                 }
1006                                         }( org, obj.map_acn[ 'aou_' + org_id ][i] )
1007                                 );
1008                         }
1009                 }
1010                 JSAN.use('util.exec'); var exec = new util.exec();
1011                 exec.chain( funcs );
1012         },
1013
1014         'append_org' : function (org,parent_org,params) {
1015                 var obj = this;
1016                 try {
1017                         if (obj.map_tree[ 'aou_' + org.id() ]) {
1018                                 var x = obj.map_tree[ 'aou_' + org.id() ];
1019                                 if (params) {
1020                                         for (var i in params) {
1021                                                 x.setAttribute(i,params[i]);
1022                                         }
1023                                 }
1024                                 return x;
1025                         }
1026
1027                         var data = {
1028                                 'row' : {
1029                                         'my' : {
1030                                                 'aou' : org,
1031                                         }
1032                                 },
1033                                 'skip_all_columns_except' : [0,1,2],
1034                                 'retrieve_id' : 'aou_' + org.id(),
1035                         };
1036                 
1037                         var acn_tree_list;
1038                         if ( obj.org_ids.indexOf( org.id() ) == -1 ) {
1039                                 if ( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) {
1040                                         data.row.my.volume_count = '0';
1041                                         data.row.my.copy_count = '<0>';
1042                                 } else {
1043                                         data.row.my.volume_count = '';
1044                                         data.row.my.copy_count = '';
1045                                 }
1046                         } else {
1047                                 var v_count = 0; var c_count = 0;
1048                                 acn_tree_list = obj.network.simple_request(
1049                                         'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
1050                                         [ ses(), obj.docid, [ org.id() ] ]
1051                                 );
1052                                 for (var i = 0; i < acn_tree_list.length; i++) {
1053                                         v_count++;
1054                                         obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
1055                                         var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
1056                                         for (var j = 0; j < copies.length; j++) {
1057                                                 obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
1058                                         }
1059                                 }
1060                                 data.row.my.volume_count = v_count;
1061                                 data.row.my.copy_count = '<' + c_count + '>';
1062                         }
1063                         if (parent_org) {
1064                                 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1065                         }
1066
1067                         var node = obj.list.append(data);
1068                         if (params) {
1069                                 for (var i in params) {
1070                                         node.setAttribute(i,params[i]);
1071                                 }
1072                         }
1073                         obj.map_tree[ 'aou_' + org.id() ] = node;
1074
1075                         if (org.children()) {
1076                                 node.setAttribute('container','true');
1077                         }
1078
1079                         if (parent_org) {
1080                                 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1081                                         data.node.setAttribute('open','true');
1082                                 }
1083                         } else {
1084                                 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1085                         }
1086
1087                         if (acn_tree_list) {
1088                                 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
1089                                 node.setAttribute('container','true');
1090                         }
1091
1092                 } catch(E) {
1093                         dump(E+'\n');
1094                         alert(E);
1095                 }
1096         },
1097
1098         'append_acn' : function( org, acn_tree, params ) {
1099                 var obj = this;
1100                 try {
1101                         if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
1102                                 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
1103                                 if (params) {
1104                                         for (var i in params) {
1105                                                 x.setAttribute(i,params[i]);
1106                                         }
1107                                 }
1108                                 return x;
1109                         }
1110
1111                         var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1112                         var data = {
1113                                 'row' : {
1114                                         'my' : {
1115                                                 'aou' : org,
1116                                                 'acn' : acn_tree,
1117                                                 'volume_count' : '',
1118                                                 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
1119                                         }
1120                                 },
1121                                 'skip_all_columns_except' : [0,1,2],
1122                                 'retrieve_id' : 'acn_' + acn_tree.id(),
1123                                 'node' : parent_node,
1124                         };
1125                         var node = obj.list.append(data);
1126                         obj.map_tree[ 'acn_' + acn_tree.id() ] =  node;
1127                         if (params) {
1128                                 for (var i in params) {
1129                                         node.setAttribute(i,params[i]);
1130                                 }
1131                         }
1132                         if (acn_tree.copies()) {
1133                                 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
1134                                 node.setAttribute('container','true');
1135                         }
1136
1137                 } catch(E) {
1138                         dump(E+'\n');
1139                         alert(E);
1140                 }
1141         },
1142
1143         'append_acp' : function( acp_item, acn_tree, params ) {
1144                 var obj = this;
1145                 try {
1146                         if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
1147                                 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
1148                                 if (params) {
1149                                         for (var i in params) {
1150                                                 x.setAttribute(i,params[i]);
1151                                         }
1152                                 }
1153                                 return x;
1154                         }
1155
1156                         var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
1157                         var data = {
1158                                 'row' : {
1159                                         'my' : {
1160                                                 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
1161                                                 'acn' : acn_tree,
1162                                                 'acp' : acp_item,
1163                                                 'volume_count' : '',
1164                                                 'copy_count' : '',
1165                                         }
1166                                 },
1167                                 'retrieve_id' : 'acp_' + acp_item.id(),
1168                                 'node' : parent_node,
1169                         };
1170                         var node = obj.list.append(data);
1171                         obj.map_tree[ 'acp_' + acp_item.id() ] =  node;
1172                         if (params) {
1173                                 for (var i in params) {
1174                                         node.setAttribute(i,params[i]);
1175                                 }
1176                         }
1177
1178                 } catch(E) {
1179                         dump(E+'\n');
1180                         alert(E);
1181                 }
1182         },
1183
1184         'list_init' : function( params ) {
1185
1186                 try {
1187                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1188                         var obj = this;
1189                         
1190                         JSAN.use('circ.util');
1191                         var columns = [
1192                                 {
1193                                         'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
1194                                         'primary' : true, 'hidden' : false, 
1195                                         'render' : 'my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"'
1196                                 },
1197                                 {
1198                                         'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
1199                                         'primary' : false, 'hidden' : false, 
1200                                         'render' : 'my.volume_count'
1201                                 },
1202                                 {
1203                                         'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
1204                                         'primary' : false, 'hidden' : false, 
1205                                         'render' : 'my.copy_count'
1206                                 },
1207                         ].concat(
1208                                 circ.util.columns( 
1209                                         { 
1210                                                 'location' : { 'hidden' : false },
1211                                                 'circ_lib' : { 'hidden' : false },
1212                                                 'owning_lib' : { 'hidden' : false },
1213                                                 'call_number' : { 'hidden' : false },
1214                                                 'due_date' : { 'hidden' : false },
1215                                                 'status' : { 'hidden' : false },
1216                                         },
1217                                         {
1218                                                 'just_these' : [
1219                                                         'due_date',
1220                                                         'owning_lib',
1221                                                         'circ_lib',
1222                                                         'call_number',
1223                                                         'copy_number',
1224                                                         'location',
1225                                                         'barcode',
1226                                                         'loan_duration',
1227                                                         'fine_level',
1228                                                         'circulate',
1229                                                         'holdable',
1230                                                         'opac_visible',
1231                                                         'ref',
1232                                                         'deposit',
1233                                                         'deposit_amount',
1234                                                         'price',
1235                                                         'circ_as_type',
1236                                                         'circ_modifier',
1237                                                         'status',
1238                                                         'alert_message',
1239                                                         'acp_id',
1240                                                 ]
1241                                         }
1242                                 )
1243                         );
1244                         JSAN.use('util.list'); obj.list = new util.list('copy_tree');
1245                         obj.list.init(
1246                                 {
1247                                         'columns' : columns,
1248                                         'map_row_to_column' : circ.util.std_map_row_to_column(' '),
1249                                         'retrieve_row' : function(params) {
1250
1251                                                 var row = params.row;
1252
1253                                                 var funcs = [];
1254                                         /*      
1255                                                 if (!row.my.mvr) funcs.push(
1256                                                         function() {
1257
1258                                                                 row.my.mvr = obj.network.request(
1259                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
1260                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
1261                                                                         [ row.my.circ.target_copy() ]
1262                                                                 );
1263
1264                                                         }
1265                                                 );
1266                                                 if (!row.my.acp) {
1267                                                         funcs.push(     
1268                                                                 function() {
1269
1270                                                                         row.my.acp = obj.network.request(
1271                                                                                 api.FM_ACP_RETRIEVE.app,
1272                                                                                 api.FM_ACP_RETRIEVE.method,
1273                                                                                 [ row.my.circ.target_copy() ]
1274                                                                         );
1275
1276                                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1277
1278                                                                 }
1279                                                         );
1280                                                 } else {
1281                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1282                                                 }
1283                                         */
1284                                                 funcs.push(
1285                                                         function() {
1286
1287                                                                 if (typeof params.on_retrieve == 'function') {
1288                                                                         params.on_retrieve(row);
1289                                                                 }
1290
1291                                                         }
1292                                                 );
1293
1294                                                 JSAN.use('util.exec'); var exec = new util.exec();
1295                                                 exec.on_error = function(E) {
1296                                                         var err = 'items chain: ' + js2JSON(E);
1297                                                         obj.error.sdump('D_ERROR',err);
1298                                                         return true; /* keep going */
1299                                                 }
1300                                                 exec.chain( funcs );
1301
1302                                                 return row;
1303                                         },
1304                                         'on_click' : function(ev) {
1305                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1306                                                 var row = {}; var col = {}; var nobj = {};
1307                                                 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
1308                                                 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
1309                                                 var node = obj.list.node.contentView.getItemAtIndex(row.value);
1310                                                 var list = [ node.getAttribute('retrieve_id') ];
1311                                                 if (typeof obj.on_select == 'function') {
1312                                                         obj.on_select(list,true);
1313                                                 }
1314                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1315                                                         window.xulG.on_select(list);
1316                                                 }
1317                                         },
1318                                         'on_select' : function(ev) {
1319                                                 JSAN.use('util.functional');
1320                                                 var sel = obj.list.retrieve_selection();
1321                                                 obj.controller.view.sel_clip.disabled = sel.length < 1;
1322                                                 obj.sel_list = util.functional.map_list(
1323                                                         sel,
1324                                                         function(o) { return o.getAttribute('retrieve_id'); }
1325                                                 );
1326                                                 obj.toggle_actions();
1327                                                 if (typeof obj.on_select == 'function') {
1328                                                         obj.on_select(obj.sel_list);
1329                                                 }
1330                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1331                                                         window.xulG.on_select(obj.sel_list);
1332                                                 }
1333                                         },
1334                                 }
1335                         );
1336
1337                         obj.controller.render();
1338
1339                 } catch(E) {
1340                         this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
1341                         alert(E);
1342                 }
1343         },
1344
1345         'toggle_actions' : function() {
1346                 var obj = this;
1347                 try {
1348                         var found_aou = false; var found_acn = false; var found_acp = false;
1349                         for (var i = 0; i < obj.sel_list.length; i++) {
1350                                 var type = obj.sel_list[i].split(/_/)[0];
1351                                 switch(type) {
1352                                         case 'aou' : found_aou = true; break;
1353                                         case 'acn' : found_acn = true; break;
1354                                         case 'acp' : found_acp = true; break;
1355                                 }
1356                         }
1357                         obj.controller.view.cmd_add_items.setAttribute('disabled','true');
1358                         obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','true');
1359                         obj.controller.view.cmd_edit_items.setAttribute('disabled','true');
1360                         obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
1361                         obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','true');
1362                         obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
1363                         obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1364                         obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
1365                         obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
1366                         obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
1367                         obj.controller.view.cmd_transfer_volume.setAttribute('disabled','true');
1368                         obj.controller.view.cmd_transfer_items.setAttribute('disabled','true');
1369                         obj.controller.view.sel_copy_details.setAttribute('disabled','true');
1370                         obj.controller.view.sel_patron.setAttribute('disabled','true');
1371                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
1372                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
1373                         if (found_aou) {
1374                                 obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
1375                                 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1376                         }
1377                         if (found_acn) {
1378                                 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
1379                                 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
1380                                 obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
1381                                 obj.controller.view.cmd_add_items.setAttribute('disabled','false');
1382                                 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','false');
1383                         }
1384                         if (found_acp) {
1385                                 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
1386                                 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
1387                                 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','false');
1388                                 obj.controller.view.cmd_edit_items.setAttribute('disabled','false');
1389                                 obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
1390                                 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','false');
1391                                 obj.controller.view.cmd_transfer_items.setAttribute('disabled','false');
1392                                 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
1393                                 obj.controller.view.sel_patron.setAttribute('disabled','false');
1394                         }
1395                 } catch(E) {
1396                         obj.error.standard_unexpected_error_alert('Copy Browser Actions',E);
1397                 }
1398         },
1399
1400         'refresh_list' : function() { 
1401                 try {
1402                         var obj = this;
1403                         obj.list.clear();
1404                         obj.map_tree = {};
1405                         obj.map_acn = {};
1406                         obj.map_acp = {};
1407                         obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
1408                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1409                         obj.show_libs( org );
1410                         obj.show_my_libs();
1411                 } catch(E) {
1412                         this.error.standard_unexpected_error_alert('Problem refreshing the volume/copy tree.',E);
1413                 }
1414         },
1415 }
1416
1417 dump('exiting cat.copy_browser.js\n');