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