4 detachAllEvt('common', 'run');
5 attachEvt("common", "run", rdetailDraw);
6 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
7 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
8 attachEvt("rdetail", "recordDrawn", rdetailGetPageIds);
11 var cp_statuses = null;
12 var recordsCache = [];
14 var copyRowParent = null;
17 var numStatuses = null;
19 var callnumberCache = {};
20 var rdetailLocalOnly = true;
21 var globalCNCache = {};
24 var _statusPositions = {};
26 var rdetailShowLocal = true;
27 var rdetailShowCopyLocation = true;
28 var googleBookPreview = true;
29 var displaySerialHoldings = true;
32 /* serials are currently the only use of Dojo strings in the OPAC */
33 if (displaySerialHoldings) {
34 dojo.requireLocalization("openils.opac", "opac");
35 opac_strings = dojo.i18n.getLocalization("openils.opac", "opac");
38 var nextContainerIndex;
40 function rdetailReload() {
42 args[PARAM_LOCATION] = getNewSearchLocation();
43 args[PARAM_DEPTH] = depthSelGetDepth();
44 goTo(buildOPACLink(args));
50 var rdetailPrev = null;
51 var rdetailNext = null;
52 var rdetailStart = null;
53 var rdetailEnd = null;
57 /* looks to see if we have a next and/or previous record in the
58 record cache, if so, set up the nav links */
59 function rdetailSetPaging(ids) {
62 cachedRecords.ids = ids;
64 for( var i = 0; i < cachedRecords.ids.length; i++ ) {
65 var rec = cachedRecords.ids[i];
66 if( rec == getRid() ) {
67 if( i > 0 ) prevRecord = cachedRecords.ids[i-1];
68 if( i < cachedRecords.ids.length - 1 )
69 nextRecord = cachedRecords.ids[i+1];
74 $('np_offset').appendChild(text(i + 1));
75 $('np_count').appendChild(text(getHitCount()));
78 unHideMe($('np_table'));
79 unHideMe($('np_prev'));
80 unHideMe($('np_start'));
81 rdetailPrev = function() { _rdetailNav(prevRecord); };
82 rdetailStart = function() { _rdetailNav(cachedRecords.ids[0]); };
86 unHideMe($('np_table'));
87 unHideMe($('np_next'));
88 unHideMe($('np_end'));
89 rdetailNext = function() { _rdetailNav(nextRecord); };
90 rdetailEnd = function() { _rdetailNav(cachedRecords.ids[cachedRecords.ids.length-1]); };
93 runEvt('rdetail', 'nextPrevDrawn', i, cachedRecords.ids.length);
97 function _rdetailNav(id, offset) {
100 goTo(buildOPACLink(args));
103 function rdetailDraw() {
105 detachAllEvt('common','depthChanged');
106 detachAllEvt('common','locationUpdated');
107 attachEvt('common','depthChanged', rdetailReload);
108 attachEvt('common','locationUpdated', rdetailReload);
109 attachEvt('common','holdUpdated', rdetailReload);
110 attachEvt('common','holdUpdateCanceled', rdetailReload);
112 copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
113 copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
114 statusRow = G.ui.rdetail.cp_status.parentNode;
115 statusRow.id = '__rdsrow';
117 G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
118 G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
120 if(getLocation() == globalOrgTree.id())
121 hideMe(G.ui.rdetail.cp_info_all);
123 var req = new Request(FETCH_RMODS, getRid());
124 req.callback(_rdetailDraw);
127 if (displaySerialHoldings) {
128 var req = new Request(FETCH_MFHD_SUMMARY, getRid());
129 req.callback(_holdingsDraw);
133 detachAllEvt("result", "idsReceived");
134 G.evt.result.hitCountReceived = [];
135 G.evt.result.recordReceived = [];
136 G.evt.result.copyCountsReceived = [];
137 G.evt.result.allRecordsReceived = [];
140 function rdetailGetPageIds() {
141 attachEvt("result", "idsReceived", rdetailSetPaging );
142 resultFetchAllRecords = true;
143 rresultCollectIds(true);
147 function buildunAPISpan (span, type, id) {
151 addCSSClass(span,'unapi-id');
154 'title', 'tag:' + cgi.server_name + ',' +
155 d.getFullYear() + ':' + type + '/' + id
159 function rdetailViewMarc(r,id) {
160 hideMe($('rdetail_extras_loading'));
161 $('rdetail_view_marc_box').innerHTML = r.getResultObject();
163 var div = elem('div', { "class" : 'hide_me' });
164 var span = div.appendChild( elem('abbr') );
166 buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
168 $('rdetail_view_marc_box').insertBefore(span, $('rdetail_view_marc_box').firstChild);
172 function rdetailShowLocalCopies() {
173 rdetailShowLocal = true;
174 rdetailBuildInfoRows();
175 hideMe(G.ui.rdetail.cp_info_local);
176 unHideMe(G.ui.rdetail.cp_info_all);
177 hideMe(G.ui.rdetail.cp_info_none);
180 function rdetailShowAllCopies() {
182 rdetailShowLocal = false;
183 rdetailBuildInfoRows();
184 hideMe(G.ui.rdetail.cp_info_all);
185 unHideMe(G.ui.rdetail.cp_info_local);
186 hideMe(G.ui.rdetail.cp_info_none);
189 function OpenMarcEditWindow(pcrud, rec) {
191 To run in Firefox directly, must set signed.applets.codebase_principal_support
192 to true in about:config
194 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
195 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
196 dojo.require('openils.PermaCrud');
199 record : {marc : rec.marc()},
201 label: opac_strings.SAVE_MFHD_LABEL,
202 func: function(xmlString) {
211 function loadMarcEditor(recId) {
212 var pcrud = new openils.PermaCrud({"authtoken": G.user.session});
213 var rec = pcrud.retrieve("sre", recId);
215 OpenMarcEditWindow(pcrud, rec);
220 * This function could be written much more intelligently
221 * Limited brain power means that I'm brute-forcing it for now
223 function _holdingsDraw(h) {
224 holdings = h.getResultObject();
225 if (!holdings) { return null; }
227 dojo.forEach(holdings, _holdingsDrawMFHD);
230 function _holdingsDrawMFHD(holdings, entryNum) {
231 if (!orgIsMine(findOrgUnit(holdings.owning_lib()), findOrgUnit(getLocation()))) {
234 var hh = holdings.holdings();
235 var hch = holdings.current_holdings();
236 var hs = holdings.supplements();
237 var hcs = holdings.current_supplements();
238 var hi = holdings.indexes();
239 var hci = holdings.current_indexes();
240 var ho = holdings.online();
241 var hm = holdings.missing();
242 var hinc = holdings.incomplete();
244 if ( hh.length == 0 && hch.length == 0 && hs.length == 0 &&
245 hcs.length == 0 && hi.length == 0 && hci.length == 0 &&
246 ho.length == 0 && hm.length == 0 && hinc.length == 0
251 dojo.place("<table><caption id='mfhdHoldingsCaption' class='rdetail_header color_1'>" +
252 opac_strings.HOLDINGS_TABLE_CAPTION + "</caption><tbody id='rdetail_holdings_tbody_" +
253 entryNum + "'></tbody></table>", "rdetail_details_table", "after"
255 if (hh.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.HOLDINGS, hh); }
256 if (hch.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.CURRENT_HOLDINGS, hch); }
257 if (hs.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.SUPPLEMENTS, hs); }
258 if (hcs.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.CURRENT_SUPPLEMENTS, hcs); }
259 if (hi.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.INDEXES, hi); }
260 if (hci.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.CURRENT_INDEXES, hci); }
261 if (ho.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.ONLINE_VOLUMES, ho); }
262 if (hm.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.MISSING_VOLUMES, hm); }
263 if (hinc.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.INCOMPLETE_VOLUMES, hm); }
266 dojo.require('openils.Event');
267 dojo.require('openils.PermaCrud');
268 dojo.place("<span> - </span><a class='classic_link' href='javascript:loadMarcEditor(" +
269 holdings.id() + ")'>" + opac_strings.EDIT_LABEL + "</a>",
270 "mfhdHoldingsCaption", "last"
275 function _holdingsDrawMFHDEntry(entryNum, entryName, entry) {
276 var flatEntry = entry.toString().replace(/,/g, ', ');
277 dojo.place("<tr><td> </td><td nowrap='nowrap' class='rdetail_desc'>" + entryName + "</td><td class='rdetail_item'>" + flatEntry + "</td></tr>", "rdetail_holdings_tbody_" + entryNum, "last");
280 function _rdetailDraw(r) {
281 record = r.getResultObject();
283 runEvt('rdetail', 'recordRetrieved', record.doc_id());
285 G.ui.rdetail.title.appendChild(text(record.title()));
286 buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
287 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
288 G.ui.rdetail.edition.appendChild(text(record.edition()));
289 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
290 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
291 $('rdetail_physical_desc').appendChild(text(record.physical_description()));
292 r = record.types_of_resource();
294 G.ui.rdetail.tor.appendChild(text(r[0]));
295 setResourcePic( G.ui.rdetail.tor_pic, r[0]);
297 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
301 if(ENABLE_ADDED_CONTENT_ATTRIB_LINKS) {
302 unHideMe($('rdetail.jacket_attrib_div'));
303 var href = $('rdetail.jacket_attrib_link').getAttribute('href') +cleanISBN(record.isbn());
304 $('rdetail.jacket_attrib_link').setAttribute('href', href);
306 rdetailCheckForGBPreview();
309 hideMe($("rdetail.jacket_attrib_div"));
310 hideMe($("rdetail_img_link"));
315 // see if the record has any external links
316 var links = record.online_loc();
317 for( var i = 0; links && links.length > 0 && i < links.length; i = i + 3 ) {
319 // avoid matching "HTTP: The Complete Reference"
320 if( href.match(/https?:\/|ftps?:\/|mailto:/i) ) {
321 unHideMe($('rdetail_online_row'));
322 // MODS can contain a display label (used for the text of the link)
323 // as well as a note about the URL; many legacy systems conflate the
324 // two and generate MARC records that expect the note to be used as
325 // the text of the link, with no display label; here's the canonical
328 // 856 40 $uhttp://localhost$yDisplay label$zPublic note
330 // Note that the MARC21slim2MODS XSL concatenates $3 and $y together
331 // (as $y was defined later in MARC21's life as the display label)
332 var displayLabel = '' + links[i+1];
333 var note = '' + links[i+2];
334 if(!displayLabel || displayLabel.match(/https?:\/|ftps?:\/|mailto:/i)) {
335 if(!note || note.match(/https?:\/|ftps?:\/|mailto:/i)) {
341 $('rdetail_online').appendChild(elem('a', {href:href,'class':'classic_link'}, displayLabel));
342 if (!note && note != displayLabel) {
343 $('rdetail_online').appendChild(elem('span', {'class':'url_note'}, ' - ' + note));
345 $('rdetail_online').appendChild(elem('br'));
349 // Fill in our unAPI ID, if anyone cares
350 var abbrs = document.getElementsByTagName('abbr');
352 for (var i = 0; i < abbrs.length; i = i + 1) {
353 if (abbrs[i].getAttribute('name') == 'unapi') {
358 buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
360 $('rdetail_place_hold').setAttribute(
361 'href','javascript:holdsDrawEditor({record:"'+record.doc_id()+'",type:"T"});');
363 $('rdetail_img_link').setAttribute('href', buildISBNSrc(cleanISBN(record.isbn()), 'large'));
364 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
365 runEvt("rdetail", "recordDrawn");
366 recordsCache.push(record);
368 rdetailSetExtrasSelector();
370 var breq = new Request(FETCH_BRE, [getRid()]);
371 breq.callback( rdetailCheckDeleted );
374 resultBuildCaches( [ record ] );
375 resultDrawSubjects();
378 // grab added content
379 acCollectData(cleanISBN(record.isbn()), rdetailhandleAC);
384 function rdetailCheckDeleted(r) {
385 var br = r.getResultObject()[0];
386 if( isTrue(br.deleted()) ) {
387 hideMe($('rdetail_place_hold'));
388 $('rdetail_more_actions_selector').disabled = true;
389 unHideMe($('rdetail_deleted_exp'));
393 function rdetailSetExtrasSelector() {
394 if(!grabUser()) return;
395 unHideMe($('rdetail_more_actions'));
397 var req = new Request(
398 FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
399 req.callback(rdetailAddBookbags);
403 function rdetailAddBookbags(r) {
405 var containers = r.getResultObject();
406 var selector = $('rdetail_more_actions_selector');
409 doSelectorActions(selector);
411 for( var i = 0; i != containers.length; i++ ) {
413 var container = containers[i];
414 insertSelectorVal( selector, index++, container.name(),
415 "container_" + container.id(), rdetailAddToBookbag, 1 );
418 nextContainerIndex = index;
422 function rdetailNewBookbag() {
423 var name = prompt($('rdetail_bb_new').innerHTML,"");
427 if( id = containerCreate( name ) ) {
428 alert($('rdetail_bb_success').innerHTML);
429 var selector = $('rdetail_more_actions_selector');
430 insertSelectorVal( selector, nextContainerIndex++, name,
431 "container_" + id, rdetailAddToBookbag, 1 );
432 setSelector( selector, 'start' );
437 function rdetailAddToBookbag() {
438 var selector = $('rdetail_more_actions_selector');
439 var id = selector.options[selector.selectedIndex].value;
440 setSelector( selector, 'start' );
442 if( containerCreateItem( id.substring(10), record.doc_id() )) {
443 alert($('rdetail_bb_item_success').innerHTML);
448 var rdetailMarcFetched = false;
449 function rdetailShowExtra(type, args) {
451 hideMe($('rdetail_copy_info_div'));
452 hideMe($('rdetail_reviews_div'));
453 hideMe($('rdetail_toc_div'));
454 hideMe($('rdetail_anotes_div'));
455 hideMe($('rdetail_excerpt_div'));
456 hideMe($('rdetail_preview_div'));
457 hideMe($('rdetail_marc_div'));
458 hideMe($('cn_browse'));
459 hideMe($('rdetail_cn_browse_div'));
460 hideMe($('rdetail_notes_div'));
462 removeCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
463 removeCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
464 removeCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
465 removeCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
466 removeCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
467 removeCSSClass($('rdetail_preview_link'), 'rdetail_extras_selected');
468 removeCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
469 removeCSSClass($('rdetail_annotation_link'), 'rdetail_extras_selected');
470 removeCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
475 unHideMe($('rdetail_copy_info_div'));
476 addCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
480 addCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
481 unHideMe($('rdetail_reviews_div'));
485 addCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
486 unHideMe($('rdetail_excerpt_div'));
490 addCSSClass($('rdetail_preview_link'), 'rdetail_extras_selected');
491 unHideMe($('rdetail_preview_div'));
492 rdetailDisplayGBPreview();
496 addCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
497 unHideMe($('rdetail_anotes_div'));
501 addCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
502 unHideMe($('rdetail_toc_div'));
506 addCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
507 unHideMe($('rdetail_marc_div'));
508 if(rdetailMarcFetched) return;
509 unHideMe($('rdetail_extras_loading'));
510 rdetailMarcFetched = true;
511 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
512 req.callback(rdetailViewMarc);
517 addCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
518 unHideMe($('rdetail_cn_browse_div'));
519 rdetailShowCNBrowse(defaultCN, getLocation(), null, true);
525 function rdetailVolumeDetails(args) {
526 var row = $(args.rowid);
527 var tbody = row.parentNode;
528 cpdBuild( tbody, row, record, args.cn, args.org, args.depth, args.copy_location );
532 function rdetailBuildCNList() {
534 var select = $('cn_browse_selector');
537 for( var cn in callnumberCache ) arr.push( cn );
540 if( arr.length == 0 ) {
541 hideMe($('rdetail_cn_browse_select_div'));
545 for( var i in arr ) {
547 var opt = new Option(cn);
548 select.options[index++] = opt;
550 select.onchange = rdetailGatherCN;
553 function rdetailGatherCN() {
554 var cn = getSelectorVal($('cn_browse_selector'));
555 rdetailShowCNBrowse( cn, getLocation(), getDepth(), true );
556 setSelector( $('cn_browse_selector'), cn );
560 function rdetailShowCNBrowse( cn, loc, depth, fromOnclick ) {
563 unHideMe($('cn_browse_none'));
564 hideMe($('rdetail_cn_browse_select_div'));
568 unHideMe($('rdetail_cn_browse_select_div'));
569 rdetailBuildCNList();
570 setSelector( $('cn_browse_selector'), cn );
571 hideMe($('rdetail_copy_info_div'));
572 hideMe($('rdetail_reviews_div'));
573 hideMe($('rdetail_toc_div'));
574 hideMe($('rdetail_marc_div'));
575 unHideMe($('rdetail_cn_browse_div'));
576 unHideMe($('cn_browse'));
577 if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
578 cnBrowseGo(cn, loc, depth);
581 function rdetailhandleAC(data) {
583 if( data.reviews.html ) {
584 $('rdetail_review_container').innerHTML = data.reviews.html;
585 unHideMe($('rdetail_reviews_link'));
588 if( data.toc.html ) {
589 $('rdetail_toc_div').innerHTML = data.toc.html;
590 unHideMe($('rdetail_toc_link'));
593 if( data.excerpt.html ) {
594 $('rdetail_excerpt_div').innerHTML = data.excerpt.html;
595 unHideMe($('rdetail_excerpt_link'));
598 if( data.anotes.html ) {
599 $('rdetail_anotes_div').innerHTML = data.anotes.html;
600 unHideMe($('rdetail_anotes_link'));
604 function rdetailShowReviews(r) {
605 hideMe($('rdetail_extras_loading'));
606 var res = r.getResultObject();
607 var par = $('rdetail_reviews_div');
608 var template = par.removeChild($('rdetail_review_template'));
609 if( res && res.length > 0 ) {
610 unHideMe($('rdetail_reviews_link'));
611 for( var i = 0; i != res.length; i++ ) {
613 if( rev.text && rev.info ) {
614 var node = template.cloneNode(true);
615 $n(node, 'review_header').appendChild(text(rev.info));
616 $n(node, 'review_text').appendChild(text(rev.text));
617 par.appendChild(node);
624 function rdetailShowTOC(r) {
625 hideMe($('rdetail_extras_loading'));
626 var resp = r.getResultObject();
628 unHideMe($('rdetail_toc_link'));
629 $('rdetail_toc_div').innerHTML = resp;
633 function rdetailBuildInfoRows() {
635 var method = FETCH_COPY_COUNTS_SUMMARY;
636 if (rdetailShowCopyLocation)
637 method = FETCH_COPY_LOCATION_COUNTS_SUMMARY;
639 if( rdetailShowLocal )
640 req = new Request(method, record.doc_id(), getLocation(), getDepth())
642 req = new Request(method, record.doc_id());
643 req.callback(_rdetailBuildInfoRows);
647 function _rdetailRows(node) {
649 if( rdetailShowLocal && getLocation() != globalOrgTree.id() ) {
650 var loc = findOrgUnit(getLocation());
652 if( !orgIsMine(node, loc) && !orgIsMine(loc,node) ) return;
654 for( var i = 0; i < globalOrgTree.children().length; i++ ) {
655 var org = findOrgUnit(globalOrgTree.children()[i]);
656 if( orgIsMine(org, loc) ) {
664 if(!node && findOrgType(globalOrgTree.ou_type()).can_have_vols())
665 node = globalOrgTree;
668 /* don't show hidden orgs */
672 if(!isXUL() && !isTrue(node.opac_visible())) return;
674 var row = copyRow.cloneNode(true);
675 row.id = "cp_info_" + node.id();
677 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
678 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
679 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
680 var actions = $n(row, 'rdetail_actions_cell');
682 var p = libtd.getElementsByTagName('a')[0];
683 libtd.insertBefore(text(node.name()), p);
684 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
686 if(!findOrgType(node.ou_type()).can_have_vols()) {
688 row.removeChild(cntd);
689 row.removeChild(cpctd);
690 row.removeChild(actions);
691 row.setAttribute('novols', '1');
693 libtd.setAttribute("colspan", numStatuses + 3 );
694 libtd.colSpan = numStatuses + 3;
695 addCSSClass(row, 'copy_info_region_row');
698 copyRowParent.appendChild(row);
700 } else { node = globalOrgTree; }
702 for( var c in node.children() )
703 _rdetailRows(node.children()[c]);
706 function rdetailCNPrint(orgid, cn) {
707 var div = cpdBuildPrintWindow( record, orgid);
708 var template = div.removeChild($n(div, 'cnrow'));
709 var rowNode = $("cp_info_" + orgid);
710 cpdStylePopupWindow(div);
711 openWindow(div.innerHTML);
714 var localCNFound = false;
716 function _rdetailBuildInfoRows(r) {
718 if (rdetailShowCopyLocation)
719 unHideMe( $n( $('rdetail_copy_info_table'), 'rdetail_copylocation_header' ) );
721 removeChildren(copyRowParent);
725 var summary = r.getResultObject();
729 for( var i = 0; i < summary.length; i++ ) {
731 var arr = summary[i];
732 globalCNCache[arr[1]] = 1;
733 var thisOrg = findOrgUnit(arr[0]);
734 var rowNode = $("cp_info_" + thisOrg.id());
735 if(!rowNode) continue;
737 if(rowNode.getAttribute("used")) {
739 if( rowNode.nextSibling ) {
740 sib = rowNode.nextSibling;
741 o ='cp_info_'+thisOrg.id()+'_';
742 /* push the new row on as the last row for this org unit */
743 while( sib && sib.id.match(o) ) {
744 sib = sib.nextSibling;
747 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), sib);
749 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
751 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
754 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
755 n.appendChild(text(thisOrg.name()));
756 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
757 rowNode.id = "cp_info_" + thisOrg.id() + '_' + (++ctr);
760 rowNode.setAttribute("used", "1");
763 var cpc_temp = rowNode.removeChild(
764 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
766 var statuses = arr[2];
768 if (rdetailShowCopyLocation) {
774 rdetailApplyStatuses(rowNode, cpc_temp, statuses);
777 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) {
786 //if(isLocal) unHideMe(rowNode);
789 rdetailSetPath( thisOrg, isLocal );
790 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal, thisOrg, cl );
792 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
795 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
798 function rdetailBuildBrowseInfo(row, cn, local, orgNode, cl) {
801 var cache = callnumberCache[cn];
802 if( cache ) cache.count++;
803 else callnumberCache[cn] = { count : 1 };
806 var depth = getDepth();
807 if( !local ) depth = findOrgDepth(globalOrgTree);
809 $n(row, 'rdetail_callnumber_cell').appendChild(text(cn));
811 if (rdetailShowCopyLocation) {
812 var cl_cell = $n(row, 'rdetail_copylocation_cell');
813 cl_cell.appendChild(text(cl));
817 _debug('setting action clicks for cn ' + cn);
819 var dHref = 'javascript:rdetailVolumeDetails('+
820 '{copy_location : "'+cl+'", rowid : "'+row.id+'", cn :"'+cn+'", depth:"'+depth+'", org:"'+orgNode.id()+'", local: '+local+'});';
822 var bHref = 'javascript:rdetailShowCNBrowse("' + cn + '", '+orgNode.id()+', "'+depth+'");';
824 unHideMe( $n(row, 'details') )
825 $n(row, 'details').setAttribute('href', dHref);
826 unHideMe( $n(row, 'browse') )
827 $n(row, 'browse').setAttribute('href', bHref);
830 unHideMe($n(row, 'hold_div'));
831 $n(row, 'hold').onclick = function() {
832 var req = new Request(FETCH_VOLUME_BY_INFO, cn, record.doc_id(), orgNode.id());
835 var vol = r.getResultObject();
836 holdsDrawEditor({type: 'V', volumeObject : vol});
844 // sets the path to org as 'active' and displays the path if it's local
845 function rdetailSetPath(org, local) {
846 if( findOrgDepth(org) == 0 ) return;
847 var row = $("cp_info_" + org.id());
848 row.setAttribute("hasinfo", "1");
850 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
853 //Append all the statuses for a given summary to the
855 function rdetailApplyStatuses( row, template, statuses ) {
856 for( var j in _statusPositions ) {
857 var stat = _statusPositions[j];
858 var val = statuses[stat.id()];
859 var nn = template.cloneNode(true);
860 if(val) nn.appendChild(text(val));
861 else nn.appendChild(text(0));
866 //Add one td (creating a new column) to the copy summary
867 //table for each opac_visible copy status
868 function rdetailBuildStatusColumns() {
870 rdetailGrabCopyStatuses();
871 var parent = statusRow;
872 var template = parent.removeChild(G.ui.rdetail.cp_status);
875 for( i = 0; i < cp_statuses.length; i++ ) {
877 var c = cp_statuses[i];
878 if( c && isTrue(c.opac_visible()) ) {
880 _statusPositions[i] = c;
881 var node = template.cloneNode(true);
882 var data = findNodeByName( node, config.names.rdetail.cp_status);
884 data.appendChild(text(name));
885 parent.appendChild(node);
890 for(x in _statusPositions) numStatuses++;
893 function rdetailGrabCopyStatuses() {
894 if(cp_statuses) return cp_statuses;
895 var req = new Request(FETCH_COPY_STATUSES);
897 cp_statuses = req.result();
898 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
901 function _rdetailSortStatuses(a, b) {
902 return parseInt(a.id()) - parseInt(b.id());
906 * Check for a Google Book preview
908 function rdetailCheckForGBPreview() {
909 if (!googleBookPreview) return;
910 searchForGBPreview( cleanISBN(record.isbn()) );
915 * @param {DOM object} query The form element containing the
916 * input parameters "isbns"
918 function searchForGBPreview( isbn ) {
920 // Delete any previous Google Booksearch JSON queries.
921 var GBPJsonScript = document.getElementById("GBPJsonScript");
923 GBPJsonScript.parentNode.removeChild(GBPJsonScript);
926 // Add a script element with the src as the user's Google Booksearch query.
927 // JSON output is specified by including the alt=json-in-script argument
928 // and the callback function is also specified as a URI argument.
929 var GBPScriptElement = document.createElement("script");
931 GBPScriptElement.setAttribute("id", "GBPJsonScript");
932 GBPScriptElement.setAttribute("src",
933 "http://books.google.com/books?bibkeys=" +
934 isbn + "&jscmd=viewapi&callback=GBPreviewCallback");
935 GBPScriptElement.setAttribute("type", "text/javascript");
937 // make the request to Google booksearch
938 document.documentElement.firstChild.appendChild(GBPScriptElement);
942 * This function is the call-back function for the JSON scripts which
943 * executes a Google book search response.
945 * XXX I18N of text needed
947 * @param {JSON} booksInfo is the JSON object pulled from the Google books service.
949 function GBPreviewCallback(GBPBookInfo) {
950 var GBPreviewDiv = document.getElementById("rdetail_preview_div");
953 for ( i in GBPBookInfo ) {
954 GBPBook = GBPBookInfo[i];
961 if ( GBPBook.preview != "noview" ) {
962 if ( GBPBook.preview == 'full' ) {
963 setText( $('rdetail_preview_link'), $('rdetail_preview_full_text').innerHTML );
964 $('rdetail_preview_link_a').title = $('rdetail_preview_title').innerHTML;
967 // Add a button below the book cover image to load the preview.
968 GBPBadge = document.createElement( 'img' );
969 GBPBadge.src = 'http://books.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif';
970 GBPBadge.title = $('rdetail_preview_badge').innerHTML;
971 GBPBadge.style.border = 0;
972 GBPBadgelink = document.createElement( 'a' );
973 GBPBadgelink.href = 'javascript:rdetailShowExtra("preview");';
974 GBPBadgelink.appendChild( GBPBadge );
975 $('rdetail_image_cell').appendChild( GBPBadgelink );
976 $('rdetail_preview_div').style.height = 600;
978 /* Display the "Preview" tab in the Extras section */
979 unHideMe( $('rdetail_preview_link' ) );
984 * This is called when the user clicks on the 'Preview' link. We assume
985 * a preview is available from Google if this link was made visible.
987 * XXX I18N of Google Book Preview language attribute needed
989 function rdetailDisplayGBPreview() {
990 unHideMe($('rdetail_extras_loading'));
991 GBPreviewPane = $('rdetail_preview_div');
992 if ( GBPreviewPane.getAttribute('loaded') == null ||
993 GBPreviewPane.getAttribute('loaded') == "false" ) {
994 google.load("books", "0", {"callback" : rdetailGBPViewerLoadCallback, "language": "en"} );
995 GBPreviewPane.setAttribute('loaded', 'true');
999 function rdetailGBPViewerLoadCallback() {
1000 hideMe($('rdetail_extras_loading'));
1001 var GBPViewer = new google.books.DefaultViewer(document.getElementById('rdetail_preview_div'));
1002 GBPViewer.load('ISBN:' + cleanISBN(record.isbn()) );