]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_browser.js
add to copy bucket
[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                                                 'cmd_broken' : [
35                                                         ['command'],
36                                                         function() { alert('Not Yet Implemented'); }
37                                                 ],
38                                                 'cmd_show_my_libs' : [
39                                                         ['command'],
40                                                         function() { 
41                                                                 obj.show_my_libs(); 
42                                                         }
43                                                 ],
44                                                 'cmd_show_all_libs' : [
45                                                         ['command'],
46                                                         function() {
47                                                                 obj.show_all_libs();
48                                                         }
49                                                 ],
50                                                 'cmd_show_libs_with_copies' : [
51                                                         ['command'],
52                                                         function() {
53                                                                 obj.show_libs_with_copies();
54                                                         }
55                                                 ],
56                                                 'cmd_clear' : [
57                                                         ['command'],
58                                                         function() {
59                                                                 obj.map_tree = {};
60                                                                 obj.list.clear();
61                                                         }
62                                                 ],
63                                                 'cmd_add_items' : [
64                                                         ['command'],
65                                                         function() {
66                                                                 try {
67                                                                         JSAN.use('util.functional');
68                                                                         var list = util.functional.map_list(
69                                                                                 util.functional.filter_list(
70                                                                                         obj.sel_list,
71                                                                                         function (o) {
72                                                                                                 return o.split(/_/)[0] == 'acn';
73                                                                                         }
74                                                                                 ),
75                                                                                 function (o) {
76                                                                                         return o.split(/_/)[1];
77                                                                                 }
78                                                                         );
79                                                                         if (list.length == 0) return;
80
81                                                                         var copy_shortcut = {};
82                                                                         list = util.functional.map_list(
83                                                                                 list,
84                                                                                 function (o) {
85                                                                                         var ou_id = obj.map_acn['acn_' + o].owning_lib();
86                                                                                         var volume_id = o;
87                                                                                         var label = obj.map_acn['acn_' + o].label();
88                                                                                         if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {};
89                                                                                         copy_shortcut[ou_id][ label ] = volume_id;
90
91                                                                                         return ou_id;
92                                                                                 }
93                                                                         );
94                                                                         /* quick fix */  /* what was this fixing? */
95                                                                         list = []; for (var i in copy_shortcut) { list.push( i ); }
96
97                                                                         var edit = 0;
98                                                                         try {
99                                                                                 edit = obj.network.request(
100                                                                                         api.PERM_MULTI_ORG_CHECK.app,
101                                                                                         api.PERM_MULTI_ORG_CHECK.method,
102                                                                                         [ 
103                                                                                                 ses(), 
104                                                                                                 obj.data.list.au[0].id(), 
105                                                                                                 list,
106                                                                                                 [ 'CREATE_COPY' ]
107                                                                                         ]
108                                                                                 ).length == 0 ? 1 : 0;
109                                                                         } catch(E) {
110                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
111                                                                         }
112
113                                                                         if (edit==0) return; // no read-only view for this interface
114
115                                                                         var title = 'Add Copy';
116
117                                                                         JSAN.use('util.window'); var win = new util.window();
118                                                                         var w = win.open(
119                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
120                                                                                         +'?doc_id=' + window.escape(obj.docid)
121                                                                                         +'&ou_ids=' + window.escape( js2JSON(list) )
122                                                                                         +'&copy_shortcut=' + window.escape( js2JSON(copy_shortcut) ),
123                                                                                 title,
124                                                                                 'chrome,modal,resizable'
125                                                                         );
126                                                                         obj.refresh_list();
127                                                                 } catch(E) {
128                                                                         obj.error.standard_unexpected_error_alert('copy browser -> add copies',E);
129                                                                 }
130                                                         }
131                                                 ],
132                                                 'cmd_add_items_to_buckets' : [
133                                                         ['command'],
134                                                         function() {
135                                                                 try {
136                                                                         JSAN.use('util.functional');
137
138                                                                         var list = util.functional.filter_list(
139                                                                                 obj.sel_list,
140                                                                                 function (o) {
141                                                                                         return o.split(/_/)[0] == 'acp';
142                                                                                 }
143                                                                         );
144
145                                                                         list = util.functional.map_list(
146                                                                                 list,
147                                                                                 function (o) {
148                                                                                         return o.split(/_/)[1];
149                                                                                 }
150                                                                         );
151                                                                         
152                                                                         JSAN.use('util.window'); var win = new util.window();
153                                                                         win.open( 
154                                                                                 xulG.url_prefix(urls.XUL_COPY_BUCKETS) 
155                                                                                 + '?copy_ids=' + js2JSON( list ),
156                                                                                 'sel_bucket_win' + win.window_name_increment(),
157                                                                                 'chrome,resizable,modal,center'
158                                                                         );
159                                                                 } catch(E) {
160                                                                         obj.error.standard_unexpected_error_alert('copy browser -> add copies to bucket',E);
161                                                                 }
162                                                         }
163                                                 ],
164                                                 'cmd_edit_items' : [
165                                                         ['command'],
166                                                         function() {
167                                                                 try {
168                                                                         JSAN.use('util.functional');
169
170                                                                         var list = util.functional.filter_list(
171                                                                                 obj.sel_list,
172                                                                                 function (o) {
173                                                                                         return o.split(/_/)[0] == 'acp';
174                                                                                 }
175                                                                         );
176
177                                                                         list = util.functional.map_list(
178                                                                                 list,
179                                                                                 function (o) {
180                                                                                         return o.split(/_/)[1];
181                                                                                 }
182                                                                         );
183
184                                                                         var edit = 0;
185                                                                         try {
186                                                                                 edit = obj.network.request(
187                                                                                         api.PERM_MULTI_ORG_CHECK.app,
188                                                                                         api.PERM_MULTI_ORG_CHECK.method,
189                                                                                         [ 
190                                                                                                 ses(), 
191                                                                                                 obj.data.list.au[0].id(), 
192                                                                                                 util.functional.map_list(
193                                                                                                         list,
194                                                                                                         function (o) {
195                                                                                                                 return obj.map_acn[ 'acn_' + obj.map_acp[ 'acp_' + o ].call_number() ].owning_lib();
196                                                                                                         }
197                                                                                                 ),
198                                                                                                 [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
199                                                                                         ]
200                                                                                 ).length == 0 ? 1 : 0;
201                                                                         } catch(E) {
202                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
203                                                                         }
204
205                                                                         var title = list.length == 1 ? 'Copy' : 'Copies';
206
207                                                                         JSAN.use('util.window'); var win = new util.window();
208                                                                         obj.data.temp = '';
209                                                                         obj.data.stash('temp');
210                                                                         var w = win.open(
211                                                                                 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
212                                                                                         +'?copy_ids='+window.escape(js2JSON(list))
213                                                                                         +'&docid='+window.escape(obj.docid)
214                                                                                         +'&edit='+edit
215                                                                                         +'&handle_update=1',
216                                                                                 title,
217                                                                                 'chrome,modal,resizable'
218                                                                         );
219                                                                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
220                                                                         obj.data.stash_retrieve();
221                                                                         var copies = JSON2js( obj.data.temp );
222                                                                         obj.error.sdump('D_CAT','in browse, copies =\n<<' + copies + '>>');
223                                                                         if (edit=='1' && copies!='' && typeof copies != 'undefined') {
224                                                                                 obj.refresh_list();
225                                                                         }
226                                                                 } catch(E) {
227                                                                         obj.error.standard_unexpected_error_alert('Copy Browser -> Edit Items',E);
228                                                                 }
229                                                         }
230                                                 ],
231                                                 'cmd_delete_items' : [
232                                                         ['command'],
233                                                         function() {
234                                                         }
235                                                 ],
236                                                 'cmd_print_spine_labels' : [
237                                                         ['command'],
238                                                         function() {
239                                                         }
240                                                 ],
241                                                 'cmd_add_volumes' : [
242                                                         ['command'],
243                                                         function() {
244                                                                 try {
245                                                                         JSAN.use('util.functional');
246                                                                         var list = util.functional.filter_list(
247                                                                                 obj.sel_list,
248                                                                                 function (o) {
249                                                                                         return o.split(/_/)[0] == 'aou';
250                                                                                 }
251                                                                         );
252                                                                         list = util.functional.map_list(
253                                                                                 list,
254                                                                                 function (o) {
255                                                                                         return o.split(/_/)[1];
256                                                                                 }
257                                                                         );              
258                                                                         var edit = 0;
259                                                                         try {
260                                                                                 edit = obj.network.request(
261                                                                                         api.PERM_MULTI_ORG_CHECK.app,
262                                                                                         api.PERM_MULTI_ORG_CHECK.method,
263                                                                                         [ 
264                                                                                                 ses(), 
265                                                                                                 obj.data.list.au[0].id(), 
266                                                                                                 list,
267                                                                                                 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
268                                                                                         ]
269                                                                                 ).length == 0 ? 1 : 0;
270                                                                         } catch(E) {
271                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
272                                                                         }
273
274                                                                         if (edit==0) {
275                                                                                 alert("You don't have permission to add volumes to that library.");
276                                                                                 return; // no read-only view for this interface
277                                                                         }
278
279                                                                         var title = 'Add Volume/Copy';
280
281                                                                         JSAN.use('util.window'); var win = new util.window();
282                                                                         var w = win.open(
283                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
284                                                                                         +'?doc_id=' + window.escape(obj.docid)
285                                                                                         +'&ou_ids=' + window.escape( js2JSON(list) ),
286                                                                                 title,
287                                                                                 'chrome,modal,resizable'
288                                                                         );
289
290                                                                         obj.refresh_list();
291                                                                 } catch(E) {
292                                                                         obj.error.standard_unexpected_error_alert('copy browser -> add volumes',E);
293                                                                 }
294                                                         }
295                                                 ],
296                                                 'cmd_edit_volumes' : [
297                                                         ['command'],
298                                                         function() {
299                                                                 try {
300                                                                         JSAN.use('util.functional');
301                                                                         var list = util.functional.map_list(
302                                                                                 util.functional.filter_list(
303                                                                                         obj.sel_list,
304                                                                                         function (o) {
305                                                                                                 return o.split(/_/)[0] == 'acn';
306                                                                                         }
307                                                                                 ),
308                                                                                 function (o) {
309                                                                                         return o.split(/_/)[1];
310                                                                                 }
311                                                                         );
312                                                                         if (list.length == 0) return;
313
314                                                                         var edit = 0;
315                                                                         try {
316                                                                                 edit = obj.network.request(
317                                                                                         api.PERM_MULTI_ORG_CHECK.app,
318                                                                                         api.PERM_MULTI_ORG_CHECK.method,
319                                                                                         [ 
320                                                                                                 ses(), 
321                                                                                                 obj.data.list.au[0].id(), 
322                                                                                                 util.functional.map_list(
323                                                                                                         list,
324                                                                                                         function (o) {
325                                                                                                                 return obj.map_acn[ 'acn_' + o ].owning_lib();
326                                                                                                         }
327                                                                                                 ),
328                                                                                                 [ 'UPDATE_VOLUME' ]
329                                                                                         ]
330                                                                                 ).length == 0 ? 1 : 0;
331                                                                         } catch(E) {
332                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
333                                                                         }
334
335                                                                         if (edit==0) {
336                                                                                 alert("You don't have permission to edit this volume.");
337                                                                                 return; // no read-only view for this interface
338                                                                         }
339
340                                                                         list = util.functional.map_list(
341                                                                                 list,
342                                                                                 function (o) {
343                                                                                         var my_acn = obj.map_acn['acn_' + o];
344                                                                                         return function(r){return r;}(my_acn);
345                                                                                 }
346                                                                         );
347
348                                                                         var title = list.length == 1 ? 'Volume' : 'Volumes';
349
350                                                                         JSAN.use('util.window'); var win = new util.window();
351                                                                         obj.data.volumes_temp = js2JSON( list );
352                                                                         obj.data.stash('volumes_temp');
353                                                                         var w = win.open(
354                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
355                                                                                 title,
356                                                                                 'chrome,modal,resizable'
357                                                                         );
358
359                                                                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
360                                                                         obj.data.stash_retrieve();
361                                                                         var volumes = JSON2js( obj.data.volumes_temp );
362                                                                         obj.error.sdump('D_CAT','in browse, obj.data.temp =\n' + obj.data.temp);
363                                                                         if (volumes=='') return;
364                                                                 
365                                                                         volumes = util.functional.filter_list(
366                                                                                 volumes,
367                                                                                 function (o) {
368                                                                                         return o.ischanged() == '1';
369                                                                                 }
370                                                                         );
371
372                                                                         volumes = util.functional.map_list(
373                                                                                 volumes,
374                                                                                 function (o) {
375                                                                                         o.record( obj.docid ); // staff client 2 did not do this.  Does it matter?
376                                                                                         return o;
377                                                                                 }
378                                                                         );
379
380                                                                         if (volumes.length == 0) return;
381
382                                                                         try {
383                                                                                 var r = obj.network.request(
384                                                                                         api.FM_ACN_TREE_UPDATE.app,
385                                                                                         api.FM_ACN_TREE_UPDATE.method,
386                                                                                         [ ses(), volumes ]
387                                                                                 );
388                                                                                 if (typeof r.ilsevent != 'undefined') throw(r);
389                                                                         } catch(E) {
390                                                                                 obj.error.standard_unexpected_error_alert('volume update error: ',E);
391                                                                         }
392                                                                         obj.refresh_list();
393
394                                                                 } catch(E) {
395                                                                         obj.error.standard_unexpected_error_alert('Copy Browser -> Volume Edit',E);
396                                                                 }
397                                                         }
398                                                 ],
399                                                 'cmd_delete_volumes' : [
400                                                         ['command'],
401                                                         function() {
402                                                         }
403                                                 ],
404                                                 'cmd_mark_volume' : [
405                                                         ['command'],
406                                                         function() {
407                                                         }
408                                                 ],
409                                                 'cmd_refresh_list' : [
410                                                         ['command'],
411                                                         function() {
412                                                         }
413                                                 ],
414                                         }
415                                 }
416                         );
417
418                         obj.list_init(params);
419
420                         obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
421
422                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
423                         obj.show_libs( org );
424
425                 } catch(E) {
426                         this.error.sdump('D_ERROR','cat.copy_browser.init: ' + E + '\n');
427                 }
428         },
429
430         'show_my_libs' : function() {
431                 var obj = this;
432                 try {
433                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
434                         obj.show_libs( org, true );
435                 
436                         var p_org = obj.data.hash.aou[ org.parent_ou() ];
437                         if (p_org) {
438                                 JSAN.use('util.exec'); var exec = new util.exec();
439                                 var funcs = [];
440                                 for (var i = 0; i < p_org.children().length; i++) {
441                                         funcs.push(
442                                                 function(o) {
443                                                         return function() {
444                                                                 obj.show_libs( o, true );
445                                                         }
446                                                 }( p_org.children()[i] )
447                                         );
448                                 }
449                                 exec.chain( funcs );
450                         }
451                 } catch(E) {
452                         alert(E);
453                 }
454         },
455
456         'show_all_libs' : function() {
457                 var obj = this;
458                 try {
459                         obj.show_my_libs();
460
461                         obj.show_libs( obj.data.tree.aou );
462
463                         JSAN.use('util.exec'); var exec = new util.exec();
464                         var funcs = [];
465                         for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
466                                 funcs.push(
467                                         function(o) {
468                                                 return function() {
469                                                         obj.show_libs( o );
470                                                 }
471                                         }( obj.data.tree.aou.children()[i] )
472                                 );
473                         }
474                         exec.chain( funcs );
475                 } catch(E) {
476                         alert(E);
477                 }
478         },
479
480         'show_libs_with_copies' : function() {
481                 var obj = this;
482                 try {
483                         JSAN.use('util.exec'); var exec = new util.exec();
484                         JSAN.use('util.functional');
485
486                         var orgs = util.functional.map_list(
487                                 obj.org_ids,
488                                 function(id) { return obj.data.hash.aou[id]; }
489                         ).sort(
490                                 function( a, b ) {
491                                         if (a.shortname() < b.shortname()) return -1;
492                                         if (a.shortname() > b.shortname()) return 1;
493                                         return 0;
494                                 }
495                         );
496                         var funcs = [];
497                         for (var i = 0; i < orgs.length; i++) {
498                                 funcs.push(
499                                         function(o) {
500                                                 return function() {
501                                                         obj.show_libs(o,true);
502                                                 }
503                                         }( orgs[i] )
504                                 );
505                         }
506                         exec.chain( funcs );
507                 } catch(E) {
508                         alert(E);
509                 }
510         },
511
512         'show_libs' : function(start_aou,show_open) {
513                 var obj = this;
514                 try {
515                         if (!start_aou) throw('show_libs: Need a start_aou');
516                         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
517                         JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
518
519                         var funcs = [];
520
521                         var parents = [];
522                         var temp_aou = start_aou;
523                         while ( temp_aou.parent_ou() ) {
524                                 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
525                                 parents.push( temp_aou );
526                         }
527                         parents.reverse();
528
529                         for (var i = 0; i < parents.length; i++) {
530                                 funcs.push(
531                                         function(o,p) {
532                                                 return function() { 
533                                                         if (show_open) {
534                                                                 obj.append_org(o,p,{'container':'true','open':'true'}); 
535                                                         } else {
536                                                                 obj.append_org(o,p,{'container':'true'}); 
537                                                         }
538                                                 };
539                                         }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
540                                 );
541                         }
542
543                         funcs.push(
544                                 function(o,p) {
545                                         return function() { obj.append_org(o,p); };
546                                 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
547                         );
548
549                         funcs.push(
550                                 function() {
551                                         if (start_aou.children()) {
552                                                 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
553                                                 x.setAttribute('container','true');
554                                                 if (show_open) x.setAttribute('open','true');
555                                                 for (var i = 0; i < start_aou.children().length; i++) {
556                                                         funcs.push(
557                                                                 function(o,p) {
558                                                                         return function() { obj.append_org(o,p); };
559                                                                 }( start_aou.children()[i], start_aou )
560                                                         );
561                                                 }
562                                         }
563                                 }
564                         );
565
566                         exec.chain( funcs );
567
568                 } catch(E) {
569                         alert(E);
570                 }
571         },
572
573         'on_select' : function(list,twisty) {
574                 var obj = this;
575                 for (var i = 0; i < list.length; i++) {
576                         var node = obj.map_tree[ list[i] ];
577                         //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
578                         var row_type = list[i].split('_')[0];
579                         var id = list[i].split('_')[1];
580                         switch(row_type) {
581                                 case 'aou' : obj.on_select_org(id,twisty); break;
582                                 case 'acn' : obj.on_select_acn(id,twisty); break;
583                                 default: break;
584                         }
585                 }
586         },
587
588         'on_select_acn' : function(acn_id,twisty) {
589                 var obj = this;
590                 try {
591                         var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
592                         var funcs = [];
593                         if (acn_tree.copies()) {
594                                 for (var i = 0; i < acn_tree.copies().length; i++) {
595                                         funcs.push(
596                                                 function(c,a) {
597                                                         return function() {
598                                                                 obj.append_acp(c,a);
599                                                         }
600                                                 }( acn_tree.copies()[i], acn_tree )
601                                         )
602                                 }
603                         }
604                         JSAN.use('util.exec'); var exec = new util.exec();
605                         exec.chain( funcs );
606                 } catch(E) {
607                         alert(E);
608                 }
609         },
610
611         'on_select_org' : function(org_id,twisty) {
612                 var obj = this;
613                 var org = obj.data.hash.aou[ org_id ];
614                 var funcs = [];
615                 if (org.children()) {
616                         for (var i = 0; i < org.children().length; i++) {
617                                 funcs.push(
618                                         function(o,p) {
619                                                 return function() {
620                                                         obj.append_org(o,p)
621                                                 }
622                                         }(org.children()[i],org)
623                                 );
624                         }
625                 } 
626                 if (obj.map_acn[ 'aou_' + org_id ]) {
627                         for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
628                                 funcs.push(
629                                         function(o,a) {
630                                                 return function() {
631                                                         obj.append_acn(o,a);
632                                                 }
633                                         }( org, obj.map_acn[ 'aou_' + org_id ][i] )
634                                 );
635                         }
636                 }
637                 JSAN.use('util.exec'); var exec = new util.exec();
638                 exec.chain( funcs );
639         },
640
641         'append_org' : function (org,parent_org,params) {
642                 var obj = this;
643                 try {
644                         if (obj.map_tree[ 'aou_' + org.id() ]) {
645                                 var x = obj.map_tree[ 'aou_' + org.id() ];
646                                 if (params) {
647                                         for (var i in params) {
648                                                 x.setAttribute(i,params[i]);
649                                         }
650                                 }
651                                 return x;
652                         }
653
654                         var data = {
655                                 'row' : {
656                                         'my' : {
657                                                 'aou' : org,
658                                         }
659                                 },
660                                 'skip_all_columns_except' : [0,1,2],
661                                 'retrieve_id' : 'aou_' + org.id(),
662                         };
663                 
664                         var acn_tree_list;
665                         if ( obj.org_ids.indexOf( org.id() ) == -1 ) {
666                                 if ( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) {
667                                         data.row.my.volume_count = '0';
668                                         data.row.my.copy_count = '<0>';
669                                 } else {
670                                         data.row.my.volume_count = '';
671                                         data.row.my.copy_count = '';
672                                 }
673                         } else {
674                                 var v_count = 0; var c_count = 0;
675                                 acn_tree_list = obj.network.simple_request(
676                                         'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
677                                         [ ses(), obj.docid, [ org.id() ] ]
678                                 );
679                                 for (var i = 0; i < acn_tree_list.length; i++) {
680                                         v_count++;
681                                         obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
682                                         var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
683                                         for (var j = 0; j < copies.length; j++) {
684                                                 obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
685                                         }
686                                 }
687                                 data.row.my.volume_count = v_count;
688                                 data.row.my.copy_count = '<' + c_count + '>';
689                         }
690                         if (parent_org) {
691                                 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
692                         }
693
694                         var node = obj.list.append(data);
695                         if (params) {
696                                 for (var i in params) {
697                                         node.setAttribute(i,params[i]);
698                                 }
699                         }
700                         obj.map_tree[ 'aou_' + org.id() ] = node;
701
702                         if (org.children()) {
703                                 node.setAttribute('container','true');
704                         }
705
706                         if (parent_org) {
707                                 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
708                                         data.node.setAttribute('open','true');
709                                 }
710                         } else {
711                                 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
712                         }
713
714                         if (acn_tree_list) {
715                                 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
716                                 node.setAttribute('container','true');
717                         }
718
719                 } catch(E) {
720                         dump(E+'\n');
721                         alert(E);
722                 }
723         },
724
725         'append_acn' : function( org, acn_tree, params ) {
726                 var obj = this;
727                 try {
728                         if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
729                                 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
730                                 if (params) {
731                                         for (var i in params) {
732                                                 x.setAttribute(i,params[i]);
733                                         }
734                                 }
735                                 return x;
736                         }
737
738                         var parent_node = obj.map_tree[ 'aou_' + org.id() ];
739                         var data = {
740                                 'row' : {
741                                         'my' : {
742                                                 'aou' : org,
743                                                 'acn' : acn_tree,
744                                                 'volume_count' : '',
745                                                 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
746                                         }
747                                 },
748                                 'skip_all_columns_except' : [0,1,2],
749                                 'retrieve_id' : 'acn_' + acn_tree.id(),
750                                 'node' : parent_node,
751                         };
752                         var node = obj.list.append(data);
753                         obj.map_tree[ 'acn_' + acn_tree.id() ] =  node;
754                         if (params) {
755                                 for (var i in params) {
756                                         node.setAttribute(i,params[i]);
757                                 }
758                         }
759                         if (acn_tree.copies()) {
760                                 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
761                                 node.setAttribute('container','true');
762                         }
763
764                 } catch(E) {
765                         dump(E+'\n');
766                         alert(E);
767                 }
768         },
769
770         'append_acp' : function( acp_item, acn_tree, params ) {
771                 var obj = this;
772                 try {
773                         if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
774                                 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
775                                 if (params) {
776                                         for (var i in params) {
777                                                 x.setAttribute(i,params[i]);
778                                         }
779                                 }
780                                 return x;
781                         }
782
783                         var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
784                         var data = {
785                                 'row' : {
786                                         'my' : {
787                                                 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
788                                                 'acn' : acn_tree,
789                                                 'acp' : acp_item,
790                                                 'volume_count' : '',
791                                                 'copy_count' : '',
792                                         }
793                                 },
794                                 'retrieve_id' : 'acp_' + acp_item.id(),
795                                 'node' : parent_node,
796                         };
797                         var node = obj.list.append(data);
798                         obj.map_tree[ 'acp_' + acp_item.id() ] =  node;
799                         if (params) {
800                                 for (var i in params) {
801                                         node.setAttribute(i,params[i]);
802                                 }
803                         }
804
805                 } catch(E) {
806                         dump(E+'\n');
807                         alert(E);
808                 }
809         },
810
811         'list_init' : function( params ) {
812
813                 try {
814                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
815                         var obj = this;
816                         
817                         JSAN.use('circ.util');
818                         var columns = [
819                                 {
820                                         'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
821                                         'primary' : true, 'hidden' : false, 
822                                         'render' : 'my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"'
823                                 },
824                                 {
825                                         'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
826                                         'primary' : false, 'hidden' : false, 
827                                         'render' : 'my.volume_count'
828                                 },
829                                 {
830                                         'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
831                                         'primary' : false, 'hidden' : false, 
832                                         'render' : 'my.copy_count'
833                                 },
834                         ].concat(
835                                 circ.util.columns( 
836                                         { 
837                                                 'location' : { 'hidden' : false },
838                                                 'circ_lib' : { 'hidden' : false },
839                                                 'owning_lib' : { 'hidden' : false },
840                                                 'call_number' : { 'hidden' : false },
841                                                 'status' : { 'hidden' : false },
842                                         },
843                                         {
844                                                 'just_these' : [
845                                                         'owning_lib',
846                                                         'circ_lib',
847                                                         'call_number',
848                                                         'copy_number',
849                                                         'location',
850                                                         'barcode',
851                                                         'loan_duration',
852                                                         'fine_level',
853                                                         'circulate',
854                                                         'holdable',
855                                                         'opac_visible',
856                                                         'ref',
857                                                         'deposit',
858                                                         'deposit_amount',
859                                                         'price',
860                                                         'circ_as_type',
861                                                         'circ_modifier',
862                                                         'status',
863                                                         'alert_message',
864                                                         'acp_id',
865                                                 ]
866                                         }
867                                 )
868                         );
869                         JSAN.use('util.list'); obj.list = new util.list('copy_tree');
870                         obj.list.init(
871                                 {
872                                         'columns' : columns,
873                                         'map_row_to_column' : circ.util.std_map_row_to_column(' '),
874                                         'retrieve_row' : function(params) {
875
876                                                 var row = params.row;
877
878                                                 var funcs = [];
879                                         /*      
880                                                 if (!row.my.mvr) funcs.push(
881                                                         function() {
882
883                                                                 row.my.mvr = obj.network.request(
884                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
885                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
886                                                                         [ row.my.circ.target_copy() ]
887                                                                 );
888
889                                                         }
890                                                 );
891                                                 if (!row.my.acp) {
892                                                         funcs.push(     
893                                                                 function() {
894
895                                                                         row.my.acp = obj.network.request(
896                                                                                 api.FM_ACP_RETRIEVE.app,
897                                                                                 api.FM_ACP_RETRIEVE.method,
898                                                                                 [ row.my.circ.target_copy() ]
899                                                                         );
900
901                                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
902
903                                                                 }
904                                                         );
905                                                 } else {
906                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
907                                                 }
908                                         */
909                                                 funcs.push(
910                                                         function() {
911
912                                                                 if (typeof params.on_retrieve == 'function') {
913                                                                         params.on_retrieve(row);
914                                                                 }
915
916                                                         }
917                                                 );
918
919                                                 JSAN.use('util.exec'); var exec = new util.exec();
920                                                 exec.on_error = function(E) {
921                                                         var err = 'items chain: ' + js2JSON(E);
922                                                         obj.error.sdump('D_ERROR',err);
923                                                         return true; /* keep going */
924                                                 }
925                                                 exec.chain( funcs );
926
927                                                 return row;
928                                         },
929                                         'on_click' : function(ev) {
930                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
931                                                 var row = {}; var col = {}; var nobj = {};
932                                                 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
933                                                 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
934                                                 var node = obj.list.node.contentView.getItemAtIndex(row.value);
935                                                 var list = [ node.getAttribute('retrieve_id') ];
936                                                 if (typeof obj.on_select == 'function') {
937                                                         obj.on_select(list,true);
938                                                 }
939                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
940                                                         window.xulG.on_select(list);
941                                                 }
942                                         },
943                                         'on_select' : function(ev) {
944                                                 JSAN.use('util.functional');
945                                                 var sel = obj.list.retrieve_selection();
946                                                 obj.sel_list = util.functional.map_list(
947                                                         sel,
948                                                         function(o) { return o.getAttribute('retrieve_id'); }
949                                                 );
950                                                 obj.toggle_actions();
951                                                 if (typeof obj.on_select == 'function') {
952                                                         obj.on_select(obj.sel_list);
953                                                 }
954                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
955                                                         window.xulG.on_select(obj.sel_list);
956                                                 }
957                                         },
958                                 }
959                         );
960
961                         obj.controller.render();
962
963                 } catch(E) {
964                         this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
965                         alert(E);
966                 }
967         },
968
969         'toggle_actions' : function() {
970                 var obj = this;
971                 try {
972                         var found_aou = false; var found_acn = false; var found_acp = false;
973                         for (var i = 0; i < obj.sel_list.length; i++) {
974                                 var type = obj.sel_list[i].split(/_/)[0];
975                                 switch(type) {
976                                         case 'aou' : found_aou = true; break;
977                                         case 'acn' : found_acn = true; break;
978                                         case 'acp' : found_acp = true; break;
979                                 }
980                         }
981                         obj.controller.view.cmd_add_items.setAttribute('disabled','true');
982                         obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','true');
983                         obj.controller.view.cmd_edit_items.setAttribute('disabled','true');
984                         obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
985                         obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','true');
986                         obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
987                         obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
988                         obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
989                         obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
990                         if (found_aou) {
991                                 obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
992                         }
993                         if (found_acn) {
994                                 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
995                                 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
996                                 obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
997                                 obj.controller.view.cmd_add_items.setAttribute('disabled','false');
998                         }
999                         if (found_acp) {
1000                                 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','false');
1001                                 obj.controller.view.cmd_edit_items.setAttribute('disabled','false');
1002                                 obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
1003                                 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','false');
1004                         }
1005                 } catch(E) {
1006                         obj.error.standard_unexpected_error_alert('Copy Browser Actions',E);
1007                 }
1008         },
1009
1010         'refresh_list' : function() { alert('FIXME: refresh the list now'); },
1011 }
1012
1013 dump('exiting cat.copy_browser.js\n');