3 detachAllEvt('common', 'run');
4 attachEvt("common", "run", rdetailDraw);
5 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
6 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
7 attachEvt("rdetail", "recordDrawn", rdetailGetPageIds);
10 var cp_statuses = null;
11 var recordsCache = [];
13 var copyRowParent = null;
16 var numStatuses = null;
18 var callnumberCache = {};
19 var rdetailLocalOnly = true;
20 var globalCNCache = {};
24 var rdetailShowLocal = true;
28 var nextContainerIndex;
30 function rdetailReload() {
32 args[PARAM_LOCATION] = getNewSearchLocation();
33 args[PARAM_DEPTH] = depthSelGetDepth();
34 goTo(buildOPACLink(args));
40 var rdetailPrev = null;
41 var rdetailNext = null;
42 var rdetailStart = null;
43 var rdetailEnd = null;
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) {
52 cachedRecords.ids = ids;
54 for( var i = 0; i < cachedRecords.ids.length; i++ ) {
55 var rec = cachedRecords.ids[i];
56 if( rec == getRid() ) {
57 if( i > 0 ) prevRecord = cachedRecords.ids[i-1];
58 if( i < cachedRecords.ids.length - 1 )
59 nextRecord = cachedRecords.ids[i+1];
64 $('np_offset').appendChild(text(i + 1));
65 $('np_count').appendChild(text(getHitCount()));
68 unHideMe($('np_table'));
69 unHideMe($('np_prev'));
70 unHideMe($('np_start'));
71 rdetailPrev = function() { _rdetailNav(prevRecord); };
72 rdetailStart = function() { _rdetailNav(cachedRecords.ids[0]); };
76 unHideMe($('np_table'));
77 unHideMe($('np_next'));
78 unHideMe($('np_end'));
79 rdetailNext = function() { _rdetailNav(nextRecord); };
80 rdetailEnd = function() { _rdetailNav(cachedRecords.ids[cachedRecords.ids.length-1]); };
83 runEvt('rdetail', 'nextPrevDrawn', i, cachedRecords.ids.length);
87 function _rdetailNav(id) {
90 goTo(buildOPACLink(args));
93 function rdetailDraw() {
95 detachAllEvt('common','depthChanged');
96 detachAllEvt('common','locationUpdated');
97 attachEvt('common','depthChanged', rdetailReload);
98 attachEvt('common','locationUpdated', rdetailReload);
99 attachEvt('common','holdUpdated', rdetailReload);
100 attachEvt('common','holdUpdateCanceled', rdetailReload);
102 copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
103 copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
104 statusRow = G.ui.rdetail.cp_status.parentNode;
105 statusRow.id = '__rdsrow';
107 G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
108 G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
110 if(getLocation() == globalOrgTree.id())
111 hideMe(G.ui.rdetail.cp_info_all);
113 var req = new Request(FETCH_RMODS, getRid());
114 req.callback(_rdetailDraw);
117 detachAllEvt("result", "idsReceived");
118 G.evt.result.hitCountReceived = [];
119 G.evt.result.recordReceived = [];
120 G.evt.result.copyCountsReceived = [];
121 G.evt.result.allRecordsReceived = [];
124 function rdetailGetPageIds() {
125 attachEvt("result", "idsReceived", rdetailSetPaging );
129 function buildunAPISpan (span, type, id) {
133 addCSSClass(span,'unapi-id');
137 'tag:' + cgi.server_name + ',' +
139 ':' + type + '/' + id
143 var rdeatilMarcFetched = false;
144 function rdetailViewMarc(r,id) {
145 hideMe($('rdetail_extras_loading'));
146 $('rdetail_view_marc_box').innerHTML = r.getResultObject();
150 var span = div.appendChild( elem('abbr') );
152 buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
154 /* add the unapi span inside a hidden div */
155 $('rdetail_view_marc_box').insertBefore(span, $('rdetail_view_marc_box').firstChild);
159 function rdetailShowLocalCopies() {
162 rdetailShowLocal = true;
163 rdetailBuildInfoRows();
164 hideMe(G.ui.rdetail.cp_info_local);
165 unHideMe(G.ui.rdetail.cp_info_all);
166 hideMe(G.ui.rdetail.cp_info_none); /* XXX */
172 var rows = copyRowParent.getElementsByTagName("tr");
173 for( var r in rows ) {
175 if( row.parentNode != copyRowParent ) continue;
176 if(row.id == "__rdsrow") continue;
177 if(row.getAttribute && row.getAttribute("local")) {
185 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
186 hideMe(G.ui.rdetail.cp_info_local);
187 unHideMe(G.ui.rdetail.cp_info_all);
188 rdetailLocalOnly = true;
191 function rdetailShowAllCopies() {
194 rdetailShowLocal = false;
195 rdetailBuildInfoRows();
196 hideMe(G.ui.rdetail.cp_info_all);
197 unHideMe(G.ui.rdetail.cp_info_local);
198 hideMe(G.ui.rdetail.cp_info_none); /* XXX */
204 var rows = copyRowParent.getElementsByTagName("tr");
206 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
209 hideMe(G.ui.rdetail.cp_info_all);
210 unHideMe(G.ui.rdetail.cp_info_local);
211 hideMe(G.ui.rdetail.cp_info_none);
212 rdetailLocalOnly = false;
216 function _rdetailDraw(r) {
217 record = r.getResultObject();
219 runEvt('rdetail', 'recordRetrieved', record.doc_id());
221 G.ui.rdetail.title.appendChild(text(record.title()));
222 buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
223 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
224 G.ui.rdetail.edition.appendChild(text(record.edition()));
225 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
226 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
227 $('rdetail_physical_desc').appendChild(text(record.physical_description()));
228 G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
229 setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
230 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
233 /* see if the record has any external links */
234 var links = record.online_loc();
235 for( var i = 0; links && links.length > 0 && i < links.length; i++ ) {
237 if( href.match(/http/) ) {
238 unHideMe($('rdetail_online_row'));
239 var name = links[i+1];
240 if(!name || name.match(/http/)) name = href;
241 $('rdetail_online').appendChild(elem('a', {href:href,class:'classic_link'}, name));
242 $('rdetail_online').appendChild(elem('br'));
247 $('rdetail_place_hold').setAttribute(
248 'href','javascript:holdsDrawEditor({record:"'+record.doc_id()+'",type:"T"});');
250 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
251 runEvt("rdetail", "recordDrawn");
252 recordsCache.push(record);
254 rdetailSetExtrasSelector();
256 var breq = new Request(FETCH_BRE, [getRid()]);
257 breq.callback( rdetailCheckDeleted );
260 var req = new Request(FETCH_ACONT_SUMMARY, cleanISBN(record.isbn()));
261 req.callback(rdetailHandleAddedContent);
264 resultBuildCaches( [ record ] );
265 resultDrawSubjects();
269 function rdetailCheckDeleted(r) {
270 var br = r.getResultObject()[0];
271 if( br.deleted() == 1 ) {
272 hideMe($('rdetail_place_hold'));
273 $('rdetail_more_actions_selector').disabled = true;
274 unHideMe($('rdetail_deleted_exp'));
278 function rdetailSetExtrasSelector() {
279 if(!grabUser()) return;
280 unHideMe($('rdetail_more_actions'));
282 var req = new Request(
283 FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
284 req.callback(rdetailAddBookbags);
288 function rdetailAddBookbags(r) {
290 var containers = r.getResultObject();
291 var selector = $('rdetail_more_actions_selector');
294 doSelectorActions(selector);
296 for( var i = 0; i != containers.length; i++ ) {
298 var container = containers[i];
299 insertSelectorVal( selector, index++, container.name(),
300 "container_" + container.id(), rdetailAddToBookbag, 1 );
303 nextContainerIndex = index;
307 function rdetailNewBookbag() {
308 var name = prompt($('rdetail_bb_new').innerHTML,"");
312 if( id = containerCreate( name ) ) {
313 alert($('rdetail_bb_success').innerHTML);
314 var selector = $('rdetail_more_actions_selector');
315 insertSelectorVal( selector, nextContainerIndex++, name,
316 "container_" + id, rdetailAddToBookbag, 1 );
317 setSelector( selector, 'start' );
322 function rdetailAddToBookbag() {
323 var selector = $('rdetail_more_actions_selector');
324 var id = selector.options[selector.selectedIndex].value;
325 setSelector( selector, 'start' );
327 if( containerCreateItem( id.substring(10), record.doc_id() )) {
328 alert($('rdetail_bb_item_success').innerHTML);
334 var rdetailTocFetched = false;
335 var rdetailReviewFetched = false;
336 var rdetailMarcFetched = false;
338 function rdetailShowExtra(type, args) {
340 hideMe($('rdetail_copy_info_div'));
341 hideMe($('rdetail_reviews_div'));
342 hideMe($('rdetail_toc_div'));
343 hideMe($('rdetail_marc_div'));
344 hideMe($('cn_browse'));
345 hideMe($('rdetail_cn_browse_div'));
346 hideMe($('rdetail_notes_div'));
348 removeCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
349 removeCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
350 removeCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
351 removeCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
352 removeCSSClass($('rdetail_annotation_link'), 'rdetail_extras_selected');
353 removeCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
359 unHideMe($('rdetail_copy_info_div'));
360 addCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
364 addCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
365 unHideMe($('rdetail_reviews_div'));
366 if(rdetailReviewFetched) break;
367 unHideMe($('rdetail_extras_loading'));
368 rdetailReviewFetched = true;
369 req = new Request(FETCH_REVIEWS, cleanISBN(record.isbn()));
370 req.callback(rdetailShowReviews);
375 addCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
376 unHideMe($('rdetail_toc_div'));
377 if(rdetailTocFetched) break;
378 unHideMe($('rdetail_extras_loading'));
379 rdetailTocFetched = true;
381 hideMe($('rdetail_extras_loading'));
382 $('rdetail_toc_div').innerHTML = record.toc().replace(/--/g, "<br/>");
384 req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
385 req.callback(rdetailShowTOC);
391 addCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
392 unHideMe($('rdetail_marc_div'));
393 if(rdetailMarcFetched) return;
394 unHideMe($('rdetail_extras_loading'));
395 rdetailMarcFetched = true;
396 req = new Request( FETCH_MARC_HTML, record.doc_id() );
397 req.callback(rdetailViewMarc);
402 addCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
403 unHideMe($('rdetail_cn_browse_div'));
404 rdetailShowCNBrowse(defaultCN, getLocation(), null, true);
410 function rdetailVolumeDetails(args) {
411 var row = $(args.rowid);
412 var tbody = row.parentNode;
413 cpdBuild( tbody, row, record, args.cn, args.org, args.depth );
418 function rdetailBuildCNList() {
420 var select = $('cn_browse_selector');
423 for( var cn in callnumberCache ) arr.push( cn );
426 if( arr.length == 0 ) {
427 hideMe($('rdetail_cn_browse_select_div'));
431 for( var i in arr ) {
433 var opt = new Option(cn);
434 select.options[index++] = opt;
436 select.onchange = rdetailGatherCN;
439 function rdetailGatherCN() {
440 var cn = getSelectorVal($('cn_browse_selector'));
441 rdetailShowCNBrowse( cn, getLocation(), getDepth(), true );
442 setSelector( $('cn_browse_selector'), cn );
446 function rdetailShowCNBrowse( cn, loc, depth, fromOnclick ) {
448 rdetailBuildCNList();
449 setSelector( $('cn_browse_selector'), cn );
450 hideMe($('rdetail_copy_info_div'));
451 hideMe($('rdetail_reviews_div'));
452 hideMe($('rdetail_toc_div'));
453 hideMe($('rdetail_marc_div'));
454 unHideMe($('rdetail_cn_browse_div'));
455 unHideMe($('cn_browse'));
456 if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
457 cnBrowseGo(cn, loc, depth);
460 function rdetailHandleAddedContent(r) {
461 var resp = r.getResultObject();
462 if( resp.Review == 'true' ) unHideMe($('rdetail_reviews_link'));
463 if( resp.TOC == 'true' ) {
464 unHideMe($('rdetail_toc_link'));
468 unHideMe($('rdetail_toc_link'));
474 function rdetailShowReviews(r) {
475 hideMe($('rdetail_extras_loading'));
476 var res = r.getResultObject();
477 var par = $('rdetail_reviews_div');
478 var template = par.removeChild($('rdetail_review_template'));
479 if( res && res.length > 0 ) {
480 unHideMe($('rdetail_reviews_link'));
481 for( var i = 0; i != res.length; i++ ) {
483 if( rev.text && rev.info ) {
484 var node = template.cloneNode(true);
485 $n(node, 'review_header').appendChild(text(rev.info));
486 $n(node, 'review_text').appendChild(text(rev.text));
487 par.appendChild(node);
493 function rdetailShowTOC(r) {
494 hideMe($('rdetail_extras_loading'));
495 var resp = r.getResultObject();
497 unHideMe($('rdetail_toc_link'));
498 $('rdetail_toc_div').innerHTML = resp;
503 function rdetailBuildInfoRows() {
505 if( rdetailShowLocal )
506 req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id(), getLocation(), getDepth())
508 req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id());
509 req.callback(_rdetailBuildInfoRows);
513 /* pre-allocate the copy info table with all org units in correct order */
514 function _rdetailRows(node) {
516 if( rdetailShowLocal && getLocation() != globalOrgTree.id() ) {
518 var loc = findOrgUnit(getLocation());
521 for( var i = 0; i < globalOrgTree.children().length; i++ ) {
522 var org = findOrgUnit(globalOrgTree.children()[i]);
523 if( orgIsMine(org, loc) ) {
529 /* if the current node is not in our node trail */
530 var trail = orgNodeTrail(loc);
531 var intrail = grep( trail, function(i) { return (i.id() == node.id()); } );
539 var row = copyRow.cloneNode(true);
540 row.id = "cp_info_" + node.id();
542 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
543 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
544 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
545 var actions = $n(row, 'rdetail_actions_cell');
547 var p = libtd.getElementsByTagName('a')[0];
548 libtd.insertBefore(text(node.name()), p);
549 //libtd.appendChild(text(node.name()));
550 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
552 if(!findOrgType(node.ou_type()).can_have_vols()) {
554 row.removeChild(cntd);
555 row.removeChild(cpctd);
556 row.removeChild(actions);
557 row.setAttribute('novols', '1');
559 libtd.setAttribute("colspan", numStatuses + 3 );
560 libtd.colSpan = numStatuses + 3;
561 addCSSClass(row, 'copy_info_region_row');
564 copyRowParent.appendChild(row);
566 } else { node = globalOrgTree; }
568 for( var c in node.children() )
569 _rdetailRows(node.children()[c]);
572 function rdetailCNPrint(orgid, cn) {
574 var arr = cpdBuildPrintWindow( record, orgid);
578 var div = cpdBuildPrintWindow( record, orgid);
579 var template = div.removeChild($n(div, 'cnrow'));
580 var rowNode = $("cp_info_" + orgid);
581 cpdStylePopupWindow(div);
582 openWindow(div.innerHTML);
584 win.document.body.innerHTML = div.innerHTML;
588 /* walk through the copy info and build rows where necessary */
589 var localCNFound = false;
591 function _rdetailBuildInfoRows(r) {
594 removeChildren(copyRowParent);
598 var summary = r.getResultObject();
602 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
603 G.ui.rdetail.cp_info_loading);
607 for( var i = 0; i < summary.length; i++ ) {
609 var arr = summary[i];
610 globalCNCache[arr[1]] = 1;
611 var thisOrg = findOrgUnit(arr[0]);
612 var rowNode = $("cp_info_" + thisOrg.id());
613 if(!rowNode) continue;
615 /* set up the print link (not done) */
616 var pn = rowNode.previousSibling;
617 if( pn && pn.getAttribute('novols') ) {
618 var a = $n(pn, 'lib_print_link');
619 a.setAttribute('href',
620 'javascript:rdetailCNPrint('+thisOrg.id()+',"'+arr[1]+'");');
622 /* make this more smarter */
625 if(rowNode.getAttribute("used")) {
627 if( rowNode.nextSibling )
628 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
630 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
631 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
632 n.appendChild(text(thisOrg.name()));
633 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
634 rowNode.id = "cp_info_" + thisOrg.id() + '_' + (++ctr); /* ensure a unique id */
637 rowNode.setAttribute("used", "1");
640 var cpc_temp = rowNode.removeChild(
641 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
643 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
646 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) {
655 if(isLocal) unHideMe(rowNode);
657 rdetailSetPath( thisOrg, isLocal );
658 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal, thisOrg );
660 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
663 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
667 function rdetailBuildBrowseInfo(row, cn, local, orgNode) {
669 /* used for building the shelf browser */
671 var cache = callnumberCache[cn];
672 if( cache ) cache.count++;
673 else callnumberCache[cn] = { count : 1 };
676 var depth = getDepth();
677 if( !local ) depth = findOrgDepth(globalOrgTree);
679 $n(row, 'rdetail_callnumber_cell').appendChild(text(cn));
681 _debug('setting action clicks for cn ' + cn);
683 var dHref = 'javascript:rdetailVolumeDetails('+
684 '{rowid : "'+row.id+'", cn :"'+cn+'", depth:"'+depth+'", org:"'+orgNode.id()+'", local: '+local+'});';
686 var bHref = 'javascript:rdetailShowCNBrowse("' + cn + '", '+orgNode.id()+', "'+depth+'");';
688 $n(row, 'details').setAttribute('href', dHref);
689 $n(row, 'browse').setAttribute('href', bHref);
692 unHideMe($n(row, 'hold_div'));
693 $n(row, 'hold').onclick = function() {
694 var req = new Request(FETCH_VOLUME_BY_INFO, cn, record.doc_id(), orgNode.id());
697 var vol = r.getResultObject();
698 holdsDrawEditor({type: 'V', volumeObject : vol});
707 /* sets the path to org as 'active' and displays the
708 path if it's local */
709 function rdetailSetPath(org, local) {
710 if( findOrgDepth(org) == 0 ) return;
711 var row = $("cp_info_" + org.id());
712 row.setAttribute("hasinfo", "1");
716 row.setAttribute("local", "1");
722 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
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));
742 /* --------------------------------------------------------------------- */
743 var _statusPositions = {};
746 * Add one td (creating a new column) to the copy summary
747 * table for each holdable copy status
749 function rdetailBuildStatusColumns() {
751 rdetailGrabCopyStatuses();
752 var parent = statusRow;
753 var template = parent.removeChild(G.ui.rdetail.cp_status);
756 for( i = 0; i < cp_statuses.length; i++ ) {
758 var c = cp_statuses[i];
760 if(c && c.holdable()) {
763 _statusPositions[i] = c;
764 var node = template.cloneNode(true);
765 var data = findNodeByName( node, config.names.rdetail.cp_status);
767 data.appendChild(text(name));
768 parent.appendChild(node);
773 for(x in _statusPositions) numStatuses++;
776 function rdetailGrabCopyStatuses() {
777 if(cp_statuses) return cp_statuses;
778 var req = new Request(FETCH_COPY_STATUSES);
780 cp_statuses = req.result();
781 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
784 function _rdetailSortStatuses(a, b) {
785 return parseInt(a.id()) - parseInt(b.id());