Typo: MODS doesn't define "abreviated"
[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 = i + 2 ) {
211                 var href = links[i];
212                 // avoid matching "HTTP: The Complete Reference"
213                 if( href.match(/https?:\/|ftps?:\/|mailto:/i) ) {
214                         unHideMe($('rdetail_online_row'));
215                         var name = '' + links[i+1];
216                         if(!name || name.match(/https?:\/|ftps?:\/|mailto:/i)) name = href;
217                         $('rdetail_online').appendChild(elem('a', {href:href,'class':'classic_link'}, name));
218                         $('rdetail_online').appendChild(elem('br'));
219                 }
220         }
221
222
223         $('rdetail_place_hold').setAttribute(
224                 'href','javascript:holdsDrawEditor({record:"'+record.doc_id()+'",type:"T"});');
225
226         $('rdetail_img_link').setAttribute('href', buildISBNSrc(cleanISBN(record.isbn()), 'large'));
227         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
228         runEvt("rdetail", "recordDrawn");
229         recordsCache.push(record);
230
231         rdetailSetExtrasSelector();
232
233         var breq = new Request(FETCH_BRE, [getRid()]);
234         breq.callback( rdetailCheckDeleted );
235         breq.send();
236
237         resultBuildCaches( [ record ] );
238         resultDrawSubjects();
239         resultDrawSeries();
240
241         // grab added content 
242         acCollectData(cleanISBN(record.isbn()), rdetailhandleAC);
243 }
244
245
246
247 function rdetailCheckDeleted(r) {
248         var br = r.getResultObject()[0];
249         if( isTrue(br.deleted()) ) {
250                 hideMe($('rdetail_place_hold'));
251                 $('rdetail_more_actions_selector').disabled = true;
252                 unHideMe($('rdetail_deleted_exp'));
253         }
254 }
255
256 function rdetailSetExtrasSelector() {
257         if(!grabUser()) return;
258         unHideMe($('rdetail_more_actions'));
259
260         var req = new Request( 
261                 FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
262         req.callback(rdetailAddBookbags);
263         req.send();
264 }
265
266 function rdetailAddBookbags(r) {
267
268         var containers = r.getResultObject();
269         var selector = $('rdetail_more_actions_selector');
270         var found = false;
271         var index = 3;
272         doSelectorActions(selector);
273
274         for( var i = 0; i != containers.length; i++ ) {
275                 found = true;
276                 var container = containers[i];
277                 insertSelectorVal( selector, index++, container.name(), 
278                         "container_" + container.id(), rdetailAddToBookbag,  1 );
279         }
280
281         nextContainerIndex = index;
282 }
283
284 var _actions = {};
285 function rdetailNewBookbag() {
286         var name = prompt($('rdetail_bb_new').innerHTML,"");
287         if(!name) return;
288
289         var id;
290         if( id = containerCreate( name ) ) {
291                 alert($('rdetail_bb_success').innerHTML);
292                 var selector = $('rdetail_more_actions_selector');
293                 insertSelectorVal( selector, nextContainerIndex++, name, 
294                         "container_" + id, rdetailAddToBookbag, 1 );
295                 setSelector( selector, 'start' );
296         }
297 }
298
299
300 function rdetailAddToBookbag() {
301         var selector = $('rdetail_more_actions_selector');
302         var id = selector.options[selector.selectedIndex].value;
303         setSelector( selector, 'start' );
304
305         if( containerCreateItem( id.substring(10), record.doc_id() )) {
306                 alert($('rdetail_bb_item_success').innerHTML);
307         }
308 }
309
310
311 var rdetailMarcFetched = false;
312 function rdetailShowExtra(type, args) {
313
314         hideMe($('rdetail_copy_info_div'));
315         hideMe($('rdetail_reviews_div'));
316         hideMe($('rdetail_toc_div'));
317         hideMe($('rdetail_anotes_div'));
318         hideMe($('rdetail_excerpt_div'));
319         hideMe($('rdetail_marc_div'));
320         hideMe($('cn_browse'));
321         hideMe($('rdetail_cn_browse_div'));
322         hideMe($('rdetail_notes_div'));
323
324         removeCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
325         removeCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
326         removeCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
327         removeCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
328         removeCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
329         removeCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
330         removeCSSClass($('rdetail_annotation_link'), 'rdetail_extras_selected');
331         removeCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
332
333         switch(type) {
334
335                 case "copyinfo": 
336                         unHideMe($('rdetail_copy_info_div')); 
337                         addCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
338                         break;
339
340                 case "reviews": 
341                         addCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
342                         unHideMe($('rdetail_reviews_div')); 
343                         break;
344
345
346                 case "excerpt": 
347                         addCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
348                         unHideMe($('rdetail_excerpt_div'));
349                         break;
350
351                 case "anotes": 
352                         addCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
353                         unHideMe($('rdetail_anotes_div'));
354                         break;
355
356
357                 case "toc": 
358                         addCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
359                         unHideMe($('rdetail_toc_div'));
360                         break;
361
362                 case "marc": 
363                         addCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
364                         unHideMe($('rdetail_marc_div')); 
365                         if(rdetailMarcFetched) return;
366                         unHideMe($('rdetail_extras_loading'));
367                         rdetailMarcFetched = true;
368                         var req = new Request( FETCH_MARC_HTML, record.doc_id() );
369                         req.callback(rdetailViewMarc); 
370                         req.send();
371                         break;
372
373                 case 'cn':
374                         addCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
375                         unHideMe($('rdetail_cn_browse_div'));
376                         rdetailShowCNBrowse(defaultCN, getLocation(), null, true);
377                         break;
378
379         }
380 }
381
382 function rdetailVolumeDetails(args) {
383         var row = $(args.rowid);
384         var tbody = row.parentNode;
385         cpdBuild( tbody, row, record, args.cn, args.org, args.depth );
386         return;
387 }
388
389
390 function rdetailBuildCNList() {
391
392         var select = $('cn_browse_selector');
393         var index = 0;
394         var arr = [];
395         for( var cn in callnumberCache ) arr.push( cn );
396         arr.sort();
397
398         if( arr.length == 0 ) {
399                 hideMe($('rdetail_cn_browse_select_div'));
400                 return;
401         }
402
403         for( var i in arr ) {
404                 var cn = arr[i];
405                 var opt = new Option(cn);
406                 select.options[index++] = opt;
407         }
408         select.onchange = rdetailGatherCN;
409 }
410
411 function rdetailGatherCN() {
412         var cn = getSelectorVal($('cn_browse_selector'));
413         rdetailShowCNBrowse( cn, getLocation(), getDepth(), true );
414         setSelector( $('cn_browse_selector'), cn );
415 }
416
417
418 function rdetailShowCNBrowse( cn, loc, depth, fromOnclick ) {
419
420         if(!cn) {
421                 unHideMe($('cn_browse_none'));
422                 hideMe($('rdetail_cn_browse_select_div'));
423                 return;
424         }
425                 
426         unHideMe($('rdetail_cn_browse_select_div'));
427         rdetailBuildCNList();
428         setSelector( $('cn_browse_selector'), cn );
429         hideMe($('rdetail_copy_info_div'));
430         hideMe($('rdetail_reviews_div'));
431         hideMe($('rdetail_toc_div'));
432         hideMe($('rdetail_marc_div'));
433         unHideMe($('rdetail_cn_browse_div'));
434         unHideMe($('cn_browse'));
435         if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
436         cnBrowseGo(cn, loc, depth);
437 }
438
439 function rdetailhandleAC(data) {
440
441         if( data.reviews.html ) {
442                 $('rdetail_review_container').innerHTML = data.reviews.html;
443                 unHideMe($('rdetail_reviews_link'));
444         }
445
446         if( data.toc.html ) {
447                 $('rdetail_toc_div').innerHTML = data.toc.html;
448                 unHideMe($('rdetail_toc_link'));
449         }
450
451         if( data.excerpt.html ) {
452                 $('rdetail_excerpt_div').innerHTML = data.excerpt.html;
453                 unHideMe($('rdetail_excerpt_link'));
454         }
455
456         if( data.anotes.html ) {
457                 $('rdetail_anotes_div').innerHTML = data.anotes.html;
458                 unHideMe($('rdetail_anotes_link'));
459         }
460 }
461
462 function rdetailShowReviews(r) {
463         hideMe($('rdetail_extras_loading'));
464         var res = r.getResultObject();
465         var par = $('rdetail_reviews_div');
466         var template = par.removeChild($('rdetail_review_template'));
467         if( res && res.length > 0 ) {
468                 unHideMe($('rdetail_reviews_link'));
469                 for( var i = 0; i != res.length; i++ ) {
470                         var rev = res[i];       
471                         if( rev.text && rev.info ) {
472                                 var node = template.cloneNode(true);
473                                 $n(node, 'review_header').appendChild(text(rev.info));
474                                 $n(node, 'review_text').appendChild(text(rev.text));
475                                 par.appendChild(node);
476                         }
477                 }
478         }
479 }
480
481
482 function rdetailShowTOC(r) {
483         hideMe($('rdetail_extras_loading'));
484         var resp = r.getResultObject();
485         if(resp) {
486                 unHideMe($('rdetail_toc_link'));
487                 $('rdetail_toc_div').innerHTML = resp;
488         }
489 }
490
491
492 function rdetailBuildInfoRows() {
493         var req;
494         if( rdetailShowLocal ) 
495                 req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id(), getLocation(), getDepth())
496         else
497                 req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id());
498         req.callback(_rdetailBuildInfoRows);
499         req.send();
500 }
501
502 function _rdetailRows(node) {
503
504         if( rdetailShowLocal && getLocation() != globalOrgTree.id() ) {
505
506                 var loc = findOrgUnit(getLocation());
507
508                 if( node ) {
509                         if( !orgIsMine(loc, node) ) return;
510
511                 } else {
512
513                         for( var i = 0; i < globalOrgTree.children().length; i++ ) {
514                                 var org = findOrgUnit(globalOrgTree.children()[i]);
515                                 if( orgIsMine(org, loc) ) {
516                                         node = org;
517                                         break;
518                                 }
519                         }
520                 } 
521         }
522
523     if(!node && findOrgType(globalOrgTree.ou_type()).can_have_vols())
524         node = globalOrgTree;
525
526
527     /* don't show hidden orgs */
528
529         if(node) {
530
531         if(!isXUL() && !isTrue(node.opac_visible())) return;
532
533                 var row = copyRow.cloneNode(true);
534                 row.id = "cp_info_" + node.id();
535
536                 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
537                 var cntd  = findNodeByName( row, config.names.rdetail.cn_cell );
538                 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
539                 var actions = $n(row, 'rdetail_actions_cell');
540         
541                 var p = libtd.getElementsByTagName('a')[0];
542                 libtd.insertBefore(text(node.name()), p);
543                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
544         
545                 if(!findOrgType(node.ou_type()).can_have_vols()) {
546
547                         row.removeChild(cntd);
548                         row.removeChild(cpctd);
549                         row.removeChild(actions);
550                         row.setAttribute('novols', '1');
551
552                         libtd.setAttribute("colspan", numStatuses + 3 );
553                         libtd.colSpan = numStatuses + 3;
554                         addCSSClass(row, 'copy_info_region_row');
555                 } 
556         
557                 copyRowParent.appendChild(row);
558
559         } else { node = globalOrgTree; }
560
561         for( var c in node.children() ) 
562                 _rdetailRows(node.children()[c]);
563 }
564
565 function rdetailCNPrint(orgid, cn) {
566         var div = cpdBuildPrintWindow( record, orgid);
567         var template = div.removeChild($n(div, 'cnrow'));
568         var rowNode = $("cp_info_" + orgid);
569         cpdStylePopupWindow(div);
570         openWindow(div.innerHTML);
571 }
572
573 var localCNFound = false;
574 var ctr = 0;
575 function _rdetailBuildInfoRows(r) {
576
577         removeChildren(copyRowParent);
578
579         _rdetailRows();
580
581         var summary = r.getResultObject();
582         if(!summary) return;
583
584         var found = false;
585         for( var i = 0; i < summary.length; i++ ) {
586
587                 var arr = summary[i];
588                 globalCNCache[arr[1]] = 1;
589                 var thisOrg = findOrgUnit(arr[0]);
590                 var rowNode = $("cp_info_" + thisOrg.id());
591                 if(!rowNode) continue;
592
593                 if(rowNode.getAttribute("used")) {
594
595                         if( rowNode.nextSibling ) {
596                 sib = rowNode.nextSibling;
597                 o ='cp_info_'+thisOrg.id()+'_';
598                 /* push the new row on as the last row for this org unit */
599                 while( sib && sib.id.match(o) ) {
600                     sib = sib.nextSibling;
601                 }
602                 if(sib)
603                                     rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), sib);
604                 else
605                     rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
606             } else {
607                                 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
608             }
609
610                         var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
611                         n.appendChild(text(thisOrg.name()));
612                         n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1)  * 9) + "px;");
613                         rowNode.id = "cp_info_" + thisOrg.id() + '_' + (++ctr); 
614
615                 } else {
616                         rowNode.setAttribute("used", "1");
617                 }
618
619                 var cpc_temp = rowNode.removeChild(
620                         findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
621
622                 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
623
624                 var isLocal = false;
625                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { 
626                         found = true; 
627                         isLocal = true; 
628                         if(!localCNFound) {
629                                 localCNFound = true;
630                                 defaultCN = arr[1];
631                         }
632                 }
633
634                 //if(isLocal) unHideMe(rowNode);
635                 unHideMe(rowNode);
636
637                 rdetailSetPath( thisOrg, isLocal );
638                 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal, thisOrg );
639
640                 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
641         }
642
643         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
644 }
645
646
647 function rdetailBuildBrowseInfo(row, cn, local, orgNode) {
648
649         if(local) {
650                 var cache = callnumberCache[cn];
651                 if( cache ) cache.count++;
652                 else callnumberCache[cn] = { count : 1 };
653         }
654
655         var depth = getDepth();
656         if( !local ) depth = findOrgDepth(globalOrgTree);
657
658         $n(row, 'rdetail_callnumber_cell').appendChild(text(cn));
659
660         _debug('setting action clicks for cn ' + cn);
661
662         var dHref = 'javascript:rdetailVolumeDetails('+
663                 '{rowid : "'+row.id+'", cn :"'+cn+'", depth:"'+depth+'", org:"'+orgNode.id()+'", local: '+local+'});';
664
665         var bHref = 'javascript:rdetailShowCNBrowse("' + cn + '", '+orgNode.id()+', "'+depth+'");'; 
666
667         $n(row, 'details').setAttribute('href', dHref);
668         $n(row, 'browse').setAttribute('href', bHref);
669
670         if(isXUL()) {
671                 unHideMe($n(row, 'hold_div'));
672                 $n(row, 'hold').onclick = function() {
673                         var req = new Request(FETCH_VOLUME_BY_INFO, cn, record.doc_id(), orgNode.id());
674                         req.callback(
675                                 function(r) {
676                                         var vol = r.getResultObject();
677                                         holdsDrawEditor({type: 'V', volumeObject : vol});
678                                 }
679                         );
680                         req.send();
681                 };
682         }
683 }
684
685
686 // sets the path to org as 'active' and displays the path if it's local 
687 function rdetailSetPath(org, local) {
688         if( findOrgDepth(org) == 0 ) return;
689         var row = $("cp_info_" + org.id());
690         row.setAttribute("hasinfo", "1");
691         unHideMe(row);
692         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
693 }
694
695
696
697
698 //Append all the statuses for a give summary to the 
699 //copy summary table 
700 function rdetailApplyStatuses( row, template, statuses ) {
701         for( var j in _statusPositions ) {
702                 var stat = _statusPositions[j];
703                 var val = statuses[stat.id()];
704                 var nn = template.cloneNode(true);
705                 if(val) nn.appendChild(text(val));
706                 else nn.appendChild(text(0));
707                 row.appendChild(nn);    
708         }
709 }
710
711
712 var _statusPositions = {};
713
714 //Add one td (creating a new column) to the copy summary
715 //table for each opac_visible copy status
716
717 function rdetailBuildStatusColumns() {
718
719         rdetailGrabCopyStatuses();
720         var parent = statusRow;
721         var template = parent.removeChild(G.ui.rdetail.cp_status);
722
723         var i = 0;
724         for( i = 0; i < cp_statuses.length; i++ ) {
725
726                 var c = cp_statuses[i];
727                 if( c && isTrue(c.opac_visible()) ) {
728                         var name = c.name();
729                         _statusPositions[i] = c;
730                         var node = template.cloneNode(true);
731                         var data = findNodeByName( node, config.names.rdetail.cp_status);
732         
733                         data.appendChild(text(name));
734                         parent.appendChild(node);
735                 }
736         }       
737
738         numStatuses = 0;
739         for(x in _statusPositions) numStatuses++; 
740 }
741
742 function rdetailGrabCopyStatuses() {
743         if(cp_statuses) return cp_statuses;
744    var req = new Request(FETCH_COPY_STATUSES);
745    req.send(true);
746         cp_statuses = req.result();
747         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
748 }
749
750 function _rdetailSortStatuses(a, b) {
751         return parseInt(a.id()) - parseInt(b.id());
752 }
753