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