]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_browser.js
faster list rendering with one eval per row
[Evergreen.git] / Open-ILS / xul / staff_client / server / cat / copy_browser.js
1 dump('entering cat.copy_browser.js\n');
2
3 if (typeof cat == 'undefined') cat = {};
4 cat.copy_browser = function (params) {
5         try {
6                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
7                 JSAN.use('util.error'); this.error = new util.error();
8         } catch(E) {
9                 dump('cat.copy_browser: ' + E + '\n');
10         }
11 }
12
13 cat.copy_browser.prototype = {
14
15         'map_tree' : {},
16         'map_acn' : {},
17         'map_acp' : {},
18         'sel_list' : [],
19
20         'init' : function( params ) {
21
22                 try {
23                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
24                         var obj = this;
25
26                         obj.docid = params.docid;
27
28                         JSAN.use('util.network'); obj.network = new util.network();
29                         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
30                         JSAN.use('util.controller'); obj.controller = new util.controller();
31                         obj.controller.init(
32                                 {
33                                         control_map : {
34                                                 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
35                                                 'sel_clip' : [
36                                                         ['command'],
37                                                         function() { obj.list.clipboard(); }
38                                                 ],
39                                                 'cmd_broken' : [
40                                                         ['command'],
41                                                         function() { alert('Not Yet Implemented'); }
42                                                 ],
43                                                 'cmd_show_my_libs' : [
44                                                         ['command'],
45                                                         function() { 
46                                                                 obj.show_my_libs(); 
47                                                         }
48                                                 ],
49                                                 'cmd_show_all_libs' : [
50                                                         ['command'],
51                                                         function() {
52                                                                 obj.show_all_libs();
53                                                         }
54                                                 ],
55                                                 'cmd_show_libs_with_copies' : [
56                                                         ['command'],
57                                                         function() {
58                                                                 obj.show_libs_with_copies();
59                                                         }
60                                                 ],
61                                                 'cmd_clear' : [
62                                                         ['command'],
63                                                         function() {
64                                                                 obj.map_tree = {};
65                                                                 obj.list.clear();
66                                                         }
67                                                 ],
68                                                 'sel_mark_items_damaged' : [
69                                                         ['command'],
70                                                         function() {
71                                                                 JSAN.use('cat.util'); JSAN.use('util.functional');
72
73                                                                 var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; });
74
75                                                                 list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; });
76
77                                                                 cat.util.mark_item_damaged( list );
78
79                                                                 obj.refresh_list();
80                                                         }
81                                                 ],
82                                                 'sel_mark_items_missing' : [
83                                                         ['command'],
84                                                         function() {
85                                                                 JSAN.use('cat.util'); JSAN.use('util.functional');
86
87                                                                 var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; });
88
89                                                                 list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; });
90
91                                                                 cat.util.mark_item_missing( list );
92
93                                                                 obj.refresh_list();
94                                                         }
95                                                 ],
96                                                 'sel_patron' : [
97                                                         ['command'],
98                                                         function() {
99                                                                 JSAN.use('util.functional');
100
101                                                                 var list = util.functional.filter_list(
102                                                                         obj.sel_list,
103                                                                         function (o) {
104                                                                                 return o.split(/_/)[0] == 'acp';
105                                                                         }
106                                                                 );
107
108                                                                 list = util.functional.map_list(
109                                                                         list,
110                                                                         function (o) {
111                                                                                 return { 'copy_id' : o.split(/_/)[1] };
112                                                                         }
113                                                                 );
114                                                                 
115                                                                 JSAN.use('circ.util');
116                                                                 circ.util.show_last_few_circs(list);
117                                                         }
118                                                 ],
119                                                 'sel_copy_details' : [
120                                                         ['command'],
121                                                         function() {
122                                                                 JSAN.use('util.functional');
123
124                                                                 var list = util.functional.filter_list(
125                                                                         obj.sel_list,
126                                                                         function (o) {
127                                                                                 return o.split(/_/)[0] == 'acp';
128                                                                         }
129                                                                 );
130
131                                                                 list = util.functional.map_list(
132                                                                         list,
133                                                                         function (o) {
134                                                                                 return o.split(/_/)[1];
135                                                                         }
136                                                                 );
137         
138                                                                 JSAN.use('circ.util');
139                                                                 for (var i = 0; i < list.length; i++) {
140                                                                         circ.util.show_copy_details( list[i] );
141                                                                 }
142                                                         }
143                                                 ],
144                                                 'cmd_add_items' : [
145                                                         ['command'],
146                                                         function() {
147                                                                 try {
148                                                                         JSAN.use('util.functional');
149                                                                         var list = util.functional.map_list(
150                                                                                 util.functional.filter_list(
151                                                                                         obj.sel_list,
152                                                                                         function (o) {
153                                                                                                 return o.split(/_/)[0] == 'acn';
154                                                                                         }
155                                                                                 ),
156                                                                                 function (o) {
157                                                                                         return o.split(/_/)[1];
158                                                                                 }
159                                                                         );
160                                                                         if (list.length == 0) return;
161
162                                                                         var copy_shortcut = {};
163                                                                         list = util.functional.map_list(
164                                                                                 list,
165                                                                                 function (o) {
166                                                                                         var ou_id = obj.map_acn['acn_' + o].owning_lib();
167                                                                                         var volume_id = o;
168                                                                                         var label = obj.map_acn['acn_' + o].label();
169                                                                                         if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {};
170                                                                                         copy_shortcut[ou_id][ label ] = volume_id;
171
172                                                                                         return ou_id;
173                                                                                 }
174                                                                         );
175                                                                         /* quick fix */  /* what was this fixing? */
176                                                                         list = []; for (var i in copy_shortcut) { list.push( i ); }
177
178                                                                         var edit = 0;
179                                                                         try {
180                                                                                 edit = obj.network.request(
181                                                                                         api.PERM_MULTI_ORG_CHECK.app,
182                                                                                         api.PERM_MULTI_ORG_CHECK.method,
183                                                                                         [ 
184                                                                                                 ses(), 
185                                                                                                 obj.data.list.au[0].id(), 
186                                                                                                 list,
187                                                                                                 [ 'CREATE_COPY' ]
188                                                                                         ]
189                                                                                 ).length == 0 ? 1 : 0;
190                                                                         } catch(E) {
191                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
192                                                                         }
193
194                                                                         if (edit==0) return; // no read-only view for this interface
195
196                                                                         var title = 'Add Item';
197
198                                                                         JSAN.use('util.window'); var win = new util.window();
199                                                                         var w = win.open(
200                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
201                                                                                         +'?doc_id=' + window.escape(obj.docid)
202                                                                                         +'&ou_ids=' + window.escape( js2JSON(list) )
203                                                                                         +'&copy_shortcut=' + window.escape( js2JSON(copy_shortcut) ),
204                                                                                 title,
205                                                                                 'chrome,resizable'
206                                                                         );
207                                                                         w.refresh = function() { obj.refresh_list(); }
208                                                                 } catch(E) {
209                                                                         obj.error.standard_unexpected_error_alert('copy browser -> add copies',E);
210                                                                 }
211                                                         }
212                                                 ],
213                                                 'cmd_add_items_to_buckets' : [
214                                                         ['command'],
215                                                         function() {
216                                                                 try {
217                                                                         JSAN.use('util.functional');
218
219                                                                         var list = util.functional.filter_list(
220                                                                                 obj.sel_list,
221                                                                                 function (o) {
222                                                                                         return o.split(/_/)[0] == 'acp';
223                                                                                 }
224                                                                         );
225
226                                                                         list = util.functional.map_list(
227                                                                                 list,
228                                                                                 function (o) {
229                                                                                         return o.split(/_/)[1];
230                                                                                 }
231                                                                         );
232                                                                 
233                                                                         JSAN.use('cat.util');
234                                                                         cat.util.add_copies_to_bucket( list );
235
236                                                                 } catch(E) {
237                                                                         obj.error.standard_unexpected_error_alert('copy browser -> add copies to bucket',E);
238                                                                 }
239                                                         }
240                                                 ],
241                                                 'cmd_replace_barcode' : [
242                                                         ['command'],
243                                                         function() {
244                                                                 try {
245                                                                         JSAN.use('util.functional');
246
247                                                                         var list = util.functional.filter_list(
248                                                                                 obj.sel_list,
249                                                                                 function (o) {
250                                                                                         return o.split(/_/)[0] == 'acp';
251                                                                                 }
252                                                                         );
253
254                                                                         list = util.functional.map_list(
255                                                                                 list,
256                                                                                 function (o) {
257                                                                                         return obj.map_acp[ o ].barcode();
258                                                                                 }
259                                                                         );
260
261                                                                         JSAN.use('cat.util');
262                                                                         for (var i = 0; i < list.length; i++) {
263                                                                                 try {
264                                                                                         cat.util.replace_barcode(list[i]);
265                                                                                 } catch(E) {
266                                                                                         obj.error.standard_unexpected_error_alert('Barcode ' +list[i] + ' not likely replaced.',E);
267                                                                                 }
268                                                                         }
269                                                                         obj.refresh_list();
270
271                                                                 } catch(E) {
272                                                                         obj.error.standard_unexpected_error_alert('copy browser -> replace barcode',E);
273                                                                         obj.refresh_list();
274                                                                 }
275                                                         }
276                                                 ],
277                                                 'cmd_edit_items' : [
278                                                         ['command'],
279                                                         function() {
280                                                                 try {
281                                                                         JSAN.use('util.functional');
282
283                                                                         var list = util.functional.filter_list(
284                                                                                 obj.sel_list,
285                                                                                 function (o) {
286                                                                                         return o.split(/_/)[0] == 'acp';
287                                                                                 }
288                                                                         );
289
290                                                                         list = util.functional.map_list(
291                                                                                 list,
292                                                                                 function (o) {
293                                                                                         return o.split(/_/)[1];
294                                                                                 }
295                                                                         );
296
297                                                                         var edit = 0;
298                                                                         try {
299                                                                                 edit = obj.network.request(
300                                                                                         api.PERM_MULTI_ORG_CHECK.app,
301                                                                                         api.PERM_MULTI_ORG_CHECK.method,
302                                                                                         [ 
303                                                                                                 ses(), 
304                                                                                                 obj.data.list.au[0].id(), 
305                                                                                                 util.functional.map_list(
306                                                                                                         list,
307                                                                                                         function (o) {
308                                                                                                                 var o_acp = obj.map_acp[ 'acp_' + o ];
309                                                                                                                 if (o_acp.call_number() == -1) {
310                                                                                                                         return o_acp.circ_lib();
311                                                                                                                 } else {
312                                                                                                                         return obj.map_acn[ 'acn_' + o_acp.call_number() ].owning_lib();
313                                                                                                                 }
314                                                                                                         }
315                                                                                                 ),
316                                                                                                 list.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
317                                                                                         ]
318                                                                                 ).length == 0 ? 1 : 0;
319                                                                         } catch(E) {
320                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
321                                                                         }
322
323                                                                         JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
324                                                                         obj.refresh_list();
325
326                                                                 } catch(E) {
327                                                                         obj.error.standard_unexpected_error_alert('Copy Browser -> Edit Items',E);
328                                                                 }
329                                                         }
330                                                 ],
331                                                 'cmd_delete_items' : [
332                                                         ['command'],
333                                                         function() {
334                                                                 try {
335                                                                         JSAN.use('util.functional');
336
337                                                                         var list = util.functional.filter_list(
338                                                                                 obj.sel_list,
339                                                                                 function (o) {
340                                                                                         return o.split(/_/)[0] == 'acp';
341                                                                                 }
342                                                                         );
343
344                                                                         list = util.functional.map_list(
345                                                                                 list,
346                                                                                 function (o) {
347                                                                                         return JSON2js( js2JSON( obj.map_acp[ 'acp_' + o.split(/_/)[1] ] ) );
348                                                                                 }
349                                                                         );
350
351                                                                         var r = obj.error.yns_alert('Are you sure you would like to delete ' + (list.length != 1 ? 'these ' + list.length + ' items' : 'this one item') + '?', 'Delete Items?', 'Delete', 'Cancel', null, 'Check here to confirm this action');
352
353                                                                         if (r == 0) {
354                                                                                 var acn_hash = {}; var acn_list = [];
355                                                                                 for (var i = 0; i < list.length; i++) {
356                                                                                         list[i].isdeleted('1');
357                                                                                         var acn_id = list[i].call_number();
358                                                                                         if ( ! acn_hash[ acn_id ] ) {
359                                                                                                 acn_hash[ acn_id ] = obj.map_acn[ 'acn_' + acn_id ];
360                                                                                                 acn_hash[ acn_id ].copies( [] );
361                                                                                         }
362                                                                                         var temp = acn_hash[ acn_id ].copies();
363                                                                                         temp.push( list[i] );
364                                                                                         acn_hash[ acn_id ].copies( temp );
365                                                                                 }
366                                                                                 for (var i in acn_hash) acn_list.push( acn_hash[i] );
367                                                                                 var robj = obj.network.simple_request(
368                                                                                         'FM_ACN_TREE_UPDATE', 
369                                                                                         [ ses(), acn_list, true ],
370                                                                                         null,
371                                                                                         {
372                                                                                                 'title' : 'Override Delete Failure?',
373                                                                                                 'overridable_events' : [
374                                                                                                         1208 /* TITLE_LAST_COPY */
375                                                                                                 ]
376                                                                                         }
377                                                                                 );
378                                                                                 if (robj == null) throw(robj);
379                                                                                 if (typeof robj.ilsevent != 'undefined') {
380                                                                                         if ( (robj.ilsevent != 0) && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */) ) throw(robj);
381                                                                                 }
382                                                                                 alert('Action complete.');
383                                                                                 obj.refresh_list();
384                                                                         }
385
386                                                                         
387                                                                 } catch(E) {
388                                                                         obj.error.standard_unexpected_error_alert('copy browser -> delete items',E);
389                                                                         obj.refresh_list();
390                                                                 }
391                                                         }
392                                                 ],
393                                                 'cmd_print_spine_labels' : [
394                                                         ['command'],
395                                                         function() {
396                                                                 try {
397                                                                         JSAN.use('util.functional');
398                                                                         
399                                                                         var list = util.functional.filter_list(
400                                                                                 obj.sel_list,
401                                                                                 function (o) {
402                                                                                         return o.split(/_/)[0] == 'acp';
403                                                                                 }
404                                                                         );
405
406                                                                         list = util.functional.map_list(
407                                                                                 list,
408                                                                                 function (o) {
409                                                                                         return obj.map_acp[ o ];
410                                                                                 }
411                                                                         );
412
413                                                                         obj.data.temp_barcodes_for_labels = util.functional.map_list( list, function(o){return o.barcode();}) ; 
414                                                                         obj.data.stash('temp_barcodes_for_labels');
415                                                                         xulG.new_tab(
416                                                                                 xulG.url_prefix( urls.XUL_SPINE_LABEL ),
417                                                                                 { 'tab_name' : 'Spine Labels' },
418                                                                                 {}
419                                                                         );
420                                                                 } catch(E) {
421                                                                         obj.error.standard_unexpected_error_alert('copy browser -> Spine Labels',E);
422                                                                 }
423                                                         }
424                                                 ],
425                                                 'cmd_add_volumes' : [
426                                                         ['command'],
427                                                         function() {
428                                                                 try {
429                                                                         JSAN.use('util.functional');
430                                                                         var list = util.functional.filter_list(
431                                                                                 obj.sel_list,
432                                                                                 function (o) {
433                                                                                         return o.split(/_/)[0] == 'aou';
434                                                                                 }
435                                                                         );
436                                                                         list = util.functional.map_list(
437                                                                                 list,
438                                                                                 function (o) {
439                                                                                         return o.split(/_/)[1];
440                                                                                 }
441                                                                         );              
442                                                                         var edit = 0;
443                                                                         try {
444                                                                                 edit = obj.network.request(
445                                                                                         api.PERM_MULTI_ORG_CHECK.app,
446                                                                                         api.PERM_MULTI_ORG_CHECK.method,
447                                                                                         [ 
448                                                                                                 ses(), 
449                                                                                                 obj.data.list.au[0].id(), 
450                                                                                                 list,
451                                                                                                 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
452                                                                                         ]
453                                                                                 ).length == 0 ? 1 : 0;
454                                                                         } catch(E) {
455                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
456                                                                         }
457
458                                                                         if (edit==0) {
459                                                                                 alert("You don't have permission to add volumes to that library.");
460                                                                                 return; // no read-only view for this interface
461                                                                         }
462
463                                                                         var title = 'Add Volume/Item';
464
465                                                                         JSAN.use('util.window'); var win = new util.window();
466                                                                         var w = win.open(
467                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
468                                                                                         +'?doc_id=' + window.escape(obj.docid)
469                                                                                         +'&ou_ids=' + window.escape( js2JSON(list) ),
470                                                                                 title,
471                                                                                 'chrome,resizable'
472                                                                         );
473
474                                                                         w.refresh = function() { obj.refresh_list() };
475                                                                 } catch(E) {
476                                                                         obj.error.standard_unexpected_error_alert('copy browser -> add volumes',E);
477                                                                 }
478                                                         }
479                                                 ],
480                                                 'cmd_edit_volumes' : [
481                                                         ['command'],
482                                                         function() {
483                                                                 try {
484                                                                         JSAN.use('util.functional');
485                                                                         var list = util.functional.map_list(
486                                                                                 util.functional.filter_list(
487                                                                                         obj.sel_list,
488                                                                                         function (o) {
489                                                                                                 return o.split(/_/)[0] == 'acn';
490                                                                                         }
491                                                                                 ),
492                                                                                 function (o) {
493                                                                                         return o.split(/_/)[1];
494                                                                                 }
495                                                                         );
496                                                                         if (list.length == 0) return;
497
498                                                                         var edit = 0;
499                                                                         try {
500                                                                                 edit = obj.network.request(
501                                                                                         api.PERM_MULTI_ORG_CHECK.app,
502                                                                                         api.PERM_MULTI_ORG_CHECK.method,
503                                                                                         [ 
504                                                                                                 ses(), 
505                                                                                                 obj.data.list.au[0].id(), 
506                                                                                                 util.functional.map_list(
507                                                                                                         list,
508                                                                                                         function (o) {
509                                                                                                                 return obj.map_acn[ 'acn_' + o ].owning_lib();
510                                                                                                         }
511                                                                                                 ),
512                                                                                                 [ 'UPDATE_VOLUME' ]
513                                                                                         ]
514                                                                                 ).length == 0 ? 1 : 0;
515                                                                         } catch(E) {
516                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
517                                                                         }
518
519                                                                         if (edit==0) {
520                                                                                 alert("You don't have permission to edit this volume.");
521                                                                                 return; // no read-only view for this interface
522                                                                         }
523
524                                                                         list = util.functional.map_list(
525                                                                                 list,
526                                                                                 function (o) {
527                                                                                         var my_acn = obj.map_acn['acn_' + o];
528                                                                                         return function(r){return r;}(my_acn);
529                                                                                 }
530                                                                         );
531
532                                                                         var title = list.length == 1 ? 'Volume' : 'Volumes';
533
534                                                                         JSAN.use('util.window'); var win = new util.window();
535                                                                         obj.data.volumes_temp = js2JSON( list );
536                                                                         obj.data.stash('volumes_temp');
537                                                                         var w = win.open(
538                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
539                                                                                 title,
540                                                                                 'chrome,modal,resizable'
541                                                                         );
542
543                                                                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
544                                                                         obj.data.stash_retrieve();
545                                                                         var volumes = JSON2js( obj.data.volumes_temp );
546                                                                         obj.error.sdump('D_CAT','in browse, obj.data.temp =\n' + obj.data.temp);
547                                                                         if (volumes=='') return;
548                                                                 
549                                                                         volumes = util.functional.filter_list(
550                                                                                 volumes,
551                                                                                 function (o) {
552                                                                                         return o.ischanged() == '1';
553                                                                                 }
554                                                                         );
555
556                                                                         volumes = util.functional.map_list(
557                                                                                 volumes,
558                                                                                 function (o) {
559                                                                                         o.record( obj.docid ); // staff client 2 did not do this.  Does it matter?
560                                                                                         return o;
561                                                                                 }
562                                                                         );
563
564                                                                         if (volumes.length == 0) return;
565
566                                                                         try {
567                                                                                 var r = obj.network.request(
568                                                                                         api.FM_ACN_TREE_UPDATE.app,
569                                                                                         api.FM_ACN_TREE_UPDATE.method,
570                                                                                         [ ses(), volumes, true ]
571                                                                                 );
572                                                                                 if (typeof r.ilsevent != 'undefined') throw(r);
573                                                                                 alert('Volumes modified.');
574                                                                         } catch(E) {
575                                                                                 obj.error.standard_unexpected_error_alert('volume update error: ',E);
576                                                                         }
577                                                                         obj.refresh_list();
578
579                                                                 } catch(E) {
580                                                                         obj.error.standard_unexpected_error_alert('Copy Browser -> Volume Edit',E);
581                                                                 }
582                                                         }
583                                                 ],
584                                                 'cmd_delete_volumes' : [
585                                                         ['command'],
586                                                         function() {
587                                                                 try {
588                                                                         JSAN.use('util.functional');
589
590                                                                         var list = util.functional.filter_list(
591                                                                                 obj.sel_list,
592                                                                                 function (o) {
593                                                                                         return o.split(/_/)[0] == 'acn';
594                                                                                 }
595                                                                         );
596
597                                                                         list = util.functional.map_list(
598                                                                                 list,
599                                                                                 function (o) {
600                                                                                         return JSON2js( js2JSON( obj.map_acn[ 'acn_' + o.split(/_/)[1] ] ) );
601                                                                                 }
602                                                                         );
603
604                                                                         var r = obj.error.yns_alert('Are you sure you would like to delete ' + (list.length != 1 ? 'these ' + list.length + ' volumes' : 'this one volume') + '?', 'Delete Volumes?', 'Delete', 'Cancel', null, 'Check here to confirm this action');
605
606                                                                         if (r == 0) {
607                                                                                 for (var i = 0; i < list.length; i++) {
608                                                                                         list[i].isdeleted('1');
609                                                                                 }
610                                                                                 var robj = obj.network.simple_request(
611                                                                                         'FM_ACN_TREE_UPDATE', 
612                                                                                         [ ses(), list, true ],
613                                                                                         null,
614                                                                                         {
615                                                                                                 'title' : 'Override Delete Failure?',
616                                                                                                 'overridable_events' : [
617                                                                                                 ]
618                                                                                         }
619                                                                                 );
620                                                                                 if (robj == null) throw(robj);
621                                                                                 if (typeof robj.ilsevent != 'undefined') {
622                                                                                         if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
623                                                                                                 alert('You must delete all the copies on the volume before you may delete the volume itself.');
624                                                                                                 return;
625                                                                                         }
626                                                                                         if (robj.ilsevent != 0) throw(robj);
627                                                                                 }
628                                                                                 alert('Volumes deleted.');
629                                                                                 obj.refresh_list();
630                                                                         }
631                                                                 } catch(E) {
632                                                                         obj.error.standard_unexpected_error_alert('copy browser -> delete volumes',E);
633                                                                         obj.refresh_list();
634                                                                 }
635
636                                                         }
637                                                 ],
638                                                 'cmd_mark_library' : [
639                                                         ['command'],
640                                                         function() {
641                                                                 try {
642                                                                         var list = util.functional.filter_list(
643                                                                                 obj.sel_list,
644                                                                                 function (o) {
645                                                                                         return o.split(/_/)[0] == 'aou';
646                                                                                 }
647                                                                         );
648
649                                                                         list = util.functional.map_list(
650                                                                                 list,
651                                                                                 function (o) {
652                                                                                         return o.split(/_/)[1];
653                                                                                 }
654                                                                         );
655
656                                                                         if (list.length == 1) {
657                                                                                 obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid };
658                                                                                 obj.data.stash('marked_library');
659                                                                                 alert('Library + Record marked as Volume Transfer Destination');
660                                                                         } else {
661                                                                                 obj.error.yns_alert('Choose just one Library to mark as Volume Transfer Destination','Limit Selection','OK',null,null,'Check here to confirm this dialog');
662                                                                         }
663                                                                 } catch(E) {
664                                                                         obj.error.standard_unexpected_error_alert('copy browser -> mark library',E);
665                                                                 }
666                                                         }
667                                                 ],
668
669                                                 'cmd_mark_volume' : [
670                                                         ['command'],
671                                                         function() {
672                                                                 try {
673                                                                         var list = util.functional.filter_list(
674                                                                                 obj.sel_list,
675                                                                                 function (o) {
676                                                                                         return o.split(/_/)[0] == 'acn';
677                                                                                 }
678                                                                         );
679
680                                                                         list = util.functional.map_list(
681                                                                                 list,
682                                                                                 function (o) {
683                                                                                         return o.split(/_/)[1];
684                                                                                 }
685                                                                         );
686
687                                                                         if (list.length == 1) {
688                                                                                 obj.data.marked_volume = list[0];
689                                                                                 obj.data.stash('marked_volume');
690                                                                                 alert('Volume marked as Item Transfer Destination');
691                                                                         } else {
692                                                                                 obj.error.yns_alert('Choose just one Volume to mark as Item Transfer Destination','Limit Selection','OK',null,null,'Check here to confirm this dialog');
693                                                                         }
694                                                                 } catch(E) {
695                                                                         obj.error.standard_unexpected_error_alert('copy browser -> mark volume',E);
696                                                                 }
697                                                         }
698                                                 ],
699                                                 'cmd_refresh_list' : [
700                                                         ['command'],
701                                                         function() {
702                                                                 obj.refresh_list();
703                                                         }
704                                                 ],
705                                                 'cmd_transfer_volume' : [
706                                                         ['command'],
707                                                         function() {
708                                                                 try {
709                                                                         obj.data.stash_retrieve();
710                                                                         if (!obj.data.marked_library) {
711                                                                                 alert('Please mark a library as the destination from within holdings maintenance and then try this again.');
712                                                                                 return;
713                                                                         }
714                                                                         
715                                                                         JSAN.use('util.functional');
716
717                                                                         var list = util.functional.filter_list(
718                                                                                 obj.sel_list,
719                                                                                 function (o) {
720                                                                                         return o.split(/_/)[0] == 'acn';
721                                                                                 }
722                                                                         );
723
724                                                                         list = util.functional.map_list(
725                                                                                 list,
726                                                                                 function (o) {
727                                                                                         return o.split(/_/)[1];
728                                                                                 }
729                                                                         );
730
731                                                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
732                                                                         var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
733                                                                         xml += '<description>Transfer volumes ';
734
735                                                                         xml += util.functional.map_list(
736                                                                                 list,
737                                                                                 function (o) {
738                                                                                         return obj.map_acn[ 'acn_' + o ].label();
739                                                                                 }
740                                                                         ).join(", ");
741
742                                                                         xml += ' to library ' + obj.data.hash.aou[ obj.data.marked_library.lib ].shortname();
743                                                                         xml += ' on the following record?</description>';
744                                                                         xml += '<hbox><button label="Transfer" name="fancy_submit"/>';
745                                                                         xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
746                                                                         xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
747                                                                         xml += '</vbox>';
748                                                                         obj.data.temp_transfer = xml; obj.data.stash('temp_transfer');
749                                                                         window.open(
750                                                                                 urls.XUL_FANCY_PROMPT
751                                                                                 + '?xml_in_stash=temp_transfer'
752                                                                                 + '&title=' + window.escape('Volume Transfer'),
753                                                                                 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300'
754                                                                         );
755                                                                         JSAN.use('OpenILS.data');
756                                                                         var data = new OpenILS.data(); data.init({'via':'stash'});
757                                                                         if (data.fancy_prompt_data == '') { alert('Transfer Aborted'); return; }
758
759                                                                         var robj = obj.network.simple_request(
760                                                                                 'FM_ACN_TRANSFER', 
761                                                                                 [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'volumes' : list } ],
762                                                                                 null,
763                                                                                 {
764                                                                                         'title' : 'Override Volume Transfer Failure?',
765                                                                                         'overridable_events' : [
766                                                                                                 1208 /* TITLE_LAST_COPY */,
767                                                                                                 1219 /* COPY_REMOTE_CIRC_LIB */,
768                                                                                         ],
769                                                                                 }
770                                                                         );
771
772                                                                         if (typeof robj.ilsevent != 'undefined') {
773                                                                                 if (robj.ilsevent == 1221 /* ORG_CANNOT_HAVE_VOLS */) {
774                                                                                         alert('That destination cannot have volumes.');
775                                                                                 } else {
776                                                                                         throw(robj);
777                                                                                 }
778                                                                         } else {
779                                                                                 alert('Volumes transferred.');
780                                                                         }
781
782                                                                 } catch(E) {
783                                                                         obj.error.standard_unexpected_error_alert('All volumes not likely transferred.',E);
784                                                                 }
785                                                                 obj.refresh_list();
786                                                         }
787                                                 ],
788
789                                                 'cmd_transfer_items' : [
790                                                         ['command'],
791                                                         function() {
792                                                                 try {
793                                                                         obj.data.stash_retrieve();
794                                                                         if (!obj.data.marked_volume) {
795                                                                                 alert('Please mark a volume as the destination from within holdings maintenance and then try this again.');
796                                                                                 return;
797                                                                         }
798                                                                         
799                                                                         JSAN.use('util.functional');
800
801                                                                         var list = util.functional.filter_list(
802                                                                                 obj.sel_list,
803                                                                                 function (o) {
804                                                                                         return o.split(/_/)[0] == 'acp';
805                                                                                 }
806                                                                         );
807
808                                                                         list = util.functional.map_list(
809                                                                                 list,
810                                                                                 function (o) {
811                                                                                         return o.split(/_/)[1];
812                                                                                 }
813                                                                         );
814
815                                                                         var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
816
817                                                                         JSAN.use('cat.util'); cat.util.transfer_copies( { 
818                                                                                 'copy_ids' : list, 
819                                                                                 'docid' : volume.record(),
820                                                                                 'volume_label' : volume.label(),
821                                                                                 'owning_lib' : volume.owning_lib(),
822                                                                         } );
823
824                                                                 } catch(E) {
825                                                                         obj.error.standard_unexpected_error_alert('All copies not likely transferred.',E);
826                                                                 }
827                                                                 obj.refresh_list();
828                                                         }
829                                                 ],
830                                         }
831                                 }
832                         );
833
834                         obj.list_init(params);
835
836                         obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
837
838                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
839                         //obj.show_libs( org );
840
841                         //obj.show_my_libs();
842
843                         JSAN.use('util.file'); JSAN.use('util.widgets');
844
845                         var file; var list_data; var ml; 
846
847                         file = new util.file('offline_ou_list'); 
848                         if (file._file.exists()) {
849                                 list_data = file.get_object(); file.close();
850                                 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
851                                 ml.setAttribute('id','lib_menu'); document.getElementById('x_lib_menu').appendChild(ml);
852                                 for (var i = 0; i < obj.org_ids.length; i++) {
853                                         ml.getElementsByAttribute('value',obj.org_ids[i])[0].setAttribute('class','has_copies');
854                                 }
855                                 ml.firstChild.addEventListener(
856                                         'popupshown',
857                                         function(ev) {
858                                                 document.getElementById('legend').setAttribute('hidden','false');
859                                         },
860                                         false
861                                 );
862                                 ml.firstChild.addEventListener(
863                                         'popuphidden',
864                                         function(ev) {
865                                                 document.getElementById('legend').setAttribute('hidden','true');
866                                         },
867                                         false
868                                 );
869                                 ml.addEventListener(
870                                         'command',
871                                         function(ev) {
872                                                 //obj.show_my_libs(ev.target.value);
873                                                 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs');
874                                                 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
875                                                 obj.refresh_list();
876                                         },
877                                         false
878                                 );
879                         } else {
880                                 throw('Missing library list.\n');
881                         }
882
883                         JSAN.use('util.widgets'); 
884                 
885                         file = new util.file('copy_browser_prefs');
886                         util.widgets.load_attributes(file);
887                         ml.value = ml.getAttribute('value');
888
889                         document.getElementById('show_acns').addEventListener(
890                                 'command',
891                                 function(ev) {
892                                         JSAN.use('util.file'); var file = new util.file('copy_browser_prefs');
893                                         util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
894                                 },
895                                 false
896                         );
897
898                         document.getElementById('show_acps').addEventListener(
899                                 'command',
900                                 function(ev) {
901                                         JSAN.use('util.file'); var file = new util.file('copy_browser_prefs');
902                                         util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
903                                 },
904                                 false
905                         );
906
907                         obj.show_my_libs( ml.value );
908
909                 } catch(E) {
910                         this.error.sdump('D_ERROR','cat.copy_browser.init: ' + E + '\n');
911                 }
912         },
913
914         'show_my_libs' : function(org) {
915                 var obj = this;
916                 try {
917                         if (!org) {
918                                 org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
919                         } else {
920                                 if (typeof org != 'object') org = obj.data.hash.aou[ org ];
921                         }
922                         obj.show_libs( org, true );
923                 
924                         var p_org = obj.data.hash.aou[ org.parent_ou() ];
925                         if (p_org) {
926                                 JSAN.use('util.exec'); var exec = new util.exec();
927                                 var funcs = [];
928                                 funcs.push( function() { 
929                                         document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
930                                         document.getElementById('lib_menu').setAttribute('disabled','true'); 
931                                 } );
932                                 for (var i = 0; i < p_org.children().length; i++) {
933                                         funcs.push(
934                                                 function(o) {
935                                                         return function() {
936                                                                 obj.show_libs( o, true );
937                                                         }
938                                                 }( p_org.children()[i] )
939                                         );
940                                 }
941                                 funcs.push( function() { 
942                                         document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
943                                         document.getElementById('lib_menu').setAttribute('disabled','false'); 
944                                 } );
945                                 exec.chain( funcs );
946                         }
947                 } catch(E) {
948                         alert(E);
949                 }
950         },
951
952         'show_all_libs' : function() {
953                 var obj = this;
954                 try {
955                         obj.show_my_libs();
956
957                         obj.show_libs( obj.data.tree.aou );
958
959                         JSAN.use('util.exec'); var exec = new util.exec();
960                         var funcs = [];
961                         funcs.push( function() { 
962                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
963                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
964                         } );
965
966                         for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
967                                 funcs.push(
968                                         function(o) {
969                                                 return function() {
970                                                         obj.show_libs( o );
971                                                 }
972                                         }( obj.data.tree.aou.children()[i] )
973                                 );
974                         }
975                         funcs.push( function() { 
976                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
977                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
978                         } );
979
980                         exec.chain( funcs );
981                 } catch(E) {
982                         alert(E);
983                 }
984         },
985
986         'show_libs_with_copies' : function() {
987                 var obj = this;
988                 try {
989                         JSAN.use('util.exec'); var exec = new util.exec();
990                         JSAN.use('util.functional');
991
992                         var orgs = util.functional.map_list(
993                                 obj.org_ids,
994                                 function(id) { return obj.data.hash.aou[id]; }
995                         ).sort(
996                                 function( a, b ) {
997                                         if (a.shortname() < b.shortname()) return -1;
998                                         if (a.shortname() > b.shortname()) return 1;
999                                         return 0;
1000                                 }
1001                         );
1002                         var funcs = [];
1003                         funcs.push( function() { 
1004                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1005                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1006                         } );
1007
1008                         for (var i = 0; i < orgs.length; i++) {
1009                                 funcs.push(
1010                                         function(o) {
1011                                                 return function() {
1012                                                         obj.show_libs(o,true);
1013                                                 }
1014                                         }( orgs[i] )
1015                                 );
1016                         }
1017                         funcs.push( function() { 
1018                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1019                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1020                         } );
1021
1022                         exec.chain( funcs );
1023                 } catch(E) {
1024                         alert(E);
1025                 }
1026         },
1027
1028         'show_libs' : function(start_aou,show_open) {
1029                 var obj = this;
1030                 try {
1031                         if (!start_aou) throw('show_libs: Need a start_aou');
1032                         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1033                         JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
1034
1035                         var funcs = [];
1036
1037                         var parents = [];
1038                         var temp_aou = start_aou;
1039                         while ( temp_aou.parent_ou() ) {
1040                                 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
1041                                 parents.push( temp_aou );
1042                         }
1043                         parents.reverse();
1044
1045                         for (var i = 0; i < parents.length; i++) {
1046                                 funcs.push(
1047                                         function(o,p) {
1048                                                 return function() { 
1049                                                         if (show_open) {
1050                                                                 obj.append_org(o,p,{'container':'true','open':'true'}); 
1051                                                         } else {
1052                                                                 obj.append_org(o,p,{'container':'true'}); 
1053                                                         }
1054                                                 };
1055                                         }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
1056                                 );
1057                         }
1058
1059                         funcs.push(
1060                                 function(o,p) {
1061                                         return function() { obj.append_org(o,p); };
1062                                 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
1063                         );
1064
1065                         funcs.push(
1066                                 function() {
1067                                         if (start_aou.children()) {
1068                                                 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
1069                                                 x.setAttribute('container','true');
1070                                                 if (show_open) x.setAttribute('open','true');
1071                                                 for (var i = 0; i < start_aou.children().length; i++) {
1072                                                         funcs.push(
1073                                                                 function(o,p) {
1074                                                                         return function() { obj.append_org(o,p); };
1075                                                                 }( start_aou.children()[i], start_aou )
1076                                                         );
1077                                                 }
1078                                         }
1079                                 }
1080                         );
1081
1082                         exec.chain( funcs );
1083
1084                 } catch(E) {
1085                         alert(E);
1086                 }
1087         },
1088
1089         'on_select' : function(list,twisty) {
1090                 var obj = this;
1091                 for (var i = 0; i < list.length; i++) {
1092                         var node = obj.map_tree[ list[i] ];
1093                         //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
1094                         var row_type = list[i].split('_')[0];
1095                         var id = list[i].split('_')[1];
1096                         switch(row_type) {
1097                                 case 'aou' : obj.on_select_org(id,twisty); break;
1098                                 case 'acn' : obj.on_select_acn(id,twisty); break;
1099                                 default: break;
1100                         }
1101                 }
1102         },
1103
1104         'on_select_acn' : function(acn_id,twisty) {
1105                 var obj = this;
1106                 try {
1107                         var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
1108                         var funcs = [];
1109                         funcs.push( function() { 
1110                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1111                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1112                         } );
1113                         if (acn_tree.copies()) {
1114                                 for (var i = 0; i < acn_tree.copies().length; i++) {
1115                                         funcs.push(
1116                                                 function(c,a) {
1117                                                         return function() {
1118                                                                 obj.append_acp(c,a);
1119                                                         }
1120                                                 }( acn_tree.copies()[i], acn_tree )
1121                                         )
1122                                 }
1123                         }
1124                         funcs.push( function() { 
1125                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1126                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1127                         } );
1128                         JSAN.use('util.exec'); var exec = new util.exec();
1129                         exec.chain( funcs );
1130                 } catch(E) {
1131                         alert(E);
1132                 }
1133         },
1134
1135         'on_select_org' : function(org_id,twisty) {
1136                 var obj = this;
1137                 var org = obj.data.hash.aou[ org_id ];
1138                 if (obj.data.hash.aout[ org.ou_type() ].depth() == 0) return; 
1139                 /* otherwise, we'd show every system in the consortia */
1140                 var funcs = [];
1141                 funcs.push( function() { 
1142                         document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1143                         document.getElementById('lib_menu').setAttribute('disabled','true'); 
1144                 } );
1145                 if (org.children()) {
1146                         for (var i = 0; i < org.children().length; i++) {
1147                                 funcs.push(
1148                                         function(o,p) {
1149                                                 return function() {
1150                                                         obj.append_org(o,p)
1151                                                 }
1152                                         }(org.children()[i],org)
1153                                 );
1154                         }
1155                 } 
1156                 if (obj.map_acn[ 'aou_' + org_id ]) {
1157                         for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
1158                                 funcs.push(
1159                                         function(o,a) {
1160                                                 return function() {
1161                                                         obj.append_acn(o,a);
1162                                                 }
1163                                         }( org, obj.map_acn[ 'aou_' + org_id ][i] )
1164                                 );
1165                         }
1166                 }
1167                 funcs.push( function() { 
1168                         document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1169                         document.getElementById('lib_menu').setAttribute('disabled','false'); 
1170                 } );
1171                 JSAN.use('util.exec'); var exec = new util.exec();
1172                 exec.chain( funcs );
1173         },
1174
1175         'append_org' : function (org,parent_org,params) {
1176                 var obj = this;
1177                 try {
1178                         if (obj.map_tree[ 'aou_' + org.id() ]) {
1179                                 var x = obj.map_tree[ 'aou_' + org.id() ];
1180                                 if (params) {
1181                                         for (var i in params) {
1182                                                 x.setAttribute(i,params[i]);
1183                                         }
1184                                 }
1185                                 return x;
1186                         }
1187
1188                         var data = {
1189                                 'row' : {
1190                                         'my' : {
1191                                                 'aou' : org,
1192                                         }
1193                                 },
1194                                 'skip_all_columns_except' : [0,1,2],
1195                                 'retrieve_id' : 'aou_' + org.id(),
1196                         };
1197                 
1198                         var acn_tree_list;
1199                         if ( obj.org_ids.indexOf( org.id() ) == -1 ) {
1200                                 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) {
1201                                         data.row.my.volume_count = '0';
1202                                         data.row.my.copy_count = '<0>';
1203                                 } else {
1204                                         data.row.my.volume_count = '';
1205                                         data.row.my.copy_count = '';
1206                                 }
1207                         } else {
1208                                 var v_count = 0; var c_count = 0;
1209                                 acn_tree_list = obj.network.simple_request(
1210                                         'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
1211                                         [ ses(), obj.docid, [ org.id() ] ]
1212                                 );
1213                                 for (var i = 0; i < acn_tree_list.length; i++) {
1214                                         v_count++;
1215                                         obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
1216                                         var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
1217                                         for (var j = 0; j < copies.length; j++) {
1218                                                 obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
1219                                         }
1220                                 }
1221                                 data.row.my.volume_count = v_count;
1222                                 data.row.my.copy_count = '<' + c_count + '>';
1223                         }
1224                         if (parent_org) {
1225                                 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1226                         }
1227
1228                         var node = obj.list.append(data);
1229                         if (params) {
1230                                 for (var i in params) {
1231                                         node.setAttribute(i,params[i]);
1232                                 }
1233                         }
1234                         obj.map_tree[ 'aou_' + org.id() ] = node;
1235
1236                         if (org.children()) {
1237                                 node.setAttribute('container','true');
1238                         }
1239
1240                         if (parent_org) {
1241                                 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1242                                         data.node.setAttribute('open','true');
1243                                 }
1244                         } else {
1245                                 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1246                         }
1247
1248                         if (acn_tree_list) {
1249                                 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
1250                                 node.setAttribute('container','true');
1251                         }
1252
1253                         if (document.getElementById('show_acns').checked) {
1254                                 if ( obj.data.hash.aout[ org.ou_type() ].depth() != 0 ) {
1255                                         node.setAttribute('open','true');
1256                                         setTimeout( function() { obj.on_select_org( org.id() ); }, 0 );
1257                                 }
1258                         }
1259
1260                 } catch(E) {
1261                         dump(E+'\n');
1262                         alert(E);
1263                 }
1264         },
1265
1266         'append_acn' : function( org, acn_tree, params ) {
1267                 var obj = this;
1268                 try {
1269                         if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
1270                                 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
1271                                 if (params) {
1272                                         for (var i in params) {
1273                                                 x.setAttribute(i,params[i]);
1274                                         }
1275                                 }
1276                                 return x;
1277                         }
1278
1279                         var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1280                         var data = {
1281                                 'row' : {
1282                                         'my' : {
1283                                                 'aou' : org,
1284                                                 'acn' : acn_tree,
1285                                                 'volume_count' : '',
1286                                                 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
1287                                         }
1288                                 },
1289                                 'skip_all_columns_except' : [0,1,2],
1290                                 'retrieve_id' : 'acn_' + acn_tree.id(),
1291                                 'node' : parent_node,
1292                         };
1293                         var node = obj.list.append(data);
1294                         obj.map_tree[ 'acn_' + acn_tree.id() ] =  node;
1295                         if (params) {
1296                                 for (var i in params) {
1297                                         node.setAttribute(i,params[i]);
1298                                 }
1299                         }
1300                         if (acn_tree.copies()) {
1301                                 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
1302                                 node.setAttribute('container','true');
1303                         }
1304                         if (document.getElementById('show_acps').checked) {
1305                                 node.setAttribute('open','true');
1306                                 setTimeout( function() { obj.on_select_acn( acn_tree.id() ); }, 0 );
1307                         }
1308
1309                 } catch(E) {
1310                         dump(E+'\n');
1311                         alert(E);
1312                 }
1313         },
1314
1315         'append_acp' : function( acp_item, acn_tree, params ) {
1316                 var obj = this;
1317                 try {
1318                         if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
1319                                 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
1320                                 if (params) {
1321                                         for (var i in params) {
1322                                                 x.setAttribute(i,params[i]);
1323                                         }
1324                                 }
1325                                 return x;
1326                         }
1327
1328                         var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
1329                         var data = {
1330                                 'row' : {
1331                                         'my' : {
1332                                                 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
1333                                                 'acn' : acn_tree,
1334                                                 'acp' : acp_item,
1335                                                 'volume_count' : '',
1336                                                 'copy_count' : '',
1337                                         }
1338                                 },
1339                                 'retrieve_id' : 'acp_' + acp_item.id(),
1340                                 'node' : parent_node,
1341                         };
1342                         var node = obj.list.append(data);
1343                         obj.map_tree[ 'acp_' + acp_item.id() ] =  node;
1344                         if (params) {
1345                                 for (var i in params) {
1346                                         node.setAttribute(i,params[i]);
1347                                 }
1348                         }
1349
1350                 } catch(E) {
1351                         dump(E+'\n');
1352                         alert(E);
1353                 }
1354         },
1355
1356         'list_init' : function( params ) {
1357
1358                 try {
1359                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1360                         var obj = this;
1361                         
1362                         JSAN.use('circ.util');
1363                         var columns = [
1364                                 {
1365                                         'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
1366                                         'primary' : true, 'hidden' : false, 
1367                                         'render' : 'my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"'
1368                                 },
1369                                 {
1370                                         'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
1371                                         'primary' : false, 'hidden' : false, 
1372                                         'render' : 'my.volume_count'
1373                                 },
1374                                 {
1375                                         'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
1376                                         'primary' : false, 'hidden' : false, 
1377                                         'render' : 'my.copy_count'
1378                                 },
1379                         ].concat(
1380                                 circ.util.columns( 
1381                                         { 
1382                                                 'location' : { 'hidden' : false },
1383                                                 'circ_lib' : { 'hidden' : false },
1384                                                 'owning_lib' : { 'hidden' : false },
1385                                                 'call_number' : { 'hidden' : false },
1386                                                 'due_date' : { 'hidden' : false },
1387                                                 'status' : { 'hidden' : false },
1388                                         },
1389                                         {
1390                                                 'just_these' : [
1391                                                         'due_date',
1392                                                         'owning_lib',
1393                                                         'circ_lib',
1394                                                         'call_number',
1395                                                         'copy_number',
1396                                                         'location',
1397                                                         'barcode',
1398                                                         'loan_duration',
1399                                                         'fine_level',
1400                                                         'circulate',
1401                                                         'holdable',
1402                                                         'opac_visible',
1403                                                         'ref',
1404                                                         'deposit',
1405                                                         'deposit_amount',
1406                                                         'price',
1407                                                         'circ_as_type',
1408                                                         'circ_modifier',
1409                                                         'status',
1410                                                         'alert_message',
1411                                                         'acp_id',
1412                                                 ]
1413                                         }
1414                                 )
1415                         );
1416                         JSAN.use('util.list'); obj.list = new util.list('copy_tree');
1417                         obj.list.init(
1418                                 {
1419                                         'columns' : columns,
1420                                         'map_row_to_columns' : circ.util.std_map_row_to_columns(' '),
1421                                         'retrieve_row' : function(params) {
1422
1423                                                 var row = params.row;
1424
1425                                                 var funcs = [];
1426                                         /*      
1427                                                 if (!row.my.mvr) funcs.push(
1428                                                         function() {
1429
1430                                                                 row.my.mvr = obj.network.request(
1431                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
1432                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
1433                                                                         [ row.my.circ.target_copy() ]
1434                                                                 );
1435
1436                                                         }
1437                                                 );
1438                                                 if (!row.my.acp) {
1439                                                         funcs.push(     
1440                                                                 function() {
1441
1442                                                                         row.my.acp = obj.network.request(
1443                                                                                 api.FM_ACP_RETRIEVE.app,
1444                                                                                 api.FM_ACP_RETRIEVE.method,
1445                                                                                 [ row.my.circ.target_copy() ]
1446                                                                         );
1447
1448                                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1449
1450                                                                 }
1451                                                         );
1452                                                 } else {
1453                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1454                                                 }
1455                                         */
1456                                                 funcs.push(
1457                                                         function() {
1458
1459                                                                 if (typeof params.on_retrieve == 'function') {
1460                                                                         params.on_retrieve(row);
1461                                                                 }
1462
1463                                                         }
1464                                                 );
1465
1466                                                 JSAN.use('util.exec'); var exec = new util.exec();
1467                                                 exec.on_error = function(E) {
1468                                                         var err = 'items chain: ' + js2JSON(E);
1469                                                         obj.error.sdump('D_ERROR',err);
1470                                                         return true; /* keep going */
1471                                                 }
1472                                                 exec.chain( funcs );
1473
1474                                                 return row;
1475                                         },
1476                                         'on_click' : function(ev) {
1477                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1478                                                 var row = {}; var col = {}; var nobj = {};
1479                                                 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
1480                                                 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
1481                                                 var node = obj.list.node.contentView.getItemAtIndex(row.value);
1482                                                 var list = [ node.getAttribute('retrieve_id') ];
1483                                                 if (typeof obj.on_select == 'function') {
1484                                                         obj.on_select(list,true);
1485                                                 }
1486                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1487                                                         window.xulG.on_select(list);
1488                                                 }
1489                                         },
1490                                         'on_select' : function(ev) {
1491                                                 JSAN.use('util.functional');
1492                                                 var sel = obj.list.retrieve_selection();
1493                                                 obj.controller.view.sel_clip.disabled = sel.length < 1;
1494                                                 obj.sel_list = util.functional.map_list(
1495                                                         sel,
1496                                                         function(o) { return o.getAttribute('retrieve_id'); }
1497                                                 );
1498                                                 obj.toggle_actions();
1499                                                 if (typeof obj.on_select == 'function') {
1500                                                         obj.on_select(obj.sel_list);
1501                                                 }
1502                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1503                                                         window.xulG.on_select(obj.sel_list);
1504                                                 }
1505                                         },
1506                                 }
1507                         );
1508
1509                         obj.controller.render();
1510
1511                 } catch(E) {
1512                         this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
1513                         alert(E);
1514                 }
1515         },
1516
1517         'toggle_actions' : function() {
1518                 var obj = this;
1519                 try {
1520                         var found_aou = false; var found_acn = false; var found_acp = false;
1521                         var found_aou_with_can_have_vols = false;
1522                         for (var i = 0; i < obj.sel_list.length; i++) {
1523                                 var type = obj.sel_list[i].split(/_/)[0];
1524                                 switch(type) {
1525                                         case 'aou' : 
1526                                                 found_aou = true; 
1527                                                 var org = obj.data.hash.aou[ obj.sel_list[i].split(/_/)[1] ];
1528                                                 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) found_aou_with_can_have_vols = true;
1529                                         break;
1530                                         case 'acn' : found_acn = true; break;
1531                                         case 'acp' : found_acp = true; break;
1532                                 }
1533                         }
1534                         obj.controller.view.cmd_add_items.setAttribute('disabled','true');
1535                         obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','true');
1536                         obj.controller.view.cmd_edit_items.setAttribute('disabled','true');
1537                         obj.controller.view.cmd_replace_barcode.setAttribute('disabled','true');
1538                         obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
1539                         obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','true');
1540                         obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
1541                         obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1542                         obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
1543                         obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
1544                         obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
1545                         obj.controller.view.cmd_transfer_volume.setAttribute('disabled','true');
1546                         obj.controller.view.cmd_transfer_items.setAttribute('disabled','true');
1547                         obj.controller.view.sel_copy_details.setAttribute('disabled','true');
1548                         obj.controller.view.sel_patron.setAttribute('disabled','true');
1549                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
1550                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
1551                         if (found_aou && found_aou_with_can_have_vols) {
1552                                 obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
1553                                 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1554                         }
1555                         if (found_acn) {
1556                                 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
1557                                 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
1558                                 obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
1559                                 obj.controller.view.cmd_add_items.setAttribute('disabled','false');
1560                                 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','false');
1561                         }
1562                         if (found_acp) {
1563                                 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
1564                                 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
1565                                 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','false');
1566                                 obj.controller.view.cmd_edit_items.setAttribute('disabled','false');
1567                                 obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
1568                                 obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
1569                                 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','false');
1570                                 obj.controller.view.cmd_transfer_items.setAttribute('disabled','false');
1571                                 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
1572                                 obj.controller.view.sel_patron.setAttribute('disabled','false');
1573                         }
1574                 } catch(E) {
1575                         obj.error.standard_unexpected_error_alert('Copy Browser Actions',E);
1576                 }
1577         },
1578
1579         'refresh_list' : function() { 
1580                 try {
1581                         var obj = this;
1582                         obj.list.clear();
1583                         obj.map_tree = {};
1584                         obj.map_acn = {};
1585                         obj.map_acp = {};
1586                         obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
1587                         /*
1588                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1589                         obj.show_libs( org );
1590                         */
1591                         obj.show_my_libs( document.getElementById('lib_menu').value );
1592                 } catch(E) {
1593                         this.error.standard_unexpected_error_alert('Problem refreshing the volume/copy tree.',E);
1594                 }
1595         },
1596 }
1597
1598 dump('exiting cat.copy_browser.js\n');