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