]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_browser.js
8c31a51937fc87a881c1e1413ea0e5eb8a1ae6b8
[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                                                                                                         1227 /* COPY_DELETE_WARNING */,
376                                                                                                 ]
377                                                                                         }
378                                                                                 );
379                                                                                 if (robj == null) throw(robj);
380                                                                                 if (typeof robj.ilsevent != 'undefined') {
381                                                                                         if ( (robj.ilsevent != 0) && (robj.ilsevent != 1227 /* COPY_DELETE_WARNING */) && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */) ) throw(robj);
382                                                                                 }
383                                                                                 alert('Action complete.');
384                                                                                 obj.refresh_list();
385                                                                         }
386
387                                                                         
388                                                                 } catch(E) {
389                                                                         obj.error.standard_unexpected_error_alert('copy browser -> delete items',E);
390                                                                         obj.refresh_list();
391                                                                 }
392                                                         }
393                                                 ],
394                                                 'cmd_print_spine_labels' : [
395                                                         ['command'],
396                                                         function() {
397                                                                 try {
398                                                                         JSAN.use('util.functional');
399                                                                         
400                                                                         var list = util.functional.filter_list(
401                                                                                 obj.sel_list,
402                                                                                 function (o) {
403                                                                                         return o.split(/_/)[0] == 'acp';
404                                                                                 }
405                                                                         );
406
407                                                                         list = util.functional.map_list(
408                                                                                 list,
409                                                                                 function (o) {
410                                                                                         return obj.map_acp[ o ];
411                                                                                 }
412                                                                         );
413
414                                                                         obj.data.temp_barcodes_for_labels = util.functional.map_list( list, function(o){return o.barcode();}) ; 
415                                                                         obj.data.stash('temp_barcodes_for_labels');
416                                                                         xulG.new_tab(
417                                                                                 xulG.url_prefix( urls.XUL_SPINE_LABEL ),
418                                                                                 { 'tab_name' : 'Spine Labels' },
419                                                                                 {}
420                                                                         );
421                                                                 } catch(E) {
422                                                                         obj.error.standard_unexpected_error_alert('copy browser -> Spine Labels',E);
423                                                                 }
424                                                         }
425                                                 ],
426                                                 'cmd_add_volumes' : [
427                                                         ['command'],
428                                                         function() {
429                                                                 try {
430                                                                         JSAN.use('util.functional');
431                                                                         var list = util.functional.filter_list(
432                                                                                 obj.sel_list,
433                                                                                 function (o) {
434                                                                                         return o.split(/_/)[0] == 'aou';
435                                                                                 }
436                                                                         );
437                                                                         list = util.functional.map_list(
438                                                                                 list,
439                                                                                 function (o) {
440                                                                                         return o.split(/_/)[1];
441                                                                                 }
442                                                                         );              
443                                                                         var edit = 0;
444                                                                         try {
445                                                                                 edit = obj.network.request(
446                                                                                         api.PERM_MULTI_ORG_CHECK.app,
447                                                                                         api.PERM_MULTI_ORG_CHECK.method,
448                                                                                         [ 
449                                                                                                 ses(), 
450                                                                                                 obj.data.list.au[0].id(), 
451                                                                                                 list,
452                                                                                                 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
453                                                                                         ]
454                                                                                 ).length == 0 ? 1 : 0;
455                                                                         } catch(E) {
456                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
457                                                                         }
458
459                                                                         if (edit==0) {
460                                                                                 alert("You don't have permission to add volumes to that library.");
461                                                                                 return; // no read-only view for this interface
462                                                                         }
463
464                                                                         var title = 'Add Volume/Item';
465
466                                                                         JSAN.use('util.window'); var win = new util.window();
467                                                                         var w = win.open(
468                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
469                                                                                         +'?doc_id=' + window.escape(obj.docid)
470                                                                                         +'&ou_ids=' + window.escape( js2JSON(list) ),
471                                                                                 title,
472                                                                                 'chrome,resizable'
473                                                                         );
474
475                                                                         w.refresh = function() { obj.refresh_list() };
476                                                                 } catch(E) {
477                                                                         obj.error.standard_unexpected_error_alert('copy browser -> add volumes',E);
478                                                                 }
479                                                         }
480                                                 ],
481                                                 'cmd_edit_volumes' : [
482                                                         ['command'],
483                                                         function() {
484                                                                 try {
485                                                                         JSAN.use('util.functional');
486                                                                         var list = util.functional.map_list(
487                                                                                 util.functional.filter_list(
488                                                                                         obj.sel_list,
489                                                                                         function (o) {
490                                                                                                 return o.split(/_/)[0] == 'acn';
491                                                                                         }
492                                                                                 ),
493                                                                                 function (o) {
494                                                                                         return o.split(/_/)[1];
495                                                                                 }
496                                                                         );
497                                                                         if (list.length == 0) return;
498
499                                                                         var edit = 0;
500                                                                         try {
501                                                                                 edit = obj.network.request(
502                                                                                         api.PERM_MULTI_ORG_CHECK.app,
503                                                                                         api.PERM_MULTI_ORG_CHECK.method,
504                                                                                         [ 
505                                                                                                 ses(), 
506                                                                                                 obj.data.list.au[0].id(), 
507                                                                                                 util.functional.map_list(
508                                                                                                         list,
509                                                                                                         function (o) {
510                                                                                                                 return obj.map_acn[ 'acn_' + o ].owning_lib();
511                                                                                                         }
512                                                                                                 ),
513                                                                                                 [ 'UPDATE_VOLUME' ]
514                                                                                         ]
515                                                                                 ).length == 0 ? 1 : 0;
516                                                                         } catch(E) {
517                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
518                                                                         }
519
520                                                                         if (edit==0) {
521                                                                                 alert("You don't have permission to edit this volume.");
522                                                                                 return; // no read-only view for this interface
523                                                                         }
524
525                                                                         list = util.functional.map_list(
526                                                                                 list,
527                                                                                 function (o) {
528                                                                                         var my_acn = obj.map_acn['acn_' + o];
529                                                                                         return function(r){return r;}(my_acn);
530                                                                                 }
531                                                                         );
532
533                                                                         var title = list.length == 1 ? 'Volume' : 'Volumes';
534
535                                                                         JSAN.use('util.window'); var win = new util.window();
536                                                                         obj.data.volumes_temp = js2JSON( list );
537                                                                         obj.data.stash('volumes_temp');
538                                                                         var w = win.open(
539                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
540                                                                                 title,
541                                                                                 'chrome,modal,resizable'
542                                                                         );
543
544                                                                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
545                                                                         obj.data.stash_retrieve();
546                                                                         var volumes = JSON2js( obj.data.volumes_temp );
547                                                                         obj.error.sdump('D_CAT','in browse, obj.data.temp =\n' + obj.data.temp);
548                                                                         if (volumes=='') return;
549                                                                 
550                                                                         volumes = util.functional.filter_list(
551                                                                                 volumes,
552                                                                                 function (o) {
553                                                                                         return o.ischanged() == '1';
554                                                                                 }
555                                                                         );
556
557                                                                         volumes = util.functional.map_list(
558                                                                                 volumes,
559                                                                                 function (o) {
560                                                                                         o.record( obj.docid ); // staff client 2 did not do this.  Does it matter?
561                                                                                         return o;
562                                                                                 }
563                                                                         );
564
565                                                                         if (volumes.length == 0) return;
566
567                                                                         try {
568                                                                                 var r = obj.network.request(
569                                                                                         api.FM_ACN_TREE_UPDATE.app,
570                                                                                         api.FM_ACN_TREE_UPDATE.method,
571                                                                                         [ ses(), volumes, true ]
572                                                                                 );
573                                                                                 if (typeof r.ilsevent != 'undefined') throw(r);
574                                                                                 alert('Volumes modified.');
575                                                                         } catch(E) {
576                                                                                 obj.error.standard_unexpected_error_alert('volume update error: ',E);
577                                                                         }
578                                                                         obj.refresh_list();
579
580                                                                 } catch(E) {
581                                                                         obj.error.standard_unexpected_error_alert('Copy Browser -> Volume Edit',E);
582                                                                 }
583                                                         }
584                                                 ],
585                                                 'cmd_delete_volumes' : [
586                                                         ['command'],
587                                                         function() {
588                                                                 try {
589                                                                         JSAN.use('util.functional');
590
591                                                                         var list = util.functional.filter_list(
592                                                                                 obj.sel_list,
593                                                                                 function (o) {
594                                                                                         return o.split(/_/)[0] == 'acn';
595                                                                                 }
596                                                                         );
597
598                                                                         list = util.functional.map_list(
599                                                                                 list,
600                                                                                 function (o) {
601                                                                                         return JSON2js( js2JSON( obj.map_acn[ 'acn_' + o.split(/_/)[1] ] ) );
602                                                                                 }
603                                                                         );
604
605                                                                         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');
606
607                                                                         if (r == 0) {
608                                                                                 for (var i = 0; i < list.length; i++) {
609                                                                                         list[i].isdeleted('1');
610                                                                                 }
611                                                                                 var robj = obj.network.simple_request(
612                                                                                         'FM_ACN_TREE_UPDATE', 
613                                                                                         [ ses(), list, true ],
614                                                                                         null,
615                                                                                         {
616                                                                                                 'title' : 'Override Delete Failure?',
617                                                                                                 'overridable_events' : [
618                                                                                                 ]
619                                                                                         }
620                                                                                 );
621                                                                                 if (robj == null) throw(robj);
622                                                                                 if (typeof robj.ilsevent != 'undefined') {
623                                                                                         if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
624                                                                                                 alert('You must delete all the copies on the volume before you may delete the volume itself.');
625                                                                                                 return;
626                                                                                         }
627                                                                                         if (robj.ilsevent != 0) throw(robj);
628                                                                                 }
629                                                                                 alert('Volumes deleted.');
630                                                                                 obj.refresh_list();
631                                                                         }
632                                                                 } catch(E) {
633                                                                         obj.error.standard_unexpected_error_alert('copy browser -> delete volumes',E);
634                                                                         obj.refresh_list();
635                                                                 }
636
637                                                         }
638                                                 ],
639                                                 'cmd_mark_library' : [
640                                                         ['command'],
641                                                         function() {
642                                                                 try {
643                                                                         var list = util.functional.filter_list(
644                                                                                 obj.sel_list,
645                                                                                 function (o) {
646                                                                                         return o.split(/_/)[0] == 'aou';
647                                                                                 }
648                                                                         );
649
650                                                                         list = util.functional.map_list(
651                                                                                 list,
652                                                                                 function (o) {
653                                                                                         return o.split(/_/)[1];
654                                                                                 }
655                                                                         );
656
657                                                                         if (list.length == 1) {
658                                                                                 obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid };
659                                                                                 obj.data.stash('marked_library');
660                                                                                 alert('Library + Record marked as Volume Transfer Destination');
661                                                                         } else {
662                                                                                 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');
663                                                                         }
664                                                                 } catch(E) {
665                                                                         obj.error.standard_unexpected_error_alert('copy browser -> mark library',E);
666                                                                 }
667                                                         }
668                                                 ],
669
670                                                 'cmd_mark_volume' : [
671                                                         ['command'],
672                                                         function() {
673                                                                 try {
674                                                                         var list = util.functional.filter_list(
675                                                                                 obj.sel_list,
676                                                                                 function (o) {
677                                                                                         return o.split(/_/)[0] == 'acn';
678                                                                                 }
679                                                                         );
680
681                                                                         list = util.functional.map_list(
682                                                                                 list,
683                                                                                 function (o) {
684                                                                                         return o.split(/_/)[1];
685                                                                                 }
686                                                                         );
687
688                                                                         if (list.length == 1) {
689                                                                                 obj.data.marked_volume = list[0];
690                                                                                 obj.data.stash('marked_volume');
691                                                                                 alert('Volume marked as Item Transfer Destination');
692                                                                         } else {
693                                                                                 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');
694                                                                         }
695                                                                 } catch(E) {
696                                                                         obj.error.standard_unexpected_error_alert('copy browser -> mark volume',E);
697                                                                 }
698                                                         }
699                                                 ],
700                                                 'cmd_refresh_list' : [
701                                                         ['command'],
702                                                         function() {
703                                                                 obj.refresh_list();
704                                                         }
705                                                 ],
706                                                 'cmd_transfer_volume' : [
707                                                         ['command'],
708                                                         function() {
709                                                                 try {
710                                                                         obj.data.stash_retrieve();
711                                                                         if (!obj.data.marked_library) {
712                                                                                 alert('Please mark a library as the destination from within holdings maintenance and then try this again.');
713                                                                                 return;
714                                                                         }
715                                                                         
716                                                                         JSAN.use('util.functional');
717
718                                                                         var list = util.functional.filter_list(
719                                                                                 obj.sel_list,
720                                                                                 function (o) {
721                                                                                         return o.split(/_/)[0] == 'acn';
722                                                                                 }
723                                                                         );
724
725                                                                         list = util.functional.map_list(
726                                                                                 list,
727                                                                                 function (o) {
728                                                                                         return o.split(/_/)[1];
729                                                                                 }
730                                                                         );
731
732                                                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
733                                                                         var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
734                                                                         xml += '<description>Transfer volumes ';
735
736                                                                         xml += util.functional.map_list(
737                                                                                 list,
738                                                                                 function (o) {
739                                                                                         return obj.map_acn[ 'acn_' + o ].label();
740                                                                                 }
741                                                                         ).join(", ");
742
743                                                                         xml += ' to library ' + obj.data.hash.aou[ obj.data.marked_library.lib ].shortname();
744                                                                         xml += ' on the following record?</description>';
745                                                                         xml += '<hbox><button label="Transfer" name="fancy_submit"/>';
746                                                                         xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
747                                                                         xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
748                                                                         xml += '</vbox>';
749                                                                         JSAN.use('OpenILS.data');
750                                                                         var data = new OpenILS.data(); data.init({'via':'stash'});
751                                                                         data.temp_transfer = xml; data.stash('temp_transfer');
752                                                                         window.open(
753                                                                                 urls.XUL_FANCY_PROMPT
754                                                                                 + '?xml_in_stash=temp_transfer'
755                                                                                 + '&title=' + window.escape('Volume Transfer'),
756                                                                                 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300'
757                                                                         );
758                                                                         data.init({'via':'stash'});
759
760                                                                         if (data.fancy_prompt_data == '') { alert('Transfer Aborted'); return; }
761
762                                                                         var robj = obj.network.simple_request(
763                                                                                 'FM_ACN_TRANSFER', 
764                                                                                 [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'volumes' : list } ],
765                                                                                 null,
766                                                                                 {
767                                                                                         'title' : 'Override Volume Transfer Failure?',
768                                                                                         'overridable_events' : [
769                                                                                                 1208 /* TITLE_LAST_COPY */,
770                                                                                                 1219 /* COPY_REMOTE_CIRC_LIB */,
771                                                                                         ],
772                                                                                 }
773                                                                         );
774
775                                                                         if (typeof robj.ilsevent != 'undefined') {
776                                                                                 if (robj.ilsevent == 1221 /* ORG_CANNOT_HAVE_VOLS */) {
777                                                                                         alert('That destination cannot have volumes.');
778                                                                                 } else {
779                                                                                         throw(robj);
780                                                                                 }
781                                                                         } else {
782                                                                                 alert('Volumes transferred.');
783                                                                         }
784
785                                                                 } catch(E) {
786                                                                         obj.error.standard_unexpected_error_alert('All volumes not likely transferred.',E);
787                                                                 }
788                                                                 obj.refresh_list();
789                                                         }
790                                                 ],
791
792                                                 'cmd_transfer_items' : [
793                                                         ['command'],
794                                                         function() {
795                                                                 try {
796                                                                         obj.data.stash_retrieve();
797                                                                         if (!obj.data.marked_volume) {
798                                                                                 alert('Please mark a volume as the destination from within holdings maintenance and then try this again.');
799                                                                                 return;
800                                                                         }
801                                                                         
802                                                                         JSAN.use('util.functional');
803
804                                                                         var list = util.functional.filter_list(
805                                                                                 obj.sel_list,
806                                                                                 function (o) {
807                                                                                         return o.split(/_/)[0] == 'acp';
808                                                                                 }
809                                                                         );
810
811                                                                         list = util.functional.map_list(
812                                                                                 list,
813                                                                                 function (o) {
814                                                                                         return o.split(/_/)[1];
815                                                                                 }
816                                                                         );
817
818                                                                         var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
819
820                                                                         JSAN.use('cat.util'); cat.util.transfer_copies( { 
821                                                                                 'copy_ids' : list, 
822                                                                                 'docid' : volume.record(),
823                                                                                 'volume_label' : volume.label(),
824                                                                                 'owning_lib' : volume.owning_lib(),
825                                                                         } );
826
827                                                                 } catch(E) {
828                                                                         obj.error.standard_unexpected_error_alert('All copies not likely transferred.',E);
829                                                                 }
830                                                                 obj.refresh_list();
831                                                         }
832                                                 ],
833                                         }
834                                 }
835                         );
836
837                         obj.list_init(params);
838
839                         obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
840                         if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
841
842                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
843                         //obj.show_libs( org );
844
845                         //obj.show_my_libs();
846
847                         JSAN.use('util.file'); JSAN.use('util.widgets');
848
849                         var file; var list_data; var ml; 
850
851                         file = new util.file('offline_ou_list'); 
852                         if (file._file.exists()) {
853                                 list_data = file.get_object(); file.close();
854                                 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
855                                 ml.setAttribute('id','lib_menu'); document.getElementById('x_lib_menu').appendChild(ml);
856                                 for (var i = 0; i < obj.org_ids.length; i++) {
857                                         ml.getElementsByAttribute('value',obj.org_ids[i])[0].setAttribute('class','has_copies');
858                                 }
859                                 ml.firstChild.addEventListener(
860                                         'popupshown',
861                                         function(ev) {
862                                                 document.getElementById('legend').setAttribute('hidden','false');
863                                         },
864                                         false
865                                 );
866                                 ml.firstChild.addEventListener(
867                                         'popuphidden',
868                                         function(ev) {
869                                                 document.getElementById('legend').setAttribute('hidden','true');
870                                         },
871                                         false
872                                 );
873                                 ml.addEventListener(
874                                         'command',
875                                         function(ev) {
876                                                 //obj.show_my_libs(ev.target.value);
877                                                 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
878                                                 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
879                                                 obj.refresh_list();
880                                         },
881                                         false
882                                 );
883                         } else {
884                                 throw('Missing library list.\n');
885                         }
886
887                         JSAN.use('util.widgets'); 
888                 
889                         file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
890                         util.widgets.load_attributes(file);
891                         ml.value = ml.getAttribute('value');
892                         if (! ml.value) {
893                                 ml.value = org.id();
894                                 ml.setAttribute('value',ml.value);
895                         }
896
897                         document.getElementById('show_acns').addEventListener(
898                                 'command',
899                                 function(ev) {
900                                         JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
901                                         util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
902                                 },
903                                 false
904                         );
905
906                         document.getElementById('show_acps').addEventListener(
907                                 'command',
908                                 function(ev) {
909                                         JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
910                                         util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
911                                 },
912                                 false
913                         );
914
915                         obj.show_my_libs( ml.value );
916
917                 } catch(E) {
918                         this.error.standard_unexpected_error_alert('cat.copy_browser.init: ',E);
919                 }
920         },
921
922         'show_my_libs' : function(org) {
923                 var obj = this;
924                 try {
925                         if (!org) {
926                                 org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
927                         } else {
928                                 if (typeof org != 'object') org = obj.data.hash.aou[ org ];
929                         }
930                         obj.show_libs( org, true );
931                 
932                         var p_org = obj.data.hash.aou[ org.parent_ou() ];
933                         if (p_org) {
934                                 JSAN.use('util.exec'); var exec = new util.exec();
935                                 var funcs = [];
936                                 funcs.push( function() { 
937                                         document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
938                                         document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
939                                         document.getElementById('lib_menu').setAttribute('disabled','true'); 
940                                 } );
941                                 for (var i = 0; i < p_org.children().length; i++) {
942                                         funcs.push(
943                                                 function(o) {
944                                                         return function() {
945                                                                 obj.show_libs( o, true );
946                                                         }
947                                                 }( p_org.children()[i] )
948                                         );
949                                 }
950                                 funcs.push( function() { 
951                                         document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
952                                         document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
953                                         document.getElementById('lib_menu').setAttribute('disabled','false'); 
954                                 } );
955                                 exec.chain( funcs );
956                         }
957                 } catch(E) {
958                         alert(E);
959                 }
960         },
961
962         'show_all_libs' : function() {
963                 var obj = this;
964                 try {
965                         obj.show_my_libs();
966
967                         obj.show_libs( obj.data.tree.aou );
968
969                         JSAN.use('util.exec'); var exec = new util.exec();
970                         var funcs = [];
971                         funcs.push( function() { 
972                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
973                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
974                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
975                         } );
976
977                         for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
978                                 funcs.push(
979                                         function(o) {
980                                                 return function() {
981                                                         obj.show_libs( o );
982                                                 }
983                                         }( obj.data.tree.aou.children()[i] )
984                                 );
985                         }
986                         funcs.push( function() { 
987                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
988                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
989                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
990                         } );
991
992                         exec.chain( funcs );
993                 } catch(E) {
994                         alert(E);
995                 }
996         },
997
998         'show_libs_with_copies' : function() {
999                 var obj = this;
1000                 try {
1001                         JSAN.use('util.exec'); var exec = new util.exec();
1002                         JSAN.use('util.functional');
1003
1004                         var orgs = util.functional.map_list(
1005                                 obj.org_ids,
1006                                 function(id) { return obj.data.hash.aou[id]; }
1007                         ).sort(
1008                                 function( a, b ) {
1009                                         if (a.shortname() < b.shortname()) return -1;
1010                                         if (a.shortname() > b.shortname()) return 1;
1011                                         return 0;
1012                                 }
1013                         );
1014                         var funcs = [];
1015                         funcs.push( function() { 
1016                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1017                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1018                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1019                         } );
1020
1021                         for (var i = 0; i < orgs.length; i++) {
1022                                 funcs.push(
1023                                         function(o) {
1024                                                 return function() {
1025                                                         obj.show_libs(o,true);
1026                                                 }
1027                                         }( orgs[i] )
1028                                 );
1029                         }
1030                         funcs.push( function() { 
1031                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1032                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1033                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1034                         } );
1035
1036                         exec.chain( funcs );
1037                 } catch(E) {
1038                         alert(E);
1039                 }
1040         },
1041
1042         'show_libs' : function(start_aou,show_open) {
1043                 var obj = this;
1044                 try {
1045                         if (!start_aou) throw('show_libs: Need a start_aou');
1046                         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1047                         JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
1048
1049                         var funcs = [];
1050
1051                         var parents = [];
1052                         var temp_aou = start_aou;
1053                         while ( temp_aou.parent_ou() ) {
1054                                 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
1055                                 parents.push( temp_aou );
1056                         }
1057                         parents.reverse();
1058
1059                         for (var i = 0; i < parents.length; i++) {
1060                                 funcs.push(
1061                                         function(o,p) {
1062                                                 return function() { 
1063                                                         if (show_open) {
1064                                                                 obj.append_org(o,p,{'container':'true','open':'true'}); 
1065                                                         } else {
1066                                                                 obj.append_org(o,p,{'container':'true'}); 
1067                                                         }
1068                                                 };
1069                                         }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
1070                                 );
1071                         }
1072
1073                         funcs.push(
1074                                 function(o,p) {
1075                                         return function() { obj.append_org(o,p); };
1076                                 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
1077                         );
1078
1079                         funcs.push(
1080                                 function() {
1081                                         if (start_aou.children()) {
1082                                                 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
1083                                                 x.setAttribute('container','true');
1084                                                 if (show_open) x.setAttribute('open','true');
1085                                                 for (var i = 0; i < start_aou.children().length; i++) {
1086                                                         funcs.push(
1087                                                                 function(o,p) {
1088                                                                         return function() { obj.append_org(o,p); };
1089                                                                 }( start_aou.children()[i], start_aou )
1090                                                         );
1091                                                 }
1092                                         }
1093                                 }
1094                         );
1095
1096                         exec.chain( funcs );
1097
1098                 } catch(E) {
1099                         alert(E);
1100                 }
1101         },
1102
1103         'on_select' : function(list,twisty) {
1104                 var obj = this;
1105                 for (var i = 0; i < list.length; i++) {
1106                         var node = obj.map_tree[ list[i] ];
1107                         //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
1108                         var row_type = list[i].split('_')[0];
1109                         var id = list[i].split('_')[1];
1110                         switch(row_type) {
1111                                 case 'aou' : obj.on_select_org(id,twisty); break;
1112                                 case 'acn' : obj.on_select_acn(id,twisty); break;
1113                                 default: break;
1114                         }
1115                 }
1116         },
1117
1118         'on_select_acn' : function(acn_id,twisty) {
1119                 var obj = this;
1120                 try {
1121                         var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
1122                         var funcs = [];
1123                         funcs.push( function() { 
1124                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1125                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1126                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1127                         } );
1128                         if (acn_tree.copies()) {
1129                                 for (var i = 0; i < acn_tree.copies().length; i++) {
1130                                         funcs.push(
1131                                                 function(c,a) {
1132                                                         return function() {
1133                                                                 obj.append_acp(c,a);
1134                                                         }
1135                                                 }( acn_tree.copies()[i], acn_tree )
1136                                         )
1137                                 }
1138                         }
1139                         funcs.push( function() { 
1140                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1141                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1142                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1143                         } );
1144                         JSAN.use('util.exec'); var exec = new util.exec();
1145                         exec.chain( funcs );
1146                 } catch(E) {
1147                         alert(E);
1148                 }
1149         },
1150
1151         'on_select_org' : function(org_id,twisty) {
1152                 var obj = this;
1153                 var org = obj.data.hash.aou[ org_id ];
1154                 if (obj.data.hash.aout[ org.ou_type() ].depth() == 0) return; 
1155                 /* otherwise, we'd show every system in the consortia */
1156                 var funcs = [];
1157                 funcs.push( function() { 
1158                         document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1159                         document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1160                         document.getElementById('lib_menu').setAttribute('disabled','true'); 
1161                 } );
1162                 if (org.children()) {
1163                         for (var i = 0; i < org.children().length; i++) {
1164                                 funcs.push(
1165                                         function(o,p) {
1166                                                 return function() {
1167                                                         obj.append_org(o,p)
1168                                                 }
1169                                         }(org.children()[i],org)
1170                                 );
1171                         }
1172                 } 
1173                 if (obj.map_acn[ 'aou_' + org_id ]) {
1174                         for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
1175                                 funcs.push(
1176                                         function(o,a) {
1177                                                 return function() {
1178                                                         obj.append_acn(o,a);
1179                                                 }
1180                                         }( org, obj.map_acn[ 'aou_' + org_id ][i] )
1181                                 );
1182                         }
1183                 }
1184                 funcs.push( function() { 
1185                         document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1186                         document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1187                         document.getElementById('lib_menu').setAttribute('disabled','false'); 
1188                 } );
1189                 JSAN.use('util.exec'); var exec = new util.exec();
1190                 exec.chain( funcs );
1191         },
1192
1193         'append_org' : function (org,parent_org,params) {
1194                 var obj = this;
1195                 try {
1196                         if (obj.map_tree[ 'aou_' + org.id() ]) {
1197                                 var x = obj.map_tree[ 'aou_' + org.id() ];
1198                                 if (params) {
1199                                         for (var i in params) {
1200                                                 x.setAttribute(i,params[i]);
1201                                         }
1202                                 }
1203                                 return x;
1204                         }
1205
1206                         var data = {
1207                                 'row' : {
1208                                         'my' : {
1209                                                 'aou' : org,
1210                                         }
1211                                 },
1212                                 'skip_all_columns_except' : [0,1,2],
1213                                 'retrieve_id' : 'aou_' + org.id(),
1214                                 'to_bottom' : true,
1215                                 'no_auto_select' : true,
1216                         };
1217                 
1218                         var acn_tree_list;
1219                         if ( obj.org_ids.indexOf( org.id() ) == -1 ) {
1220                                 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) {
1221                                         data.row.my.volume_count = '0';
1222                                         data.row.my.copy_count = '<0>';
1223                                 } else {
1224                                         data.row.my.volume_count = '';
1225                                         data.row.my.copy_count = '';
1226                                 }
1227                         } else {
1228                                 var v_count = 0; var c_count = 0;
1229                                 acn_tree_list = obj.network.simple_request(
1230                                         'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
1231                                         [ ses(), obj.docid, [ org.id() ] ]
1232                                 );
1233                                 for (var i = 0; i < acn_tree_list.length; i++) {
1234                                         v_count++;
1235                                         obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
1236                                         var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
1237                                         for (var j = 0; j < copies.length; j++) {
1238                                                 obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
1239                                         }
1240                                 }
1241                                 data.row.my.volume_count = v_count;
1242                                 data.row.my.copy_count = '<' + c_count + '>';
1243                         }
1244                         if (parent_org) {
1245                                 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1246                         }
1247                         var node = obj.list.append(data);
1248                         if (params) {
1249                                 for (var i in params) {
1250                                         node.setAttribute(i,params[i]);
1251                                 }
1252                         }
1253                         obj.map_tree[ 'aou_' + org.id() ] = node;
1254
1255                         if (org.children()) {
1256                                 node.setAttribute('container','true');
1257                         }
1258
1259                         if (parent_org) {
1260                                 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1261                                         data.node.setAttribute('open','true');
1262                                 }
1263                         } else {
1264                                 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1265                         }
1266
1267                         if (acn_tree_list) {
1268                                 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
1269                                 node.setAttribute('container','true');
1270                         }
1271
1272                         if (document.getElementById('show_acns').checked) {
1273                                 if ( obj.data.hash.aout[ org.ou_type() ].depth() != 0 ) {
1274                                         node.setAttribute('open','true');
1275                                         setTimeout( function() { obj.on_select_org( org.id() ); }, 0 );
1276                                 }
1277                         }
1278
1279                 } catch(E) {
1280                         dump(E+'\n');
1281                         alert(E);
1282                 }
1283         },
1284
1285         'append_acn' : function( org, acn_tree, params ) {
1286                 var obj = this;
1287                 try {
1288                         if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
1289                                 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
1290                                 if (params) {
1291                                         for (var i in params) {
1292                                                 x.setAttribute(i,params[i]);
1293                                         }
1294                                 }
1295                                 return x;
1296                         }
1297
1298                         var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1299                         var data = {
1300                                 'row' : {
1301                                         'my' : {
1302                                                 'aou' : org,
1303                                                 'acn' : acn_tree,
1304                                                 'volume_count' : '',
1305                                                 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
1306                                         }
1307                                 },
1308                                 'skip_all_columns_except' : [0,1,2],
1309                                 'retrieve_id' : 'acn_' + acn_tree.id(),
1310                                 'node' : parent_node,
1311                                 'to_bottom' : true,
1312                                 'no_auto_select' : true,
1313                         };
1314                         var node = obj.list.append(data);
1315                         obj.map_tree[ 'acn_' + acn_tree.id() ] =  node;
1316                         if (params) {
1317                                 for (var i in params) {
1318                                         node.setAttribute(i,params[i]);
1319                                 }
1320                         }
1321                         if (acn_tree.copies()) {
1322                                 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
1323                                 node.setAttribute('container','true');
1324                         }
1325                         if (document.getElementById('show_acps').checked) {
1326                                 node.setAttribute('open','true');
1327                                 setTimeout( function() { obj.on_select_acn( acn_tree.id() ); }, 0 );
1328                         }
1329
1330                 } catch(E) {
1331                         dump(E+'\n');
1332                         alert(E);
1333                 }
1334         },
1335
1336         'append_acp' : function( acp_item, acn_tree, params ) {
1337                 var obj = this;
1338                 try {
1339                         if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
1340                                 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
1341                                 if (params) {
1342                                         for (var i in params) {
1343                                                 x.setAttribute(i,params[i]);
1344                                         }
1345                                 }
1346                                 return x;
1347                         }
1348
1349                         var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
1350                         var data = {
1351                                 'row' : {
1352                                         'my' : {
1353                                                 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
1354                                                 'acn' : acn_tree,
1355                                                 'acp' : acp_item,
1356                                                 'volume_count' : '',
1357                                                 'copy_count' : '',
1358                                         }
1359                                 },
1360                                 'retrieve_id' : 'acp_' + acp_item.id(),
1361                                 'node' : parent_node,
1362                                 'to_bottom' : true,
1363                                 'no_auto_select' : true,
1364                         };
1365                         var node = obj.list.append(data);
1366                         obj.map_tree[ 'acp_' + acp_item.id() ] =  node;
1367                         if (params) {
1368                                 for (var i in params) {
1369                                         node.setAttribute(i,params[i]);
1370                                 }
1371                         }
1372
1373                 } catch(E) {
1374                         dump(E+'\n');
1375                         alert(E);
1376                 }
1377         },
1378
1379         'list_init' : function( params ) {
1380
1381                 try {
1382                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1383                         var obj = this;
1384                         
1385                         JSAN.use('circ.util');
1386                         var columns = [
1387                                 {
1388                                         'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
1389                                         'primary' : true, 'hidden' : false, 
1390                                         'render' : function(my) { return my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"; },
1391                                 },
1392                                 {
1393                                         'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
1394                                         'primary' : false, 'hidden' : false, 
1395                                         'render' : function(my) { return my.volume_count; },
1396                                 },
1397                                 {
1398                                         'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
1399                                         'primary' : false, 'hidden' : false, 
1400                                         'render' : function(my) { return my.copy_count; },
1401                                 },
1402                         ].concat(
1403                                 circ.util.columns( 
1404                                         { 
1405                                                 'location' : { 'hidden' : false },
1406                                                 'circ_lib' : { 'hidden' : false },
1407                                                 'owning_lib' : { 'hidden' : false },
1408                                                 'call_number' : { 'hidden' : false },
1409                                                 'due_date' : { 'hidden' : false },
1410                                                 'status' : { 'hidden' : false },
1411                                         },
1412                                         {
1413                                                 'just_these' : [
1414                                                         'due_date',
1415                                                         'owning_lib',
1416                                                         'circ_lib',
1417                                                         'call_number',
1418                                                         'copy_number',
1419                                                         'location',
1420                                                         'barcode',
1421                                                         'loan_duration',
1422                                                         'fine_level',
1423                                                         'circulate',
1424                                                         'holdable',
1425                                                         'opac_visible',
1426                                                         'ref',
1427                                                         'deposit',
1428                                                         'deposit_amount',
1429                                                         'price',
1430                                                         'circ_as_type',
1431                                                         'circ_modifier',
1432                                                         'status',
1433                                                         'alert_message',
1434                                                         'acp_id',
1435                                                 ]
1436                                         }
1437                                 )
1438                         );
1439                         JSAN.use('util.list'); obj.list = new util.list('copy_tree');
1440                         obj.list.init(
1441                                 {
1442                                         'no_auto_select' : true,
1443                                         'columns' : columns,
1444                                         'map_row_to_columns' : circ.util.std_map_row_to_columns(' '),
1445                                         'retrieve_row' : function(params) {
1446
1447                                                 var row = params.row;
1448
1449                                                 var funcs = [];
1450                                         /*      
1451                                                 if (!row.my.mvr) funcs.push(
1452                                                         function() {
1453
1454                                                                 row.my.mvr = obj.network.request(
1455                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
1456                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
1457                                                                         [ row.my.circ.target_copy() ]
1458                                                                 );
1459
1460                                                         }
1461                                                 );
1462                                                 if (!row.my.acp) {
1463                                                         funcs.push(     
1464                                                                 function() {
1465
1466                                                                         row.my.acp = obj.network.request(
1467                                                                                 api.FM_ACP_RETRIEVE.app,
1468                                                                                 api.FM_ACP_RETRIEVE.method,
1469                                                                                 [ row.my.circ.target_copy() ]
1470                                                                         );
1471
1472                                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1473
1474                                                                 }
1475                                                         );
1476                                                 } else {
1477                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1478                                                 }
1479                                         */
1480                                                 funcs.push(
1481                                                         function() {
1482
1483                                                                 if (typeof params.on_retrieve == 'function') {
1484                                                                         params.on_retrieve(row);
1485                                                                 }
1486
1487                                                         }
1488                                                 );
1489
1490                                                 JSAN.use('util.exec'); var exec = new util.exec();
1491                                                 exec.on_error = function(E) {
1492                                                         var err = 'items chain: ' + js2JSON(E);
1493                                                         obj.error.sdump('D_ERROR',err);
1494                                                         return true; /* keep going */
1495                                                 }
1496                                                 exec.chain( funcs );
1497
1498                                                 return row;
1499                                         },
1500                                         'on_click' : function(ev) {
1501                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1502                                                 var row = {}; var col = {}; var nobj = {};
1503                                                 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
1504                                                 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
1505                                                 var node = obj.list.node.contentView.getItemAtIndex(row.value);
1506                                                 var list = [ node.getAttribute('retrieve_id') ];
1507                                                 if (typeof obj.on_select == 'function') {
1508                                                         obj.on_select(list,true);
1509                                                 }
1510                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1511                                                         window.xulG.on_select(list);
1512                                                 }
1513                                         },
1514                                         'on_select' : function(ev) {
1515                                                 JSAN.use('util.functional');
1516                                                 var sel = obj.list.retrieve_selection();
1517                                                 obj.controller.view.sel_clip.disabled = sel.length < 1;
1518                                                 obj.sel_list = util.functional.map_list(
1519                                                         sel,
1520                                                         function(o) { return o.getAttribute('retrieve_id'); }
1521                                                 );
1522                                                 obj.toggle_actions();
1523                                                 if (typeof obj.on_select == 'function') {
1524                                                         obj.on_select(obj.sel_list);
1525                                                 }
1526                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1527                                                         window.xulG.on_select(obj.sel_list);
1528                                                 }
1529                                         },
1530                                 }
1531                         );
1532
1533                         obj.controller.render();
1534
1535                 } catch(E) {
1536                         this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
1537                         alert(E);
1538                 }
1539         },
1540
1541         'toggle_actions' : function() {
1542                 var obj = this;
1543                 try {
1544                         var found_aou = false; var found_acn = false; var found_acp = false;
1545                         var found_aou_with_can_have_vols = false;
1546                         for (var i = 0; i < obj.sel_list.length; i++) {
1547                                 var type = obj.sel_list[i].split(/_/)[0];
1548                                 switch(type) {
1549                                         case 'aou' : 
1550                                                 found_aou = true; 
1551                                                 var org = obj.data.hash.aou[ obj.sel_list[i].split(/_/)[1] ];
1552                                                 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) found_aou_with_can_have_vols = true;
1553                                         break;
1554                                         case 'acn' : found_acn = true; break;
1555                                         case 'acp' : found_acp = true; break;
1556                                 }
1557                         }
1558                         obj.controller.view.cmd_add_items.setAttribute('disabled','true');
1559                         obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','true');
1560                         obj.controller.view.cmd_edit_items.setAttribute('disabled','true');
1561                         obj.controller.view.cmd_replace_barcode.setAttribute('disabled','true');
1562                         obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
1563                         obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','true');
1564                         obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
1565                         obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1566                         obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
1567                         obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
1568                         obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
1569                         obj.controller.view.cmd_transfer_volume.setAttribute('disabled','true');
1570                         obj.controller.view.cmd_transfer_items.setAttribute('disabled','true');
1571                         obj.controller.view.sel_copy_details.setAttribute('disabled','true');
1572                         obj.controller.view.sel_patron.setAttribute('disabled','true');
1573                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
1574                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
1575                         if (found_aou && found_aou_with_can_have_vols) {
1576                                 obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
1577                                 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1578                         }
1579                         if (found_acn) {
1580                                 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
1581                                 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
1582                                 obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
1583                                 obj.controller.view.cmd_add_items.setAttribute('disabled','false');
1584                                 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','false');
1585                         }
1586                         if (found_acp) {
1587                                 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
1588                                 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
1589                                 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','false');
1590                                 obj.controller.view.cmd_edit_items.setAttribute('disabled','false');
1591                                 obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
1592                                 obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
1593                                 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','false');
1594                                 obj.controller.view.cmd_transfer_items.setAttribute('disabled','false');
1595                                 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
1596                                 obj.controller.view.sel_patron.setAttribute('disabled','false');
1597                         }
1598                 } catch(E) {
1599                         obj.error.standard_unexpected_error_alert('Copy Browser Actions',E);
1600                 }
1601         },
1602
1603         'refresh_list' : function() { 
1604                 try {
1605                         var obj = this;
1606                         obj.list.clear();
1607                         obj.map_tree = {};
1608                         obj.map_acn = {};
1609                         obj.map_acp = {};
1610                         obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
1611                         /*
1612                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1613                         obj.show_libs( org );
1614                         */
1615                         obj.show_my_libs( document.getElementById('lib_menu').value );
1616                 } catch(E) {
1617                         this.error.standard_unexpected_error_alert('Problem refreshing the volume/copy tree.',E);
1618                 }
1619         },
1620 }
1621
1622 dump('exiting cat.copy_browser.js\n');