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