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