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