063e40e97605c1c587cbd6b81d8ef230c029521b
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / rdetail.js
1 /* */
2
3
4 detachAllEvt('common', 'run');
5 attachEvt("common", "run", rdetailDraw);
6 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
7 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
8 attachEvt("rdetail", "recordDrawn", rdetailGetPageIds);
9
10 var record = null;
11 var cp_statuses = null;
12 var recordsCache = [];
13
14 var copyRowParent = null;
15 var copyRow = null;
16 var statusRow = null;
17 var numStatuses = null;
18 var defaultCN;
19 var callnumberCache = {};
20 var rdetailLocalOnly = true;
21 var globalCNCache       = {};
22 var localTOC;
23 var cachedRecords;
24
25 var rdetailShowLocal = true;
26
27
28
29 var nextContainerIndex;
30
31 function rdetailReload() {
32         var args = {};
33         args[PARAM_LOCATION] = getNewSearchLocation();
34         args[PARAM_DEPTH] = depthSelGetDepth();
35         goTo(buildOPACLink(args));
36 }
37
38 var nextRecord;
39 var prevRecord;
40
41 var rdetailPrev = null;
42 var rdetailNext = null;
43 var rdetailStart = null;
44 var rdetailEnd = null;
45
46
47
48 /* looks to see if we have a next and/or previous record in the
49 record cache, if so, set up the nav links */
50 function rdetailSetPaging(ids) {
51
52         cachedRecords = {};
53         cachedRecords.ids = ids;
54
55         for( var i = 0; i < cachedRecords.ids.length; i++ ) {
56                 var rec = cachedRecords.ids[i];
57                 if( rec == getRid() ) {
58                         if( i > 0 ) prevRecord = cachedRecords.ids[i-1];
59                         if( i < cachedRecords.ids.length - 1 )
60                                 nextRecord = cachedRecords.ids[i+1];
61                         break;
62                 }
63         }
64
65         $('np_offset').appendChild(text(i + 1));
66         $('np_count').appendChild(text(getHitCount()));
67
68         if(prevRecord) {
69                 unHideMe($('np_table'));
70                 unHideMe($('np_prev'));
71                 unHideMe($('np_start'));
72                 rdetailPrev = function() { _rdetailNav(prevRecord); };
73                 rdetailStart = function() { _rdetailNav(cachedRecords.ids[0]); };
74         }
75
76         if(nextRecord) {
77                 unHideMe($('np_table'));
78                 unHideMe($('np_next'));
79                 unHideMe($('np_end'));
80                 rdetailNext = function() { _rdetailNav(nextRecord); };
81                 rdetailEnd = function() { _rdetailNav(cachedRecords.ids[cachedRecords.ids.length-1]); };
82         }
83
84         runEvt('rdetail', 'nextPrevDrawn', i, cachedRecords.ids.length);
85 }
86
87
88 function _rdetailNav(id, offset) {
89         var args = {};
90         args[PARAM_RID] = id;
91         goTo(buildOPACLink(args));
92 }
93
94 function rdetailDraw() {
95
96         detachAllEvt('common','depthChanged');
97         detachAllEvt('common','locationUpdated');
98         attachEvt('common','depthChanged', rdetailReload);
99         attachEvt('common','locationUpdated', rdetailReload);
100         attachEvt('common','holdUpdated', rdetailReload);
101         attachEvt('common','holdUpdateCanceled', rdetailReload);
102
103         copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
104         copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
105         statusRow = G.ui.rdetail.cp_status.parentNode;
106         statusRow.id = '__rdsrow';
107
108         G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
109         G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
110
111         if(getLocation() == globalOrgTree.id())
112                 hideMe(G.ui.rdetail.cp_info_all);
113
114         var req = new Request(FETCH_RMODS, getRid());
115         req.callback(_rdetailDraw);
116         req.send();
117
118         detachAllEvt("result", "idsReceived");
119         G.evt.result.hitCountReceived = [];
120         G.evt.result.recordReceived = [];
121         G.evt.result.copyCountsReceived = [];
122         G.evt.result.allRecordsReceived = [];
123 }
124
125 function rdetailGetPageIds() {
126         attachEvt("result", "idsReceived", rdetailSetPaging );
127         resultFetchAllRecords = true;
128         rresultCollectIds(true);
129 }
130
131
132 function buildunAPISpan (span, type, id) {
133         var cgi = new CGI();
134         var d = new Date();
135
136         addCSSClass(span,'unapi-id');
137
138         span.setAttribute(
139                 'title', 'tag:' + cgi.server_name + ',' +
140                 d.getFullYear() + ':' + type + '/' + id
141         );
142 }
143
144 function rdetailViewMarc(r,id) {
145         hideMe($('rdetail_extras_loading'));
146         $('rdetail_view_marc_box').innerHTML = r.getResultObject();
147
148         var div = elem('div', { "class" : 'hide_me' });
149         var span = div.appendChild( elem('abbr') );
150
151         buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
152
153         $('rdetail_view_marc_box').insertBefore(span, $('rdetail_view_marc_box').firstChild);
154 }
155
156
157 function rdetailShowLocalCopies() {
158         rdetailShowLocal = true;
159         rdetailBuildInfoRows();
160         hideMe(G.ui.rdetail.cp_info_local);
161         unHideMe(G.ui.rdetail.cp_info_all);
162         hideMe(G.ui.rdetail.cp_info_none); 
163 }
164
165 function rdetailShowAllCopies() {
166
167         rdetailShowLocal = false;
168         rdetailBuildInfoRows();
169         hideMe(G.ui.rdetail.cp_info_all);
170         unHideMe(G.ui.rdetail.cp_info_local);
171         hideMe(G.ui.rdetail.cp_info_none); 
172 }
173
174
175 function _rdetailDraw(r) {
176         record = r.getResultObject();
177
178         runEvt('rdetail', 'recordRetrieved', record.doc_id());
179
180         G.ui.rdetail.title.appendChild(text(record.title()));
181         buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
182         G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
183         G.ui.rdetail.edition.appendChild(text(record.edition()));
184         G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
185         G.ui.rdetail.publisher.appendChild(text(record.publisher()));
186         $('rdetail_physical_desc').appendChild(text(record.physical_description()));
187     r = record.types_of_resource();
188     if(r) {
189         G.ui.rdetail.tor.appendChild(text(r[0]));
190             setResourcePic( G.ui.rdetail.tor_pic, r[0]);
191     }
192         G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
193
194     try{
195         if(record.isbn()) {
196             if(ENABLE_ADDED_CONTENT_ATTRIB_LINKS) {
197                 unHideMe($('rdetail.jacket_attrib_div'));
198                 var href = $('rdetail.jacket_attrib_link').getAttribute('href') +cleanISBN(record.isbn());
199                 $('rdetail.jacket_attrib_link').setAttribute('href', href);
200             }
201         } else {
202             hideMe($("rdetail.jacket_attrib_div"));
203             hideMe($("rdetail_img_link"));
204         }
205     } catch(E) {}
206
207
208         // see if the record has any external links 
209         var links = record.online_loc();
210         for( var i = 0; links && links.length > 0 && i < links.length; i++ ) {
211                 var href = links[i];
212                 if( href.match(/http/) ) {
213                         unHideMe($('rdetail_online_row'));
214                         var name = links[i+1];
215                         if(!name || name.match(/http/)) name = href;
216                         $('rdetail_online').appendChild(elem('a', {href:href,'class':'classic_link'}, name));
217                         $('rdetail_online').appendChild(elem('br'));
218                 }
219         }
220
221
222         $('rdetail_place_hold').setAttribute(
223                 'href','javascript:holdsDrawEditor({record:"'+record.doc_id()+'",type:"T"});');
224
225         $('rdetail_img_link').setAttribute('href', buildISBNSrc(cleanISBN(record.isbn()), 'large'));
226         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
227         runEvt("rdetail", "recordDrawn");
228         recordsCache.push(record);
229
230         rdetailSetExtrasSelector();
231
232         var breq = new Request(FETCH_BRE, [getRid()]);
233         breq.callback( rdetailCheckDeleted );
234         breq.send();
235
236         resultBuildCaches( [ record ] );
237         resultDrawSubjects();
238         resultDrawSeries();
239
240         // grab added content 
241         acCollectData(cleanISBN(record.isbn()), rdetailhandleAC);
242 }
243
244
245
246 function rdetailCheckDeleted(r) {
247         var br = r.getResultObject()[0];
248         if( isTrue(br.deleted()) ) {
249                 hideMe($('rdetail_place_hold'));
250                 $('rdetail_more_actions_selector').disabled = true;
251                 unHideMe($('rdetail_deleted_exp'));
252         }
253 }
254
255 function rdetailSetExtrasSelector() {
256         if(!grabUser()) return;
257         unHideMe($('rdetail_more_actions'));
258
259         var req = new Request( 
260                 FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
261         req.callback(rdetailAddBookbags);
262         req.send();
263 }
264
265 function rdetailAddBookbags(r) {
266
267         var containers = r.getResultObject();
268         var selector = $('rdetail_more_actions_selector');
269         var found = false;
270         var index = 3;
271         doSelectorActions(selector);
272
273         for( var i = 0; i != containers.length; i++ ) {
274                 found = true;
275                 var container = containers[i];
276                 insertSelectorVal( selector, index++, container.name(), 
277                         "container_" + container.id(), rdetailAddToBookbag,  1 );
278         }
279
280         nextContainerIndex = index;
281 }
282
283 var _actions = {};
284 function rdetailNewBookbag() {
285         var name = prompt($('rdetail_bb_new').innerHTML,"");
286         if(!name) return;
287
288         var id;
289         if( id = containerCreate( name ) ) {
290                 alert($('rdetail_bb_success').innerHTML);
291                 var selector = $('rdetail_more_actions_selector');
292                 insertSelectorVal( selector, nextContainerIndex++, name, 
293                         "container_" + id, rdetailAddToBookbag, 1 );
294                 setSelector( selector, 'start' );
295         }
296 }
297
298
299 function rdetailAddToBookbag() {
300         var selector = $('rdetail_more_actions_selector');
301         var id = selector.options[selector.selectedIndex].value;
302         setSelector( selector, 'start' );
303
304         if( containerCreateItem( id.substring(10), record.doc_id() )) {
305                 alert($('rdetail_bb_item_success').innerHTML);
306         }
307 }
308
309
310 var rdetailMarcFetched = false;
311 function rdetailShowExtra(type, args) {
312
313         hideMe($('rdetail_copy_info_div'));
314         hideMe($('rdetail_reviews_div'));
315         hideMe($('rdetail_toc_div'));
316         hideMe($('rdetail_anotes_div'));
317         hideMe($('rdetail_excerpt_div'));
318         hideMe($('rdetail_marc_div'));
319         hideMe($('cn_browse'));
320         hideMe($('rdetail_cn_browse_div'));
321         hideMe($('rdetail_notes_div'));
322
323         removeCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
324         removeCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
325         removeCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
326         removeCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
327         removeCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
328         removeCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
329         removeCSSClass($('rdetail_annotation_link'), 'rdetail_extras_selected');
330         removeCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
331
332         switch(type) {
333
334                 case "copyinfo": 
335                         unHideMe($('rdetail_copy_info_div')); 
336                         addCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
337                         break;
338
339                 case "reviews": 
340                         addCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
341                         unHideMe($('rdetail_reviews_div')); 
342                         break;
343
344
345                 case "excerpt": 
346                         addCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
347                         unHideMe($('rdetail_excerpt_div'));
348                         break;
349
350                 case "anotes": 
351                         addCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
352                         unHideMe($('rdetail_anotes_div'));
353                         break;
354
355
356                 case "toc": 
357                         addCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
358                         unHideMe($('rdetail_toc_div'));
359                         break;
360
361                 case "marc": 
362                         addCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
363                         unHideMe($('rdetail_marc_div')); 
364                         if(rdetailMarcFetched) return;
365                         unHideMe($('rdetail_extras_loading'));
366                         rdetailMarcFetched = true;
367                         var req = new Request( FETCH_MARC_HTML, record.doc_id() );
368                         req.callback(rdetailViewMarc); 
369                         req.send();
370                         break;
371
372                 case 'cn':
373                         addCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
374                         unHideMe($('rdetail_cn_browse_div'));
375                         rdetailShowCNBrowse(defaultCN, getLocation(), null, true);
376                         break;
377
378         }
379 }
380
381 function rdetailVolumeDetails(args) {
382         var row = $(args.rowid);
383         var tbody = row.parentNode;
384         cpdBuild( tbody, row, record, args.cn, args.org, args.depth );
385         return;
386 }
387
388
389 function rdetailBuildCNList() {
390
391         var select = $('cn_browse_selector');
392         var index = 0;
393         var arr = [];
394         for( var cn in callnumberCache ) arr.push( cn );
395         arr.sort();
396
397         if( arr.length == 0 ) {
398                 hideMe($('rdetail_cn_browse_select_div'));
399                 return;
400         }
401
402         for( var i in arr ) {
403                 var cn = arr[i];
404                 var opt = new Option(cn);
405                 select.options[index++] = opt;
406         }
407         select.onchange = rdetailGatherCN;
408 }
409
410 function rdetailGatherCN() {
411         var cn = getSelectorVal($('cn_browse_selector'));
412         rdetailShowCNBrowse( cn, getLocation(), getDepth(), true );
413         setSelector( $('cn_browse_selector'), cn );
414 }
415
416
417 function rdetailShowCNBrowse( cn, loc, depth, fromOnclick ) {
418
419         if(!cn) {
420                 unHideMe($('cn_browse_none'));
421                 hideMe($('rdetail_cn_browse_select_div'));
422                 return;
423         }
424                 
425         unHideMe($('rdetail_cn_browse_select_div'));
426         rdetailBuildCNList();
427         setSelector( $('cn_browse_selector'), cn );
428         hideMe($('rdetail_copy_info_div'));
429         hideMe($('rdetail_reviews_div'));
430         hideMe($('rdetail_toc_div'));
431         hideMe($('rdetail_marc_div'));
432         unHideMe($('rdetail_cn_browse_div'));
433         unHideMe($('cn_browse'));
434         if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
435         cnBrowseGo(cn, loc, depth);
436 }
437
438 function rdetailhandleAC(data) {
439
440         if( data.reviews.html ) {
441                 $('rdetail_review_container').innerHTML = data.reviews.html;
442                 unHideMe($('rdetail_reviews_link'));
443         }
444
445         if( data.toc.html ) {
446                 $('rdetail_toc_div').innerHTML = data.toc.html;
447                 unHideMe($('rdetail_toc_link'));
448         }
449
450         if( data.excerpt.html ) {
451                 $('rdetail_excerpt_div').innerHTML = data.excerpt.html;
452                 unHideMe($('rdetail_excerpt_link'));
453         }
454
455         if( data.anotes.html ) {
456                 $('rdetail_anotes_div').innerHTML = data.anotes.html;
457                 unHideMe($('rdetail_anotes_link'));
458         }
459 }
460
461 function rdetailShowReviews(r) {
462         hideMe($('rdetail_extras_loading'));
463         var res = r.getResultObject();
464         var par = $('rdetail_reviews_div');
465         var template = par.removeChild($('rdetail_review_template'));
466         if( res && res.length > 0 ) {
467                 unHideMe($('rdetail_reviews_link'));
468                 for( var i = 0; i != res.length; i++ ) {
469                         var rev = res[i];       
470                         if( rev.text && rev.info ) {
471                                 var node = template.cloneNode(true);
472                                 $n(node, 'review_header').appendChild(text(rev.info));
473                                 $n(node, 'review_text').appendChild(text(rev.text));
474                                 par.appendChild(node);
475                         }
476                 }
477         }
478 }
479
480
481 function rdetailShowTOC(r) {
482         hideMe($('rdetail_extras_loading'));
483         var resp = r.getResultObject();
484         if(resp) {
485                 unHideMe($('rdetail_toc_link'));
486                 $('rdetail_toc_div').innerHTML = resp;
487         }
488 }
489
490
491 function rdetailBuildInfoRows() {
492         var req;
493         if( rdetailShowLocal ) 
494                 req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id(), getLocation(), getDepth())
495         else
496                 req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id());
497         req.callback(_rdetailBuildInfoRows);
498         req.send();
499 }
500
501 function _rdetailRows(node) {
502
503         if( rdetailShowLocal && getLocation() != globalOrgTree.id() ) {
504
505                 var loc = findOrgUnit(getLocation());
506
507                 if( node ) {
508                         if( !orgIsMine(loc, node) ) return;
509
510                 } else {
511
512                         for( var i = 0; i < globalOrgTree.children().length; i++ ) {
513                                 var org = findOrgUnit(globalOrgTree.children()[i]);
514                                 if( orgIsMine(org, loc) ) {
515                                         node = org;
516                                         break;
517                                 }
518                         }
519                 } 
520         }
521
522     /* don't show hidden orgs */
523
524         if(node) {
525
526         if(!isXUL() && !isTrue(node.opac_visible())) return;
527
528                 var row = copyRow.cloneNode(true);
529                 row.id = "cp_info_" + node.id();
530
531                 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
532                 var cntd  = findNodeByName( row, config.names.rdetail.cn_cell );
533                 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
534                 var actions = $n(row, 'rdetail_actions_cell');
535         
536                 var p = libtd.getElementsByTagName('a')[0];
537                 libtd.insertBefore(text(node.name()), p);
538                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
539         
540                 if(!findOrgType(node.ou_type()).can_have_vols()) {
541
542                         row.removeChild(cntd);
543                         row.removeChild(cpctd);
544                         row.removeChild(actions);
545                         row.setAttribute('novols', '1');
546
547                         libtd.setAttribute("colspan", numStatuses + 3 );
548                         libtd.colSpan = numStatuses + 3;
549                         addCSSClass(row, 'copy_info_region_row');
550                 } 
551         
552                 copyRowParent.appendChild(row);
553
554         } else { node = globalOrgTree; }
555
556         for( var c in node.children() ) 
557                 _rdetailRows(node.children()[c]);
558 }
559
560 function rdetailCNPrint(orgid, cn) {
561         var div = cpdBuildPrintWindow( record, orgid);
562         var template = div.removeChild($n(div, 'cnrow'));
563         var rowNode = $("cp_info_" + orgid);
564         cpdStylePopupWindow(div);
565         openWindow(div.innerHTML);
566 }
567
568 var localCNFound = false;
569 var ctr = 0;
570 function _rdetailBuildInfoRows(r) {
571
572         removeChildren(copyRowParent);
573
574         _rdetailRows();
575
576         var summary = r.getResultObject();
577         if(!summary) return;
578
579         var found = false;
580         for( var i = 0; i < summary.length; i++ ) {
581
582                 var arr = summary[i];
583                 globalCNCache[arr[1]] = 1;
584                 var thisOrg = findOrgUnit(arr[0]);
585                 var rowNode = $("cp_info_" + thisOrg.id());
586                 if(!rowNode) continue;
587
588                 if(rowNode.getAttribute("used")) {
589
590                         if( rowNode.nextSibling ) {
591                 sib = rowNode.nextSibling;
592                 o ='cp_info_'+thisOrg.id()+'_';
593                 /* push the new row on as the last row for this org unit */
594                 while( sib && sib.id.match(o) ) {
595                     sib = sib.nextSibling;
596                 }
597                 if(sib)
598                                     rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), sib);
599                 else
600                     rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
601             } else {
602                                 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
603             }
604
605                         var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
606                         n.appendChild(text(thisOrg.name()));
607                         n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1)  * 9) + "px;");
608                         rowNode.id = "cp_info_" + thisOrg.id() + '_' + (++ctr); 
609
610                 } else {
611                         rowNode.setAttribute("used", "1");
612                 }
613
614                 var cpc_temp = rowNode.removeChild(
615                         findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
616
617                 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
618
619                 var isLocal = false;
620                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { 
621                         found = true; 
622                         isLocal = true; 
623                         if(!localCNFound) {
624                                 localCNFound = true;
625                                 defaultCN = arr[1];
626                         }
627                 }
628
629                 //if(isLocal) unHideMe(rowNode);
630                 unHideMe(rowNode);
631
632                 rdetailSetPath( thisOrg, isLocal );
633                 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal, thisOrg );
634
635                 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
636         }
637
638         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
639 }
640
641
642 function rdetailBuildBrowseInfo(row, cn, local, orgNode) {
643
644         if(local) {
645                 var cache = callnumberCache[cn];
646                 if( cache ) cache.count++;
647                 else callnumberCache[cn] = { count : 1 };
648         }
649
650         var depth = getDepth();
651         if( !local ) depth = findOrgDepth(globalOrgTree);
652
653         $n(row, 'rdetail_callnumber_cell').appendChild(text(cn));
654
655         _debug('setting action clicks for cn ' + cn);
656
657         var dHref = 'javascript:rdetailVolumeDetails('+
658                 '{rowid : "'+row.id+'", cn :"'+cn+'", depth:"'+depth+'", org:"'+orgNode.id()+'", local: '+local+'});';
659
660         var bHref = 'javascript:rdetailShowCNBrowse("' + cn + '", '+orgNode.id()+', "'+depth+'");'; 
661
662         $n(row, 'details').setAttribute('href', dHref);
663         $n(row, 'browse').setAttribute('href', bHref);
664
665         if(isXUL()) {
666                 unHideMe($n(row, 'hold_div'));
667                 $n(row, 'hold').onclick = function() {
668                         var req = new Request(FETCH_VOLUME_BY_INFO, cn, record.doc_id(), orgNode.id());
669                         req.callback(
670                                 function(r) {
671                                         var vol = r.getResultObject();
672                                         holdsDrawEditor({type: 'V', volumeObject : vol});
673                                 }
674                         );
675                         req.send();
676                 };
677         }
678 }
679
680
681 // sets the path to org as 'active' and displays the path if it's local 
682 function rdetailSetPath(org, local) {
683         if( findOrgDepth(org) == 0 ) return;
684         var row = $("cp_info_" + org.id());
685         row.setAttribute("hasinfo", "1");
686         unHideMe(row);
687         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
688 }
689
690
691
692
693 //Append all the statuses for a give summary to the 
694 //copy summary table 
695 function rdetailApplyStatuses( row, template, statuses ) {
696         for( var j in _statusPositions ) {
697                 var stat = _statusPositions[j];
698                 var val = statuses[stat.id()];
699                 var nn = template.cloneNode(true);
700                 if(val) nn.appendChild(text(val));
701                 else nn.appendChild(text(0));
702                 row.appendChild(nn);    
703         }
704 }
705
706
707 var _statusPositions = {};
708
709 //Add one td (creating a new column) to the copy summary
710 //table for each opac_visible copy status
711
712 function rdetailBuildStatusColumns() {
713
714         rdetailGrabCopyStatuses();
715         var parent = statusRow;
716         var template = parent.removeChild(G.ui.rdetail.cp_status);
717
718         var i = 0;
719         for( i = 0; i < cp_statuses.length; i++ ) {
720
721                 var c = cp_statuses[i];
722                 if( c && isTrue(c.opac_visible()) ) {
723                         var name = c.name();
724                         _statusPositions[i] = c;
725                         var node = template.cloneNode(true);
726                         var data = findNodeByName( node, config.names.rdetail.cp_status);
727         
728                         data.appendChild(text(name));
729                         parent.appendChild(node);
730                 }
731         }       
732
733         numStatuses = 0;
734         for(x in _statusPositions) numStatuses++; 
735 }
736
737 function rdetailGrabCopyStatuses() {
738         if(cp_statuses) return cp_statuses;
739    var req = new Request(FETCH_COPY_STATUSES);
740    req.send(true);
741         cp_statuses = req.result();
742         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
743 }
744
745 function _rdetailSortStatuses(a, b) {
746         return parseInt(a.id()) - parseInt(b.id());
747 }
748