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;
31 var nextContainerIndex;
33 function rdetailReload() {
35 args[PARAM_LOCATION] = getNewSearchLocation();
36 args[PARAM_DEPTH] = depthSelGetDepth();
37 goTo(buildOPACLink(args));
43 var rdetailPrev = null;
44 var rdetailNext = null;
45 var rdetailStart = null;
46 var rdetailEnd = null;
50 /* looks to see if we have a next and/or previous record in the
51 record cache, if so, set up the nav links */
52 function rdetailSetPaging(ids) {
55 cachedRecords.ids = ids;
57 for( var i = 0; i < cachedRecords.ids.length; i++ ) {
58 var rec = cachedRecords.ids[i];
59 if( rec == getRid() ) {
60 if( i > 0 ) prevRecord = cachedRecords.ids[i-1];
61 if( i < cachedRecords.ids.length - 1 )
62 nextRecord = cachedRecords.ids[i+1];
67 $('np_offset').appendChild(text(i + 1));
68 $('np_count').appendChild(text(getHitCount()));
71 unHideMe($('np_table'));
72 unHideMe($('np_prev'));
73 unHideMe($('np_start'));
74 rdetailPrev = function() { _rdetailNav(prevRecord); };
75 rdetailStart = function() { _rdetailNav(cachedRecords.ids[0]); };
79 unHideMe($('np_table'));
80 unHideMe($('np_next'));
81 unHideMe($('np_end'));
82 rdetailNext = function() { _rdetailNav(nextRecord); };
83 rdetailEnd = function() { _rdetailNav(cachedRecords.ids[cachedRecords.ids.length-1]); };
86 runEvt('rdetail', 'nextPrevDrawn', i, cachedRecords.ids.length);
90 function _rdetailNav(id, offset) {
93 goTo(buildOPACLink(args));
96 function rdetailDraw() {
98 detachAllEvt('common','depthChanged');
99 detachAllEvt('common','locationUpdated');
100 attachEvt('common','depthChanged', rdetailReload);
101 attachEvt('common','locationUpdated', rdetailReload);
102 attachEvt('common','holdUpdated', rdetailReload);
103 attachEvt('common','holdUpdateCanceled', rdetailReload);
105 copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
106 copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
107 statusRow = G.ui.rdetail.cp_status.parentNode;
108 statusRow.id = '__rdsrow';
110 G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
111 G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
113 if(getLocation() == globalOrgTree.id())
114 hideMe(G.ui.rdetail.cp_info_all);
116 var req = new Request(FETCH_RMODS, getRid());
117 req.callback(_rdetailDraw);
120 detachAllEvt("result", "idsReceived");
121 G.evt.result.hitCountReceived = [];
122 G.evt.result.recordReceived = [];
123 G.evt.result.copyCountsReceived = [];
124 G.evt.result.allRecordsReceived = [];
127 function rdetailGetPageIds() {
128 attachEvt("result", "idsReceived", rdetailSetPaging );
129 resultFetchAllRecords = true;
130 rresultCollectIds(true);
134 function buildunAPISpan (span, type, id) {
138 addCSSClass(span,'unapi-id');
141 'title', 'tag:' + cgi.server_name + ',' +
142 d.getFullYear() + ':' + type + '/' + id
146 function rdetailViewMarc(r,id) {
147 hideMe($('rdetail_extras_loading'));
148 $('rdetail_view_marc_box').innerHTML = r.getResultObject();
150 var div = elem('div', { "class" : 'hide_me' });
151 var span = div.appendChild( elem('abbr') );
153 buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
155 $('rdetail_view_marc_box').insertBefore(span, $('rdetail_view_marc_box').firstChild);
159 function rdetailShowLocalCopies() {
160 rdetailShowLocal = true;
161 rdetailBuildInfoRows();
162 hideMe(G.ui.rdetail.cp_info_local);
163 unHideMe(G.ui.rdetail.cp_info_all);
164 hideMe(G.ui.rdetail.cp_info_none);
167 function rdetailShowAllCopies() {
169 rdetailShowLocal = false;
170 rdetailBuildInfoRows();
171 hideMe(G.ui.rdetail.cp_info_all);
172 unHideMe(G.ui.rdetail.cp_info_local);
173 hideMe(G.ui.rdetail.cp_info_none);
177 function _rdetailDraw(r) {
178 record = r.getResultObject();
180 runEvt('rdetail', 'recordRetrieved', record.doc_id());
182 G.ui.rdetail.title.appendChild(text(record.title()));
183 buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
184 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
185 G.ui.rdetail.edition.appendChild(text(record.edition()));
186 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
187 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
188 $('rdetail_physical_desc').appendChild(text(record.physical_description()));
189 r = record.types_of_resource();
191 G.ui.rdetail.tor.appendChild(text(r[0]));
192 setResourcePic( G.ui.rdetail.tor_pic, r[0]);
194 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
198 if(ENABLE_ADDED_CONTENT_ATTRIB_LINKS) {
199 unHideMe($('rdetail.jacket_attrib_div'));
200 var href = $('rdetail.jacket_attrib_link').getAttribute('href') +cleanISBN(record.isbn());
201 $('rdetail.jacket_attrib_link').setAttribute('href', href);
203 rdetailCheckForGBPreview();
206 hideMe($("rdetail.jacket_attrib_div"));
207 hideMe($("rdetail_img_link"));
212 // see if the record has any external links
213 var links = record.online_loc();
214 for( var i = 0; links && links.length > 0 && i < links.length; i = i + 3 ) {
216 // avoid matching "HTTP: The Complete Reference"
217 if( href.match(/https?:\/|ftps?:\/|mailto:/i) ) {
218 unHideMe($('rdetail_online_row'));
219 // MODS can contain a display label (used for the text of the link)
220 // as well as a note about the URL; many legacy systems conflate the
221 // two and generate MARC records that expect the note to be used as
222 // the text of the link, with no display label; here's the canonical
225 // 856 40 $uhttp://localhost$yDisplay label$zPublic note
227 // Note that the MARC21slim2MODS XSL concatenates $3 and $y together
228 // (as $y was defined later in MARC21's life as the display label)
229 var displayLabel = '' + links[i+1];
230 var note = '' + links[i+2];
231 if(!displayLabel || displayLabel.match(/https?:\/|ftps?:\/|mailto:/i)) {
232 if(!note || note.match(/https?:\/|ftps?:\/|mailto:/i)) {
238 $('rdetail_online').appendChild(elem('a', {href:href,'class':'classic_link'}, displayLabel));
239 if (!note && note != displayLabel) {
240 $('rdetail_online').appendChild(elem('span', {'class':'url_note'}, ' - ' + note));
242 $('rdetail_online').appendChild(elem('br'));
246 // Fill in our unAPI ID, if anyone cares
247 var abbrs = document.getElementsByTagName('abbr');
249 for (var i = 0; i < abbrs.length; i = i + 1) {
250 if (abbrs[i].getAttribute('name') == 'unapi') {
255 buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
257 $('rdetail_place_hold').setAttribute(
258 'href','javascript:holdsDrawEditor({record:"'+record.doc_id()+'",type:"T"});');
260 $('rdetail_img_link').setAttribute('href', buildISBNSrc(cleanISBN(record.isbn()), 'large'));
261 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
262 runEvt("rdetail", "recordDrawn");
263 recordsCache.push(record);
265 rdetailSetExtrasSelector();
267 var breq = new Request(FETCH_BRE, [getRid()]);
268 breq.callback( rdetailCheckDeleted );
271 resultBuildCaches( [ record ] );
272 resultDrawSubjects();
275 // grab added content
276 acCollectData(cleanISBN(record.isbn()), rdetailhandleAC);
281 function rdetailCheckDeleted(r) {
282 var br = r.getResultObject()[0];
283 if( isTrue(br.deleted()) ) {
284 hideMe($('rdetail_place_hold'));
285 $('rdetail_more_actions_selector').disabled = true;
286 unHideMe($('rdetail_deleted_exp'));
290 function rdetailSetExtrasSelector() {
291 if(!grabUser()) return;
292 unHideMe($('rdetail_more_actions'));
294 var req = new Request(
295 FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
296 req.callback(rdetailAddBookbags);
300 function rdetailAddBookbags(r) {
302 var containers = r.getResultObject();
303 var selector = $('rdetail_more_actions_selector');
306 doSelectorActions(selector);
308 for( var i = 0; i != containers.length; i++ ) {
310 var container = containers[i];
311 insertSelectorVal( selector, index++, container.name(),
312 "container_" + container.id(), rdetailAddToBookbag, 1 );
315 nextContainerIndex = index;
319 function rdetailNewBookbag() {
320 var name = prompt($('rdetail_bb_new').innerHTML,"");
324 if( id = containerCreate( name ) ) {
325 alert($('rdetail_bb_success').innerHTML);
326 var selector = $('rdetail_more_actions_selector');
327 insertSelectorVal( selector, nextContainerIndex++, name,
328 "container_" + id, rdetailAddToBookbag, 1 );
329 setSelector( selector, 'start' );
334 function rdetailAddToBookbag() {
335 var selector = $('rdetail_more_actions_selector');
336 var id = selector.options[selector.selectedIndex].value;
337 setSelector( selector, 'start' );
339 if( containerCreateItem( id.substring(10), record.doc_id() )) {
340 alert($('rdetail_bb_item_success').innerHTML);
345 var rdetailMarcFetched = false;
346 function rdetailShowExtra(type, args) {
348 hideMe($('rdetail_copy_info_div'));
349 hideMe($('rdetail_reviews_div'));
350 hideMe($('rdetail_toc_div'));
351 hideMe($('rdetail_anotes_div'));
352 hideMe($('rdetail_excerpt_div'));
353 hideMe($('rdetail_preview_div'));
354 hideMe($('rdetail_marc_div'));
355 hideMe($('cn_browse'));
356 hideMe($('rdetail_cn_browse_div'));
357 hideMe($('rdetail_notes_div'));
359 removeCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
360 removeCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
361 removeCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
362 removeCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
363 removeCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
364 removeCSSClass($('rdetail_preview_link'), 'rdetail_extras_selected');
365 removeCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
366 removeCSSClass($('rdetail_annotation_link'), 'rdetail_extras_selected');
367 removeCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
372 unHideMe($('rdetail_copy_info_div'));
373 addCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
377 addCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
378 unHideMe($('rdetail_reviews_div'));
382 addCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
383 unHideMe($('rdetail_excerpt_div'));
387 addCSSClass($('rdetail_preview_link'), 'rdetail_extras_selected');
388 unHideMe($('rdetail_preview_div'));
389 rdetailDisplayGBPreview();
393 addCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
394 unHideMe($('rdetail_anotes_div'));
398 addCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
399 unHideMe($('rdetail_toc_div'));
403 addCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
404 unHideMe($('rdetail_marc_div'));
405 if(rdetailMarcFetched) return;
406 unHideMe($('rdetail_extras_loading'));
407 rdetailMarcFetched = true;
408 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
409 req.callback(rdetailViewMarc);
414 addCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
415 unHideMe($('rdetail_cn_browse_div'));
416 rdetailShowCNBrowse(defaultCN, getLocation(), null, true);
422 function rdetailVolumeDetails(args) {
423 var row = $(args.rowid);
424 var tbody = row.parentNode;
425 cpdBuild( tbody, row, record, args.cn, args.org, args.depth, args.copy_location );
429 function rdetailBuildCNList() {
431 var select = $('cn_browse_selector');
434 for( var cn in callnumberCache ) arr.push( cn );
437 if( arr.length == 0 ) {
438 hideMe($('rdetail_cn_browse_select_div'));
442 for( var i in arr ) {
444 var opt = new Option(cn);
445 select.options[index++] = opt;
447 select.onchange = rdetailGatherCN;
450 function rdetailGatherCN() {
451 var cn = getSelectorVal($('cn_browse_selector'));
452 rdetailShowCNBrowse( cn, getLocation(), getDepth(), true );
453 setSelector( $('cn_browse_selector'), cn );
457 function rdetailShowCNBrowse( cn, loc, depth, fromOnclick ) {
460 unHideMe($('cn_browse_none'));
461 hideMe($('rdetail_cn_browse_select_div'));
465 unHideMe($('rdetail_cn_browse_select_div'));
466 rdetailBuildCNList();
467 setSelector( $('cn_browse_selector'), cn );
468 hideMe($('rdetail_copy_info_div'));
469 hideMe($('rdetail_reviews_div'));
470 hideMe($('rdetail_toc_div'));
471 hideMe($('rdetail_marc_div'));
472 unHideMe($('rdetail_cn_browse_div'));
473 unHideMe($('cn_browse'));
474 if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
475 cnBrowseGo(cn, loc, depth);
478 function rdetailhandleAC(data) {
480 if( data.reviews.html ) {
481 $('rdetail_review_container').innerHTML = data.reviews.html;
482 unHideMe($('rdetail_reviews_link'));
485 if( data.toc.html ) {
486 $('rdetail_toc_div').innerHTML = data.toc.html;
487 unHideMe($('rdetail_toc_link'));
490 if( data.excerpt.html ) {
491 $('rdetail_excerpt_div').innerHTML = data.excerpt.html;
492 unHideMe($('rdetail_excerpt_link'));
495 if( data.anotes.html ) {
496 $('rdetail_anotes_div').innerHTML = data.anotes.html;
497 unHideMe($('rdetail_anotes_link'));
501 function rdetailShowReviews(r) {
502 hideMe($('rdetail_extras_loading'));
503 var res = r.getResultObject();
504 var par = $('rdetail_reviews_div');
505 var template = par.removeChild($('rdetail_review_template'));
506 if( res && res.length > 0 ) {
507 unHideMe($('rdetail_reviews_link'));
508 for( var i = 0; i != res.length; i++ ) {
510 if( rev.text && rev.info ) {
511 var node = template.cloneNode(true);
512 $n(node, 'review_header').appendChild(text(rev.info));
513 $n(node, 'review_text').appendChild(text(rev.text));
514 par.appendChild(node);
521 function rdetailShowTOC(r) {
522 hideMe($('rdetail_extras_loading'));
523 var resp = r.getResultObject();
525 unHideMe($('rdetail_toc_link'));
526 $('rdetail_toc_div').innerHTML = resp;
530 function rdetailBuildInfoRows() {
532 var method = FETCH_COPY_COUNTS_SUMMARY;
533 if (rdetailShowCopyLocation)
534 method = FETCH_COPY_LOCATION_COUNTS_SUMMARY;
536 if( rdetailShowLocal )
537 req = new Request(method, record.doc_id(), getLocation(), getDepth())
539 req = new Request(method, record.doc_id());
540 req.callback(_rdetailBuildInfoRows);
544 function _rdetailRows(node) {
546 if( rdetailShowLocal && getLocation() != globalOrgTree.id() ) {
547 var loc = findOrgUnit(getLocation());
549 if( !orgIsMine(node, loc) ) return;
551 for( var i = 0; i < globalOrgTree.children().length; i++ ) {
552 var org = findOrgUnit(globalOrgTree.children()[i]);
553 if( orgIsMine(org, loc) ) {
561 if(!node && findOrgType(globalOrgTree.ou_type()).can_have_vols())
562 node = globalOrgTree;
565 /* don't show hidden orgs */
569 if(!isXUL() && !isTrue(node.opac_visible())) return;
571 var row = copyRow.cloneNode(true);
572 row.id = "cp_info_" + node.id();
574 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
575 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
576 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
577 var actions = $n(row, 'rdetail_actions_cell');
579 var p = libtd.getElementsByTagName('a')[0];
580 libtd.insertBefore(text(node.name()), p);
581 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
583 if(!findOrgType(node.ou_type()).can_have_vols()) {
585 row.removeChild(cntd);
586 row.removeChild(cpctd);
587 row.removeChild(actions);
588 row.setAttribute('novols', '1');
590 libtd.setAttribute("colspan", numStatuses + 3 );
591 libtd.colSpan = numStatuses + 3;
592 addCSSClass(row, 'copy_info_region_row');
595 copyRowParent.appendChild(row);
597 } else { node = globalOrgTree; }
599 for( var c in node.children() )
600 _rdetailRows(node.children()[c]);
603 function rdetailCNPrint(orgid, cn) {
604 var div = cpdBuildPrintWindow( record, orgid);
605 var template = div.removeChild($n(div, 'cnrow'));
606 var rowNode = $("cp_info_" + orgid);
607 cpdStylePopupWindow(div);
608 openWindow(div.innerHTML);
611 var localCNFound = false;
613 function _rdetailBuildInfoRows(r) {
615 if (rdetailShowCopyLocation)
616 unHideMe( $n( $('rdetail_copy_info_table'), 'rdetail_copylocation_header' ) );
618 removeChildren(copyRowParent);
622 var summary = r.getResultObject();
626 for( var i = 0; i < summary.length; i++ ) {
628 var arr = summary[i];
629 globalCNCache[arr[1]] = 1;
630 var thisOrg = findOrgUnit(arr[0]);
631 var rowNode = $("cp_info_" + thisOrg.id());
632 if(!rowNode) continue;
634 if(rowNode.getAttribute("used")) {
636 if( rowNode.nextSibling ) {
637 sib = rowNode.nextSibling;
638 o ='cp_info_'+thisOrg.id()+'_';
639 /* push the new row on as the last row for this org unit */
640 while( sib && sib.id.match(o) ) {
641 sib = sib.nextSibling;
644 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), sib);
646 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
648 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
651 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
652 n.appendChild(text(thisOrg.name()));
653 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
654 rowNode.id = "cp_info_" + thisOrg.id() + '_' + (++ctr);
657 rowNode.setAttribute("used", "1");
660 var cpc_temp = rowNode.removeChild(
661 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
663 var statuses = arr[2];
665 if (rdetailShowCopyLocation) {
671 rdetailApplyStatuses(rowNode, cpc_temp, statuses);
674 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) {
683 //if(isLocal) unHideMe(rowNode);
686 rdetailSetPath( thisOrg, isLocal );
687 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal, thisOrg, cl );
689 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
692 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
695 function rdetailBuildBrowseInfo(row, cn, local, orgNode, cl) {
698 var cache = callnumberCache[cn];
699 if( cache ) cache.count++;
700 else callnumberCache[cn] = { count : 1 };
703 var depth = getDepth();
704 if( !local ) depth = findOrgDepth(globalOrgTree);
706 $n(row, 'rdetail_callnumber_cell').appendChild(text(cn));
708 if (rdetailShowCopyLocation) {
709 var cl_cell = $n(row, 'rdetail_copylocation_cell');
710 cl_cell.appendChild(text(cl));
714 _debug('setting action clicks for cn ' + cn);
716 var dHref = 'javascript:rdetailVolumeDetails('+
717 '{copy_location : "'+cl+'", rowid : "'+row.id+'", cn :"'+cn+'", depth:"'+depth+'", org:"'+orgNode.id()+'", local: '+local+'});';
719 var bHref = 'javascript:rdetailShowCNBrowse("' + cn + '", '+orgNode.id()+', "'+depth+'");';
721 unHideMe( $n(row, 'details') )
722 $n(row, 'details').setAttribute('href', dHref);
723 unHideMe( $n(row, 'browse') )
724 $n(row, 'browse').setAttribute('href', bHref);
727 unHideMe($n(row, 'hold_div'));
728 $n(row, 'hold').onclick = function() {
729 var req = new Request(FETCH_VOLUME_BY_INFO, cn, record.doc_id(), orgNode.id());
732 var vol = r.getResultObject();
733 holdsDrawEditor({type: 'V', volumeObject : vol});
741 // sets the path to org as 'active' and displays the path if it's local
742 function rdetailSetPath(org, local) {
743 if( findOrgDepth(org) == 0 ) return;
744 var row = $("cp_info_" + org.id());
745 row.setAttribute("hasinfo", "1");
747 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
750 //Append all the statuses for a given summary to the
752 function rdetailApplyStatuses( row, template, statuses ) {
753 for( var j in _statusPositions ) {
754 var stat = _statusPositions[j];
755 var val = statuses[stat.id()];
756 var nn = template.cloneNode(true);
757 if(val) nn.appendChild(text(val));
758 else nn.appendChild(text(0));
763 //Add one td (creating a new column) to the copy summary
764 //table for each opac_visible copy status
765 function rdetailBuildStatusColumns() {
767 rdetailGrabCopyStatuses();
768 var parent = statusRow;
769 var template = parent.removeChild(G.ui.rdetail.cp_status);
772 for( i = 0; i < cp_statuses.length; i++ ) {
774 var c = cp_statuses[i];
775 if( c && isTrue(c.opac_visible()) ) {
777 _statusPositions[i] = c;
778 var node = template.cloneNode(true);
779 var data = findNodeByName( node, config.names.rdetail.cp_status);
781 data.appendChild(text(name));
782 parent.appendChild(node);
787 for(x in _statusPositions) numStatuses++;
790 function rdetailGrabCopyStatuses() {
791 if(cp_statuses) return cp_statuses;
792 var req = new Request(FETCH_COPY_STATUSES);
794 cp_statuses = req.result();
795 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
798 function _rdetailSortStatuses(a, b) {
799 return parseInt(a.id()) - parseInt(b.id());
803 * Check for a Google Book preview
805 function rdetailCheckForGBPreview() {
806 if (!googleBookPreview) return;
807 searchForGBPreview( cleanISBN(record.isbn()) );
812 * @param {DOM object} query The form element containing the
813 * input parameters "isbns"
815 function searchForGBPreview( isbn ) {
817 // Delete any previous Google Booksearch JSON queries.
818 var GBPJsonScript = document.getElementById("GBPJsonScript");
820 GBPJsonScript.parentNode.removeChild(GBPJsonScript);
823 // Add a script element with the src as the user's Google Booksearch query.
824 // JSON output is specified by including the alt=json-in-script argument
825 // and the callback function is also specified as a URI argument.
826 var GBPScriptElement = document.createElement("script");
828 GBPScriptElement.setAttribute("id", "GBPJsonScript");
829 GBPScriptElement.setAttribute("src",
830 "http://books.google.com/books?bibkeys=" +
831 isbn + "&jscmd=viewapi&callback=GBPreviewCallback");
832 GBPScriptElement.setAttribute("type", "text/javascript");
834 // make the request to Google booksearch
835 document.documentElement.firstChild.appendChild(GBPScriptElement);
839 * This function is the call-back function for the JSON scripts which
840 * executes a Google book search response.
842 * XXX I18N of text needed
844 * @param {JSON} booksInfo is the JSON object pulled from the Google books service.
846 function GBPreviewCallback(GBPBookInfo) {
847 var GBPreviewDiv = document.getElementById("rdetail_preview_div");
850 for ( i in GBPBookInfo ) {
851 GBPBook = GBPBookInfo[i];
858 if ( GBPBook.preview != "noview" ) {
859 if ( GBPBook.preview == 'full' ) {
860 setText( $('rdetail_preview_link'), $('rdetail_preview_full_text').innerHTML );
861 $('rdetail_preview_link_a').title = $('rdetail_preview_title').innerHTML;
864 // Add a button below the book cover image to load the preview.
865 GBPBadge = document.createElement( 'img' );
866 GBPBadge.src = 'http://books.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif';
867 GBPBadge.title = $('rdetail_preview_badge').innerHTML;
868 GBPBadge.style.border = 0;
869 GBPBadgelink = document.createElement( 'a' );
870 GBPBadgelink.href = 'javascript:rdetailShowExtra("preview");';
871 GBPBadgelink.appendChild( GBPBadge );
872 $('rdetail_image_cell').appendChild( GBPBadgelink );
873 $('rdetail_preview_div').style.height = 600;
875 /* Display the "Preview" tab in the Extras section */
876 unHideMe( $('rdetail_preview_link' ) );
881 * This is called when the user clicks on the 'Preview' link. We assume
882 * a preview is available from Google if this link was made visible.
884 * XXX I18N of Google Book Preview language attribute needed
886 function rdetailDisplayGBPreview() {
887 unHideMe($('rdetail_extras_loading'));
888 GBPreviewPane = $('rdetail_preview_div');
889 if ( GBPreviewPane.getAttribute('loaded') == null ||
890 GBPreviewPane.getAttribute('loaded') == "false" ) {
891 google.load("books", "0", {"callback" : rdetailGBPViewerLoadCallback, "language": "en"} );
892 GBPreviewPane.setAttribute('loaded', 'true');
896 function rdetailGBPViewerLoadCallback() {
897 hideMe($('rdetail_extras_loading'));
898 var GBPViewer = new google.books.DefaultViewer(document.getElementById('rdetail_preview_div'));
899 GBPViewer.load('ISBN:' + cleanISBN(record.isbn()) );