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