]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_browser.js
COPY_DELETE_WARNING for deleting items of magical statuses
[working/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');
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');
890                         util.widgets.load_attributes(file);
891                         ml.value = ml.getAttribute('value');
892
893                         document.getElementById('show_acns').addEventListener(
894                                 'command',
895                                 function(ev) {
896                                         JSAN.use('util.file'); var file = new util.file('copy_browser_prefs');
897                                         util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
898                                 },
899                                 false
900                         );
901
902                         document.getElementById('show_acps').addEventListener(
903                                 'command',
904                                 function(ev) {
905                                         JSAN.use('util.file'); var file = new util.file('copy_browser_prefs');
906                                         util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
907                                 },
908                                 false
909                         );
910
911                         obj.show_my_libs( ml.value );
912
913                 } catch(E) {
914                         this.error.standard_unexpected_error_alert('cat.copy_browser.init: ',E);
915                 }
916         },
917
918         'show_my_libs' : function(org) {
919                 var obj = this;
920                 try {
921                         if (!org) {
922                                 org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
923                         } else {
924                                 if (typeof org != 'object') org = obj.data.hash.aou[ org ];
925                         }
926                         obj.show_libs( org, true );
927                 
928                         var p_org = obj.data.hash.aou[ org.parent_ou() ];
929                         if (p_org) {
930                                 JSAN.use('util.exec'); var exec = new util.exec();
931                                 var funcs = [];
932                                 funcs.push( function() { 
933                                         document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
934                                         document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
935                                         document.getElementById('lib_menu').setAttribute('disabled','true'); 
936                                 } );
937                                 for (var i = 0; i < p_org.children().length; i++) {
938                                         funcs.push(
939                                                 function(o) {
940                                                         return function() {
941                                                                 obj.show_libs( o, true );
942                                                         }
943                                                 }( p_org.children()[i] )
944                                         );
945                                 }
946                                 funcs.push( function() { 
947                                         document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
948                                         document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
949                                         document.getElementById('lib_menu').setAttribute('disabled','false'); 
950                                 } );
951                                 exec.chain( funcs );
952                         }
953                 } catch(E) {
954                         alert(E);
955                 }
956         },
957
958         'show_all_libs' : function() {
959                 var obj = this;
960                 try {
961                         obj.show_my_libs();
962
963                         obj.show_libs( obj.data.tree.aou );
964
965                         JSAN.use('util.exec'); var exec = new util.exec();
966                         var funcs = [];
967                         funcs.push( function() { 
968                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
969                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
970                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
971                         } );
972
973                         for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
974                                 funcs.push(
975                                         function(o) {
976                                                 return function() {
977                                                         obj.show_libs( o );
978                                                 }
979                                         }( obj.data.tree.aou.children()[i] )
980                                 );
981                         }
982                         funcs.push( function() { 
983                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
984                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
985                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
986                         } );
987
988                         exec.chain( funcs );
989                 } catch(E) {
990                         alert(E);
991                 }
992         },
993
994         'show_libs_with_copies' : function() {
995                 var obj = this;
996                 try {
997                         JSAN.use('util.exec'); var exec = new util.exec();
998                         JSAN.use('util.functional');
999
1000                         var orgs = util.functional.map_list(
1001                                 obj.org_ids,
1002                                 function(id) { return obj.data.hash.aou[id]; }
1003                         ).sort(
1004                                 function( a, b ) {
1005                                         if (a.shortname() < b.shortname()) return -1;
1006                                         if (a.shortname() > b.shortname()) return 1;
1007                                         return 0;
1008                                 }
1009                         );
1010                         var funcs = [];
1011                         funcs.push( function() { 
1012                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1013                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1014                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1015                         } );
1016
1017                         for (var i = 0; i < orgs.length; i++) {
1018                                 funcs.push(
1019                                         function(o) {
1020                                                 return function() {
1021                                                         obj.show_libs(o,true);
1022                                                 }
1023                                         }( orgs[i] )
1024                                 );
1025                         }
1026                         funcs.push( function() { 
1027                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1028                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1029                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1030                         } );
1031
1032                         exec.chain( funcs );
1033                 } catch(E) {
1034                         alert(E);
1035                 }
1036         },
1037
1038         'show_libs' : function(start_aou,show_open) {
1039                 var obj = this;
1040                 try {
1041                         if (!start_aou) throw('show_libs: Need a start_aou');
1042                         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1043                         JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
1044
1045                         var funcs = [];
1046
1047                         var parents = [];
1048                         var temp_aou = start_aou;
1049                         while ( temp_aou.parent_ou() ) {
1050                                 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
1051                                 parents.push( temp_aou );
1052                         }
1053                         parents.reverse();
1054
1055                         for (var i = 0; i < parents.length; i++) {
1056                                 funcs.push(
1057                                         function(o,p) {
1058                                                 return function() { 
1059                                                         if (show_open) {
1060                                                                 obj.append_org(o,p,{'container':'true','open':'true'}); 
1061                                                         } else {
1062                                                                 obj.append_org(o,p,{'container':'true'}); 
1063                                                         }
1064                                                 };
1065                                         }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
1066                                 );
1067                         }
1068
1069                         funcs.push(
1070                                 function(o,p) {
1071                                         return function() { obj.append_org(o,p); };
1072                                 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
1073                         );
1074
1075                         funcs.push(
1076                                 function() {
1077                                         if (start_aou.children()) {
1078                                                 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
1079                                                 x.setAttribute('container','true');
1080                                                 if (show_open) x.setAttribute('open','true');
1081                                                 for (var i = 0; i < start_aou.children().length; i++) {
1082                                                         funcs.push(
1083                                                                 function(o,p) {
1084                                                                         return function() { obj.append_org(o,p); };
1085                                                                 }( start_aou.children()[i], start_aou )
1086                                                         );
1087                                                 }
1088                                         }
1089                                 }
1090                         );
1091
1092                         exec.chain( funcs );
1093
1094                 } catch(E) {
1095                         alert(E);
1096                 }
1097         },
1098
1099         'on_select' : function(list,twisty) {
1100                 var obj = this;
1101                 for (var i = 0; i < list.length; i++) {
1102                         var node = obj.map_tree[ list[i] ];
1103                         //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
1104                         var row_type = list[i].split('_')[0];
1105                         var id = list[i].split('_')[1];
1106                         switch(row_type) {
1107                                 case 'aou' : obj.on_select_org(id,twisty); break;
1108                                 case 'acn' : obj.on_select_acn(id,twisty); break;
1109                                 default: break;
1110                         }
1111                 }
1112         },
1113
1114         'on_select_acn' : function(acn_id,twisty) {
1115                 var obj = this;
1116                 try {
1117                         var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
1118                         var funcs = [];
1119                         funcs.push( function() { 
1120                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1121                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1122                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1123                         } );
1124                         if (acn_tree.copies()) {
1125                                 for (var i = 0; i < acn_tree.copies().length; i++) {
1126                                         funcs.push(
1127                                                 function(c,a) {
1128                                                         return function() {
1129                                                                 obj.append_acp(c,a);
1130                                                         }
1131                                                 }( acn_tree.copies()[i], acn_tree )
1132                                         )
1133                                 }
1134                         }
1135                         funcs.push( function() { 
1136                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1137                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1138                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1139                         } );
1140                         JSAN.use('util.exec'); var exec = new util.exec();
1141                         exec.chain( funcs );
1142                 } catch(E) {
1143                         alert(E);
1144                 }
1145         },
1146
1147         'on_select_org' : function(org_id,twisty) {
1148                 var obj = this;
1149                 var org = obj.data.hash.aou[ org_id ];
1150                 if (obj.data.hash.aout[ org.ou_type() ].depth() == 0) return; 
1151                 /* otherwise, we'd show every system in the consortia */
1152                 var funcs = [];
1153                 funcs.push( function() { 
1154                         document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1155                         document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1156                         document.getElementById('lib_menu').setAttribute('disabled','true'); 
1157                 } );
1158                 if (org.children()) {
1159                         for (var i = 0; i < org.children().length; i++) {
1160                                 funcs.push(
1161                                         function(o,p) {
1162                                                 return function() {
1163                                                         obj.append_org(o,p)
1164                                                 }
1165                                         }(org.children()[i],org)
1166                                 );
1167                         }
1168                 } 
1169                 if (obj.map_acn[ 'aou_' + org_id ]) {
1170                         for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
1171                                 funcs.push(
1172                                         function(o,a) {
1173                                                 return function() {
1174                                                         obj.append_acn(o,a);
1175                                                 }
1176                                         }( org, obj.map_acn[ 'aou_' + org_id ][i] )
1177                                 );
1178                         }
1179                 }
1180                 funcs.push( function() { 
1181                         document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1182                         document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1183                         document.getElementById('lib_menu').setAttribute('disabled','false'); 
1184                 } );
1185                 JSAN.use('util.exec'); var exec = new util.exec();
1186                 exec.chain( funcs );
1187         },
1188
1189         'append_org' : function (org,parent_org,params) {
1190                 var obj = this;
1191                 try {
1192                         if (obj.map_tree[ 'aou_' + org.id() ]) {
1193                                 var x = obj.map_tree[ 'aou_' + org.id() ];
1194                                 if (params) {
1195                                         for (var i in params) {
1196                                                 x.setAttribute(i,params[i]);
1197                                         }
1198                                 }
1199                                 return x;
1200                         }
1201
1202                         var data = {
1203                                 'row' : {
1204                                         'my' : {
1205                                                 'aou' : org,
1206                                         }
1207                                 },
1208                                 'skip_all_columns_except' : [0,1,2],
1209                                 'retrieve_id' : 'aou_' + org.id(),
1210                         };
1211                 
1212                         var acn_tree_list;
1213                         if ( obj.org_ids.indexOf( org.id() ) == -1 ) {
1214                                 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) {
1215                                         data.row.my.volume_count = '0';
1216                                         data.row.my.copy_count = '<0>';
1217                                 } else {
1218                                         data.row.my.volume_count = '';
1219                                         data.row.my.copy_count = '';
1220                                 }
1221                         } else {
1222                                 var v_count = 0; var c_count = 0;
1223                                 acn_tree_list = obj.network.simple_request(
1224                                         'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
1225                                         [ ses(), obj.docid, [ org.id() ] ]
1226                                 );
1227                                 for (var i = 0; i < acn_tree_list.length; i++) {
1228                                         v_count++;
1229                                         obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
1230                                         var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
1231                                         for (var j = 0; j < copies.length; j++) {
1232                                                 obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
1233                                         }
1234                                 }
1235                                 data.row.my.volume_count = v_count;
1236                                 data.row.my.copy_count = '<' + c_count + '>';
1237                         }
1238                         if (parent_org) {
1239                                 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1240                         }
1241                         var node = obj.list.append(data);
1242                         if (params) {
1243                                 for (var i in params) {
1244                                         node.setAttribute(i,params[i]);
1245                                 }
1246                         }
1247                         obj.map_tree[ 'aou_' + org.id() ] = node;
1248
1249                         if (org.children()) {
1250                                 node.setAttribute('container','true');
1251                         }
1252
1253                         if (parent_org) {
1254                                 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1255                                         data.node.setAttribute('open','true');
1256                                 }
1257                         } else {
1258                                 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1259                         }
1260
1261                         if (acn_tree_list) {
1262                                 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
1263                                 node.setAttribute('container','true');
1264                         }
1265
1266                         if (document.getElementById('show_acns').checked) {
1267                                 if ( obj.data.hash.aout[ org.ou_type() ].depth() != 0 ) {
1268                                         node.setAttribute('open','true');
1269                                         setTimeout( function() { obj.on_select_org( org.id() ); }, 0 );
1270                                 }
1271                         }
1272
1273                 } catch(E) {
1274                         dump(E+'\n');
1275                         alert(E);
1276                 }
1277         },
1278
1279         'append_acn' : function( org, acn_tree, params ) {
1280                 var obj = this;
1281                 try {
1282                         if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
1283                                 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
1284                                 if (params) {
1285                                         for (var i in params) {
1286                                                 x.setAttribute(i,params[i]);
1287                                         }
1288                                 }
1289                                 return x;
1290                         }
1291
1292                         var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1293                         var data = {
1294                                 'row' : {
1295                                         'my' : {
1296                                                 'aou' : org,
1297                                                 'acn' : acn_tree,
1298                                                 'volume_count' : '',
1299                                                 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
1300                                         }
1301                                 },
1302                                 'skip_all_columns_except' : [0,1,2],
1303                                 'retrieve_id' : 'acn_' + acn_tree.id(),
1304                                 'node' : parent_node,
1305                         };
1306                         var node = obj.list.append(data);
1307                         obj.map_tree[ 'acn_' + acn_tree.id() ] =  node;
1308                         if (params) {
1309                                 for (var i in params) {
1310                                         node.setAttribute(i,params[i]);
1311                                 }
1312                         }
1313                         if (acn_tree.copies()) {
1314                                 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
1315                                 node.setAttribute('container','true');
1316                         }
1317                         if (document.getElementById('show_acps').checked) {
1318                                 node.setAttribute('open','true');
1319                                 setTimeout( function() { obj.on_select_acn( acn_tree.id() ); }, 0 );
1320                         }
1321
1322                 } catch(E) {
1323                         dump(E+'\n');
1324                         alert(E);
1325                 }
1326         },
1327
1328         'append_acp' : function( acp_item, acn_tree, params ) {
1329                 var obj = this;
1330                 try {
1331                         if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
1332                                 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
1333                                 if (params) {
1334                                         for (var i in params) {
1335                                                 x.setAttribute(i,params[i]);
1336                                         }
1337                                 }
1338                                 return x;
1339                         }
1340
1341                         var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
1342                         var data = {
1343                                 'row' : {
1344                                         'my' : {
1345                                                 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
1346                                                 'acn' : acn_tree,
1347                                                 'acp' : acp_item,
1348                                                 'volume_count' : '',
1349                                                 'copy_count' : '',
1350                                         }
1351                                 },
1352                                 'retrieve_id' : 'acp_' + acp_item.id(),
1353                                 'node' : parent_node,
1354                         };
1355                         var node = obj.list.append(data);
1356                         obj.map_tree[ 'acp_' + acp_item.id() ] =  node;
1357                         if (params) {
1358                                 for (var i in params) {
1359                                         node.setAttribute(i,params[i]);
1360                                 }
1361                         }
1362
1363                 } catch(E) {
1364                         dump(E+'\n');
1365                         alert(E);
1366                 }
1367         },
1368
1369         'list_init' : function( params ) {
1370
1371                 try {
1372                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1373                         var obj = this;
1374                         
1375                         JSAN.use('circ.util');
1376                         var columns = [
1377                                 {
1378                                         'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
1379                                         'primary' : true, 'hidden' : false, 
1380                                         'render' : function(my) { return my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"; },
1381                                 },
1382                                 {
1383                                         'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
1384                                         'primary' : false, 'hidden' : false, 
1385                                         'render' : function(my) { return my.volume_count; },
1386                                 },
1387                                 {
1388                                         'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
1389                                         'primary' : false, 'hidden' : false, 
1390                                         'render' : function(my) { return my.copy_count; },
1391                                 },
1392                         ].concat(
1393                                 circ.util.columns( 
1394                                         { 
1395                                                 'location' : { 'hidden' : false },
1396                                                 'circ_lib' : { 'hidden' : false },
1397                                                 'owning_lib' : { 'hidden' : false },
1398                                                 'call_number' : { 'hidden' : false },
1399                                                 'due_date' : { 'hidden' : false },
1400                                                 'status' : { 'hidden' : false },
1401                                         },
1402                                         {
1403                                                 'just_these' : [
1404                                                         'due_date',
1405                                                         'owning_lib',
1406                                                         'circ_lib',
1407                                                         'call_number',
1408                                                         'copy_number',
1409                                                         'location',
1410                                                         'barcode',
1411                                                         'loan_duration',
1412                                                         'fine_level',
1413                                                         'circulate',
1414                                                         'holdable',
1415                                                         'opac_visible',
1416                                                         'ref',
1417                                                         'deposit',
1418                                                         'deposit_amount',
1419                                                         'price',
1420                                                         'circ_as_type',
1421                                                         'circ_modifier',
1422                                                         'status',
1423                                                         'alert_message',
1424                                                         'acp_id',
1425                                                 ]
1426                                         }
1427                                 )
1428                         );
1429                         JSAN.use('util.list'); obj.list = new util.list('copy_tree');
1430                         obj.list.init(
1431                                 {
1432                                         'columns' : columns,
1433                                         'map_row_to_columns' : circ.util.std_map_row_to_columns(' '),
1434                                         'retrieve_row' : function(params) {
1435
1436                                                 var row = params.row;
1437
1438                                                 var funcs = [];
1439                                         /*      
1440                                                 if (!row.my.mvr) funcs.push(
1441                                                         function() {
1442
1443                                                                 row.my.mvr = obj.network.request(
1444                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
1445                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
1446                                                                         [ row.my.circ.target_copy() ]
1447                                                                 );
1448
1449                                                         }
1450                                                 );
1451                                                 if (!row.my.acp) {
1452                                                         funcs.push(     
1453                                                                 function() {
1454
1455                                                                         row.my.acp = obj.network.request(
1456                                                                                 api.FM_ACP_RETRIEVE.app,
1457                                                                                 api.FM_ACP_RETRIEVE.method,
1458                                                                                 [ row.my.circ.target_copy() ]
1459                                                                         );
1460
1461                                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1462
1463                                                                 }
1464                                                         );
1465                                                 } else {
1466                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1467                                                 }
1468                                         */
1469                                                 funcs.push(
1470                                                         function() {
1471
1472                                                                 if (typeof params.on_retrieve == 'function') {
1473                                                                         params.on_retrieve(row);
1474                                                                 }
1475
1476                                                         }
1477                                                 );
1478
1479                                                 JSAN.use('util.exec'); var exec = new util.exec();
1480                                                 exec.on_error = function(E) {
1481                                                         var err = 'items chain: ' + js2JSON(E);
1482                                                         obj.error.sdump('D_ERROR',err);
1483                                                         return true; /* keep going */
1484                                                 }
1485                                                 exec.chain( funcs );
1486
1487                                                 return row;
1488                                         },
1489                                         'on_click' : function(ev) {
1490                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1491                                                 var row = {}; var col = {}; var nobj = {};
1492                                                 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
1493                                                 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
1494                                                 var node = obj.list.node.contentView.getItemAtIndex(row.value);
1495                                                 var list = [ node.getAttribute('retrieve_id') ];
1496                                                 if (typeof obj.on_select == 'function') {
1497                                                         obj.on_select(list,true);
1498                                                 }
1499                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1500                                                         window.xulG.on_select(list);
1501                                                 }
1502                                         },
1503                                         'on_select' : function(ev) {
1504                                                 JSAN.use('util.functional');
1505                                                 var sel = obj.list.retrieve_selection();
1506                                                 obj.controller.view.sel_clip.disabled = sel.length < 1;
1507                                                 obj.sel_list = util.functional.map_list(
1508                                                         sel,
1509                                                         function(o) { return o.getAttribute('retrieve_id'); }
1510                                                 );
1511                                                 obj.toggle_actions();
1512                                                 if (typeof obj.on_select == 'function') {
1513                                                         obj.on_select(obj.sel_list);
1514                                                 }
1515                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1516                                                         window.xulG.on_select(obj.sel_list);
1517                                                 }
1518                                         },
1519                                 }
1520                         );
1521
1522                         obj.controller.render();
1523
1524                 } catch(E) {
1525                         this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
1526                         alert(E);
1527                 }
1528         },
1529
1530         'toggle_actions' : function() {
1531                 var obj = this;
1532                 try {
1533                         var found_aou = false; var found_acn = false; var found_acp = false;
1534                         var found_aou_with_can_have_vols = false;
1535                         for (var i = 0; i < obj.sel_list.length; i++) {
1536                                 var type = obj.sel_list[i].split(/_/)[0];
1537                                 switch(type) {
1538                                         case 'aou' : 
1539                                                 found_aou = true; 
1540                                                 var org = obj.data.hash.aou[ obj.sel_list[i].split(/_/)[1] ];
1541                                                 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) found_aou_with_can_have_vols = true;
1542                                         break;
1543                                         case 'acn' : found_acn = true; break;
1544                                         case 'acp' : found_acp = true; break;
1545                                 }
1546                         }
1547                         obj.controller.view.cmd_add_items.setAttribute('disabled','true');
1548                         obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','true');
1549                         obj.controller.view.cmd_edit_items.setAttribute('disabled','true');
1550                         obj.controller.view.cmd_replace_barcode.setAttribute('disabled','true');
1551                         obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
1552                         obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','true');
1553                         obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
1554                         obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1555                         obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
1556                         obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
1557                         obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
1558                         obj.controller.view.cmd_transfer_volume.setAttribute('disabled','true');
1559                         obj.controller.view.cmd_transfer_items.setAttribute('disabled','true');
1560                         obj.controller.view.sel_copy_details.setAttribute('disabled','true');
1561                         obj.controller.view.sel_patron.setAttribute('disabled','true');
1562                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
1563                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
1564                         if (found_aou && found_aou_with_can_have_vols) {
1565                                 obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
1566                                 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1567                         }
1568                         if (found_acn) {
1569                                 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
1570                                 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
1571                                 obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
1572                                 obj.controller.view.cmd_add_items.setAttribute('disabled','false');
1573                                 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','false');
1574                         }
1575                         if (found_acp) {
1576                                 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
1577                                 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
1578                                 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','false');
1579                                 obj.controller.view.cmd_edit_items.setAttribute('disabled','false');
1580                                 obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
1581                                 obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
1582                                 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','false');
1583                                 obj.controller.view.cmd_transfer_items.setAttribute('disabled','false');
1584                                 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
1585                                 obj.controller.view.sel_patron.setAttribute('disabled','false');
1586                         }
1587                 } catch(E) {
1588                         obj.error.standard_unexpected_error_alert('Copy Browser Actions',E);
1589                 }
1590         },
1591
1592         'refresh_list' : function() { 
1593                 try {
1594                         var obj = this;
1595                         obj.list.clear();
1596                         obj.map_tree = {};
1597                         obj.map_acn = {};
1598                         obj.map_acp = {};
1599                         obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
1600                         /*
1601                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1602                         obj.show_libs( org );
1603                         */
1604                         obj.show_my_libs( document.getElementById('lib_menu').value );
1605                 } catch(E) {
1606                         this.error.standard_unexpected_error_alert('Problem refreshing the volume/copy tree.',E);
1607                 }
1608         },
1609 }
1610
1611 dump('exiting cat.copy_browser.js\n');