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