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