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