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