]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_browser.js
Back on that i18n horse
[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' : list }
540                                                                         );
541
542                                                                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
543                                                                         //obj.data.stash_retrieve();
544                                                                         var volumes = my_xulG.volumes;
545                                                                         if (!volumes) return;
546                                                                 
547                                                                         volumes = util.functional.filter_list(
548                                                                                 volumes,
549                                                                                 function (o) {
550                                                                                         return o.ischanged() == '1';
551                                                                                 }
552                                                                         );
553
554                                                                         volumes = util.functional.map_list(
555                                                                                 volumes,
556                                                                                 function (o) {
557                                                                                         o.record( obj.docid ); // staff client 2 did not do this.  Does it matter?
558                                                                                         return o;
559                                                                                 }
560                                                                         );
561
562                                                                         if (volumes.length == 0) return;
563
564                                                                         try {
565                                                                                 var r = obj.network.request(
566                                                                                         api.FM_ACN_TREE_UPDATE.app,
567                                                                                         api.FM_ACN_TREE_UPDATE.method,
568                                                                                         [ ses(), volumes, true ]
569                                                                                 );
570                                                                                 if (typeof r.ilsevent != 'undefined') {
571                                             switch(Number(r.ilsevent)) {
572                                                 case 1705 /* VOLUME_LABEL_EXISTS */ :
573                                                     alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.failed'));
574                                                     break;
575                                                 default: throw(r);
576                                             }
577                                         } else {
578                                                                                 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.success'));
579                                         }
580                                                                         } catch(E) {
581                                                                                 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.error'),E);
582                                                                         }
583                                                                         obj.refresh_list();
584
585                                                                 } catch(E) {
586                                                                         obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.exception'),E);
587                                                                 }
588                                                         }
589                                                 ],
590                                                 'cmd_delete_volumes' : [
591                                                         ['command'],
592                                                         function() {
593                                                                 try {
594                                                                         JSAN.use('util.functional');
595
596                                                                         var list = util.functional.filter_list(
597                                                                                 obj.sel_list,
598                                                                                 function (o) {
599                                                                                         return o.split(/_/)[0] == 'acn';
600                                                                                 }
601                                                                         );
602
603                                                                         list = util.functional.map_list(
604                                                                                 list,
605                                                                                 function (o) {
606                                                                                         return JSON2js( js2JSON( obj.map_acn[ 'acn_' + o.split(/_/)[1] ] ) );
607                                                                                 }
608                                                                         );
609
610                                                                         var del_prompt;
611                                                                         if (list.length == 1) {
612                                                                                 del_prompt = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.prompt');
613                                                                         } else {
614                                                                                 del_prompt = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_volume.prompt.plural', [list.length]);
615                                                                         }
616
617                                                                         var r = obj.error.yns_alert(
618                                                                                         del_prompt,
619                                                                                         document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.title'),
620                                                                                         document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.delete'),
621                                                                                         document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.cancel'),
622                                                                                         null,
623                                                                                         document.getElementById('commonStrings').getString('common.confirm')
624                                                                         );
625
626                                                                         if (r == 0) {
627                                                                                 for (var i = 0; i < list.length; i++) {
628                                                                                         list[i].isdeleted('1');
629                                                                                 }
630                                                                                 var robj = obj.network.simple_request(
631                                                                                         'FM_ACN_TREE_UPDATE', 
632                                                                                         [ ses(), list, true ],
633                                                                                         null,
634                                                                                         {
635                                                                                                 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.override'),
636                                                                                                 'overridable_events' : [
637                                                                                                 ]
638                                                                                         }
639                                                                                 );
640                                                                                 if (robj == null) throw(robj);
641                                                                                 if (typeof robj.ilsevent != 'undefined') {
642                                                                                         if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
643                                                                                                 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain'));
644                                                                                                 return;
645                                                                                         }
646                                                                                         if (robj.ilsevent != 0) throw(robj);
647                                                                                 }
648                                                                                 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.success'));
649                                                                                 obj.refresh_list();
650                                                                         }
651                                                                 } catch(E) {
652                                                                         obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.exception'),E);
653                                                                         obj.refresh_list();
654                                                                 }
655
656                                                         }
657                                                 ],
658                                                 'cmd_mark_library' : [
659                                                         ['command'],
660                                                         function() {
661                                                                 try {
662                                                                         var list = util.functional.filter_list(
663                                                                                 obj.sel_list,
664                                                                                 function (o) {
665                                                                                         return o.split(/_/)[0] == 'aou';
666                                                                                 }
667                                                                         );
668
669                                                                         list = util.functional.map_list(
670                                                                                 list,
671                                                                                 function (o) {
672                                                                                         return o.split(/_/)[1];
673                                                                                 }
674                                                                         );
675
676                                                                         if (list.length == 1) {
677                                                                                 obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid };
678                                                                                 obj.data.stash('marked_library');
679                                                                                 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.alert'));
680                                                                         } else {
681                                                                                 obj.error.yns_alert(
682                                                                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.prompt'),
683                                                                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.title'),
684                                                                                                 document.getElementById('commonStrings').getString('common.ok'),
685                                                                                                 null,
686                                                                                                 null,
687                                                                                                 document.getElementById('commonStrings').getString('common.confirm')
688                                                                                                 );
689                                                                         }
690                                                                 } catch(E) {
691                                                                         obj.error.standard_unexpected_error_alert('copy browser -> mark library',E);
692                                                                 }
693                                                         }
694                                                 ],
695
696                                                 'cmd_mark_volume' : [
697                                                         ['command'],
698                                                         function() {
699                                                                 try {
700                                                                         var list = util.functional.filter_list(
701                                                                                 obj.sel_list,
702                                                                                 function (o) {
703                                                                                         return o.split(/_/)[0] == 'acn';
704                                                                                 }
705                                                                         );
706
707                                                                         list = util.functional.map_list(
708                                                                                 list,
709                                                                                 function (o) {
710                                                                                         return o.split(/_/)[1];
711                                                                                 }
712                                                                         );
713
714                                                                         if (list.length == 1) {
715                                                                                 obj.data.marked_volume = list[0];
716                                                                                 obj.data.stash('marked_volume');
717                                                                                 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.alert'));
718                                                                         } else {
719                                                                                 obj.error.yns_alert(
720                                                                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.prompt'),
721                                                                                                 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.title'),
722                                                                                                 document.getElementById('commonStrings').getString('common.ok'),
723                                                                                                 null,
724                                                                                                 null,
725                                                                                                 document.getElementById('commonStrings').getString('common.confirm')
726                                                                                                 );
727                                                                         }
728                                                                 } catch(E) {
729                                                                         obj.error.standard_unexpected_error_alert('copy browser -> mark volume',E);
730                                                                 }
731                                                         }
732                                                 ],
733                                                 'cmd_refresh_list' : [
734                                                         ['command'],
735                                                         function() {
736                                                                 obj.refresh_list();
737                                                         }
738                                                 ],
739                                                 'cmd_transfer_volume' : [
740                                                         ['command'],
741                                                         function() {
742                                                                 try {
743                                                                         obj.data.stash_retrieve();
744                                                                         if (!obj.data.marked_library) {
745                                                                                 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_volume.alert'));
746                                                                                 return;
747                                                                         }
748                                                                         
749                                                                         JSAN.use('util.functional');
750
751                                                                         var list = util.functional.filter_list(
752                                                                                 obj.sel_list,
753                                                                                 function (o) {
754                                                                                         return o.split(/_/)[0] == 'acn';
755                                                                                 }
756                                                                         );
757
758                                                                         list = util.functional.map_list(
759                                                                                 list,
760                                                                                 function (o) {
761                                                                                         return o.split(/_/)[1];
762                                                                                 }
763                                                                         );
764
765                                                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
766
767                                                                         var acn_list = util.functional.map_list(
768                                                                                 list,
769                                                                                 function (o) {
770                                                                                         return obj.map_acn[ 'acn_' + o ].label();
771                                                                                 }
772                                                                         ).join(document.getElementById('commonStrings').getString('common.grouping_string'));
773
774                                                                         var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
775                                                                         xml += '<description>';
776                                                                         xml += document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.transfer.prompt', [acn_list, obj.data.hash.aou[ obj.data.marked_library.lib ].shortname()]);
777                                                                         xml += '</description>';
778                                                                         xml += '<hbox><button label="' + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.submit.label') + '" name="fancy_submit"/>';
779                                                                         xml += '<button label="' 
780                                                                                 + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.label') 
781                                                                                 + '" accesskey="' 
782                                                                                 + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.accesskey') 
783                                                                                 + '" name="fancy_cancel"/></hbox>';
784                                                                         xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
785                                                                         xml += '</vbox>';
786                                                                         JSAN.use('OpenILS.data');
787                                                                         var data = new OpenILS.data(); data.init({'via':'stash'});
788                                                                         //data.temp_transfer = xml; data.stash('temp_transfer');
789                                                                         JSAN.use('util.window'); var win = new util.window();
790                                                                         var fancy_prompt_data = win.open(
791                                                                                 urls.XUL_FANCY_PROMPT,
792                                                                                 //+ '?xml_in_stash=temp_transfer'
793                                                                                 //+ '&title=' + window.escape('Volume Transfer'),
794                                                                                 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300',
795                                                                                 {
796                                                                                         'xml' : xml,
797                                                                                         'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.title')
798                                                                                 }
799                                                                         );
800
801                                                                         if (fancy_prompt_data.fancy_status == 'incomplete') {
802                                                                                 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.incomplete'));
803                                                                                 return;
804                                                                         }
805
806                                                                         var robj = obj.network.simple_request(
807                                                                                 'FM_ACN_TRANSFER', 
808                                                                                 [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'volumes' : list } ],
809                                                                                 null,
810                                                                                 {
811                                                                                         'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.override.failure'),
812                                                                                         'overridable_events' : [
813                                                                                                 1208 /* TITLE_LAST_COPY */,
814                                                                                                 1219 /* COPY_REMOTE_CIRC_LIB */,
815                                                                                         ],
816                                                                                 }
817                                                                         );
818
819                                                                         if (typeof robj.ilsevent != 'undefined') {
820                                                                                 if (robj.ilsevent == 1221 /* ORG_CANNOT_HAVE_VOLS */) {
821                                                                                         alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.ineligible_destination'));
822                                                                                 } else {
823                                                                                         throw(robj);
824                                                                                 }
825                                                                         } else {
826                                                                                 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.success'));
827                                                                         }
828
829                                                                 } catch(E) {
830                                                                         obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.unexpected_error'),E);
831                                                                 }
832                                                                 obj.refresh_list();
833                                                         }
834                                                 ],
835
836                                                 'cmd_transfer_items' : [
837                                                         ['command'],
838                                                         function() {
839                                                                 try {
840                                                                         obj.data.stash_retrieve();
841                                                                         if (!obj.data.marked_volume) {
842                                                                                 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.missing_volume'));
843                                                                                 return;
844                                                                         }
845                                                                         
846                                                                         JSAN.use('util.functional');
847
848                                                                         var list = util.functional.filter_list(
849                                                                                 obj.sel_list,
850                                                                                 function (o) {
851                                                                                         return o.split(/_/)[0] == 'acp';
852                                                                                 }
853                                                                         );
854
855                                                                         list = util.functional.map_list(
856                                                                                 list,
857                                                                                 function (o) {
858                                                                                         return o.split(/_/)[1];
859                                                                                 }
860                                                                         );
861
862                                                                         var volume = obj.network.simple_request('FM_ACN_RETRIEVE.authoritative',[ obj.data.marked_volume ]);
863
864                                                                         JSAN.use('cat.util'); cat.util.transfer_copies( { 
865                                                                                 'copy_ids' : list, 
866                                                                                 'docid' : volume.record(),
867                                                                                 'volume_label' : volume.label(),
868                                                                                 'owning_lib' : volume.owning_lib(),
869                                                                         } );
870
871                                                                 } catch(E) {
872                                                                         obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.unexpected_error'),E);
873                                                                 }
874                                                                 obj.refresh_list();
875                                                         }
876                                                 ],
877                                         }
878                                 }
879                         );
880
881                         obj.list_init(params);
882
883                         obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
884                         if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
885             JSAN.use('util.functional'); 
886             obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
887
888                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
889                         //obj.show_libs( org );
890
891                         //obj.show_my_libs();
892
893                         JSAN.use('util.file'); JSAN.use('util.widgets');
894
895                         var file; var list_data; var ml; 
896
897                         file = new util.file('offline_ou_list'); 
898                         if (file._file.exists()) {
899                                 list_data = file.get_object(); file.close();
900                                 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
901                                 ml.setAttribute('id','lib_menu'); document.getElementById('x_lib_menu').appendChild(ml);
902                                 for (var i = 0; i < obj.org_ids.length; i++) {
903                                         ml.getElementsByAttribute('value',obj.org_ids[i])[0].setAttribute('class','has_copies');
904                                 }
905                                 ml.firstChild.addEventListener(
906                                         'popupshown',
907                                         function(ev) {
908                                                 document.getElementById('legend').setAttribute('hidden','false');
909                                         },
910                                         false
911                                 );
912                                 ml.firstChild.addEventListener(
913                                         'popuphidden',
914                                         function(ev) {
915                                                 document.getElementById('legend').setAttribute('hidden','true');
916                                         },
917                                         false
918                                 );
919                                 ml.addEventListener(
920                                         'command',
921                                         function(ev) {
922                                                 //obj.show_my_libs(ev.target.value);
923                                                 //alert('lib picker, command caught - ml = ' + ml + '\nml.value = ' + ml.value + '\n');
924                                                 if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus(); 
925                                                 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
926                                                 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
927                                                 obj.refresh_list();
928                                         },
929                                         false
930                                 );
931                         } else {
932                                 throw(document.getElementById('catStrings').getString('staff.cat.copy_browser.missing_library') + '\n');
933                         }
934
935                         JSAN.use('util.widgets'); 
936                 
937                         file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
938                         util.widgets.load_attributes(file);
939                         ml.value = ml.getAttribute('value');
940                         if (! ml.value) {
941                                 ml.value = org.id();
942                                 ml.setAttribute('value',ml.value);
943                         }
944
945                         document.getElementById('show_acns').addEventListener(
946                                 'command',
947                                 function(ev) {
948                                         JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
949                                         util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
950                                 },
951                                 false
952                         );
953
954                         document.getElementById('show_acps').addEventListener(
955                                 'command',
956                                 function(ev) {
957                                         JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
958                                         util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
959                                 },
960                                 false
961                         );
962
963                         obj.show_my_libs( ml.value );
964
965                         obj.show_consortial_count();
966
967                 } catch(E) {
968                         this.error.standard_unexpected_error_alert('cat.copy_browser.init: ',E);
969                 }
970         },
971
972         'show_consortial_count' : function() {
973                 var obj = this;
974                 try {
975                         obj.network.simple_request('FM_ACP_COUNT.authoritative',[ obj.data.tree.aou.id(), obj.docid ],function(req){ 
976                                 try {
977                                         var robj = req.getResultObject();
978                                         var x = document.getElementById('consortial_total');
979                                         if (x) x.setAttribute('value',robj[0].count);
980                                         x = document.getElementById('consortial_available');
981                                         if (x) x.setAttribute('value',robj[0].available);
982                                 } catch(E) {
983                                         obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.consortial_copy_count.error'),E);
984                                 }
985                         });
986                 } catch(E) {
987                         this.error.standard_unexpected_error_alert('cat.copy_browser.show_consortial_count: ',E);
988                 }
989         },
990
991         'show_my_libs' : function(org) {
992                 var obj = this;
993                 try {
994                         if (!org) {
995                                 org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
996                         } else {
997                                 if (typeof org != 'object') org = obj.data.hash.aou[ org ];
998                         }
999                         obj.show_libs( org, false );
1000                 
1001                         var p_org = obj.data.hash.aou[ org.parent_ou() ];
1002                         if (p_org) {
1003                                 JSAN.use('util.exec'); var exec = new util.exec();
1004                                 var funcs = [];
1005                                 funcs.push( function() { 
1006                                         document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1007                                         document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1008                                         document.getElementById('lib_menu').setAttribute('disabled','true'); 
1009                                 } );
1010                                 for (var i = 0; i < p_org.children().length; i++) {
1011                                         funcs.push(
1012                                                 function(o) {
1013                                                         return function() {
1014                                                                 obj.show_libs( o, false );
1015                                                         }
1016                                                 }( p_org.children()[i] )
1017                                         );
1018                                 }
1019                                 funcs.push( function() { 
1020                                         document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1021                                         document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1022                                         document.getElementById('lib_menu').setAttribute('disabled','false'); 
1023                                 } );
1024                                 exec.chain( funcs );
1025                         }
1026                 } catch(E) {
1027                         alert(E);
1028                 }
1029         },
1030
1031         'show_all_libs' : function() {
1032                 var obj = this;
1033                 try {
1034                         obj.show_my_libs();
1035
1036                         obj.show_libs( obj.data.tree.aou );
1037
1038                         JSAN.use('util.exec'); var exec = new util.exec();
1039                         var funcs = [];
1040                         funcs.push( function() { 
1041                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1042                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1043                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1044                         } );
1045
1046                         for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
1047                                 funcs.push(
1048                                         function(o) {
1049                                                 return function() {
1050                                                         obj.show_libs( o );
1051                                                 }
1052                                         }( obj.data.tree.aou.children()[i] )
1053                                 );
1054                         }
1055                         funcs.push( function() { 
1056                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1057                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1058                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1059                         } );
1060
1061                         exec.chain( funcs );
1062                 } catch(E) {
1063                         alert(E);
1064                 }
1065         },
1066
1067         'show_libs_with_copies' : function() {
1068                 var obj = this;
1069                 try {
1070                         JSAN.use('util.exec'); var exec = new util.exec();
1071                         JSAN.use('util.functional');
1072
1073                         var orgs = util.functional.map_list(
1074                                 obj.org_ids,
1075                                 function(id) { return obj.data.hash.aou[id]; }
1076                         ).sort(
1077                                 function( a, b ) {
1078                                         if (a.shortname() < b.shortname()) return -1;
1079                                         if (a.shortname() > b.shortname()) return 1;
1080                                         return 0;
1081                                 }
1082                         );
1083                         var funcs = [];
1084                         funcs.push( function() { 
1085                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1086                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1087                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1088                         } );
1089
1090                         for (var i = 0; i < orgs.length; i++) {
1091                                 funcs.push(
1092                                         function(o) {
1093                                                 return function() {
1094                                                         obj.show_libs(o,false);
1095                                                 }
1096                                         }( orgs[i] )
1097                                 );
1098                         }
1099                         funcs.push( function() { 
1100                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1101                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1102                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1103                         } );
1104
1105                         exec.chain( funcs );
1106                 } catch(E) {
1107                         alert(E);
1108                 }
1109         },
1110
1111         'show_libs' : function(start_aou,show_open) {
1112                 var obj = this;
1113                 try {
1114                         if (!start_aou) throw('show_libs: Need a start_aou');
1115                         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1116                         JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
1117
1118                         var funcs = [];
1119
1120                         var parents = [];
1121                         var temp_aou = start_aou;
1122                         while ( temp_aou.parent_ou() ) {
1123                                 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
1124                                 parents.push( temp_aou );
1125                         }
1126                         parents.reverse();
1127
1128                         for (var i = 0; i < parents.length; i++) {
1129                                 funcs.push(
1130                                         function(o,p) {
1131                                                 return function() { 
1132                                                         if (show_open) {
1133                                                                 obj.append_org(o,p,{'container':'true','open':'true'}); 
1134                                                         } else {
1135                                                                 obj.append_org(o,p,{'container':'true'}); 
1136                                                         }
1137                                                 };
1138                                         }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
1139                                 );
1140                         }
1141
1142                         funcs.push(
1143                                 function(o,p) {
1144                                         return function() { obj.append_org(o,p); };
1145                                 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
1146                         );
1147
1148                         funcs.push(
1149                                 function() {
1150                                         if (start_aou.children()) {
1151                                                 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
1152                                                 x.setAttribute('container','true');
1153                                                 if (show_open) x.setAttribute('open','true');
1154                                                 for (var i = 0; i < start_aou.children().length; i++) {
1155                                                         funcs.push(
1156                                                                 function(o,p) {
1157                                                                         return function() { obj.append_org(o,p); };
1158                                                                 }( start_aou.children()[i], start_aou )
1159                                                         );
1160                                                 }
1161                                         }
1162                                 }
1163                         );
1164
1165                         exec.chain( funcs );
1166
1167                 } catch(E) {
1168                         alert(E);
1169                 }
1170         },
1171
1172         'on_select' : function(list,twisty) {
1173                 var obj = this;
1174                 for (var i = 0; i < list.length; i++) {
1175                         var node = obj.map_tree[ list[i] ];
1176                         //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
1177                         var row_type = list[i].split('_')[0];
1178                         var id = list[i].split('_')[1];
1179                         switch(row_type) {
1180                                 case 'aou' : obj.on_select_org(id,twisty); break;
1181                                 case 'acn' : obj.on_select_acn(id,twisty); break;
1182                                 default: break;
1183                         }
1184                 }
1185         },
1186
1187         'on_select_acn' : function(acn_id,twisty) {
1188                 var obj = this;
1189                 try {
1190                         var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
1191                         var funcs = [];
1192                         funcs.push( function() { 
1193                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','true'); 
1194                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true'); 
1195                                 document.getElementById('lib_menu').setAttribute('disabled','true'); 
1196                         } );
1197                         if (acn_tree.copies()) {
1198                                 for (var i = 0; i < acn_tree.copies().length; i++) {
1199                                         funcs.push(
1200                                                 function(c,a) {
1201                                                         return function() {
1202                                                                 obj.append_acp(c,a);
1203                                                         }
1204                                                 }( acn_tree.copies()[i], acn_tree )
1205                                         )
1206                                 }
1207                         }
1208                         funcs.push( function() { 
1209                                 document.getElementById('cmd_refresh_list').setAttribute('disabled','false'); 
1210                                 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false'); 
1211                                 document.getElementById('lib_menu').setAttribute('disabled','false'); 
1212                         } );
1213                         JSAN.use('util.exec'); var exec = new util.exec();
1214                         exec.chain( funcs );
1215                 } catch(E) {
1216                         alert(E);
1217                 }
1218         },
1219
1220         'on_select_org' : function(org_id,twisty) {
1221                 var obj = this;
1222                 var org = obj.data.hash.aou[ org_id ];
1223                 if (obj.data.hash.aout[ org.ou_type() ].depth() == 0) return; 
1224                 /* otherwise, we'd show every system in the consortia */
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 ) {
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');