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