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