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