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 = {};
25 var rdetailShowLocal = true;
26 var rdetailShowCopyLocation = true;
27 var googleBookPreview = true;
30 var nextContainerIndex;
32 function rdetailReload() {
34 args[PARAM_LOCATION] = getNewSearchLocation();
35 args[PARAM_DEPTH] = depthSelGetDepth();
36 goTo(buildOPACLink(args));
42 var rdetailPrev = null;
43 var rdetailNext = null;
44 var rdetailStart = null;
45 var rdetailEnd = null;
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) {
54 cachedRecords.ids = ids;
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];
66 $('np_offset').appendChild(text(i + 1));
67 $('np_count').appendChild(text(getHitCount()));
70 unHideMe($('np_table'));
71 unHideMe($('np_prev'));
72 unHideMe($('np_start'));
73 rdetailPrev = function() { _rdetailNav(prevRecord); };
74 rdetailStart = function() { _rdetailNav(cachedRecords.ids[0]); };
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]); };
85 runEvt('rdetail', 'nextPrevDrawn', i, cachedRecords.ids.length);
89 function _rdetailNav(id, offset) {
92 goTo(buildOPACLink(args));
95 function rdetailDraw() {
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);
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';
109 G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
110 G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
112 if(getLocation() == globalOrgTree.id())
113 hideMe(G.ui.rdetail.cp_info_all);
115 var req = new Request(FETCH_RMODS, getRid());
116 req.callback(_rdetailDraw);
119 detachAllEvt("result", "idsReceived");
120 G.evt.result.hitCountReceived = [];
121 G.evt.result.recordReceived = [];
122 G.evt.result.copyCountsReceived = [];
123 G.evt.result.allRecordsReceived = [];
126 function rdetailGetPageIds() {
127 attachEvt("result", "idsReceived", rdetailSetPaging );
128 resultFetchAllRecords = true;
129 rresultCollectIds(true);
133 function buildunAPISpan (span, type, id) {
137 addCSSClass(span,'unapi-id');
140 'title', 'tag:' + cgi.server_name + ',' +
141 d.getFullYear() + ':' + type + '/' + id
145 function rdetailViewMarc(r,id) {
146 hideMe($('rdetail_extras_loading'));
147 $('rdetail_view_marc_box').innerHTML = r.getResultObject();
149 var div = elem('div', { "class" : 'hide_me' });
150 var span = div.appendChild( elem('abbr') );
152 buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
154 $('rdetail_view_marc_box').insertBefore(span, $('rdetail_view_marc_box').firstChild);
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);
166 function rdetailShowAllCopies() {
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);
176 function _rdetailDraw(r) {
177 record = r.getResultObject();
179 runEvt('rdetail', 'recordRetrieved', record.doc_id());
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();
190 G.ui.rdetail.tor.appendChild(text(r[0]));
191 setResourcePic( G.ui.rdetail.tor_pic, r[0]);
193 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
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);
202 rdetailCheckForPreview();
205 hideMe($("rdetail.jacket_attrib_div"));
206 hideMe($("rdetail_img_link"));
211 // see if the record has any external links
212 var links = record.online_loc();
213 for( var i = 0; links && links.length > 0 && i < links.length; i = i + 3 ) {
215 // avoid matching "HTTP: The Complete Reference"
216 if( href.match(/https?:\/|ftps?:\/|mailto:/i) ) {
217 unHideMe($('rdetail_online_row'));
218 // MODS can contain a display label (used for the text of the link)
219 // as well as a note about the URL; many legacy systems conflate the
220 // two and generate MARC records that expect the note to be used as
221 // the text of the link, with no display label; here's the canonical
224 // 856 40 $uhttp://localhost$yDisplay label$zPublic note
226 // Note that the MARC21slim2MODS XSL concatenates $3 and $y together
227 // (as $y was defined later in MARC21's life as the display label)
228 var displayLabel = '' + links[i+1];
229 var note = '' + links[i+2];
230 if(!displayLabel || displayLabel.match(/https?:\/|ftps?:\/|mailto:/i)) {
231 if(!note || note.match(/https?:\/|ftps?:\/|mailto:/i)) {
237 $('rdetail_online').appendChild(elem('a', {href:href,'class':'classic_link'}, displayLabel));
238 if (!note && note != displayLabel) {
239 $('rdetail_online').appendChild(elem('span', {'class':'url_note'}, ' - ' + note));
241 $('rdetail_online').appendChild(elem('br'));
245 // Fill in our unAPI ID, if anyone cares
246 var abbrs = document.getElementsByTagName('abbr');
248 for (var i = 0; i < abbrs.length; i = i + 1) {
249 if (abbrs[i].getAttribute('name') == 'unapi') {
254 buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
256 $('rdetail_place_hold').setAttribute(
257 'href','javascript:holdsDrawEditor({record:"'+record.doc_id()+'",type:"T"});');
259 $('rdetail_img_link').setAttribute('href', buildISBNSrc(cleanISBN(record.isbn()), 'large'));
260 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
261 runEvt("rdetail", "recordDrawn");
262 recordsCache.push(record);
264 rdetailSetExtrasSelector();
266 var breq = new Request(FETCH_BRE, [getRid()]);
267 breq.callback( rdetailCheckDeleted );
270 resultBuildCaches( [ record ] );
271 resultDrawSubjects();
274 // grab added content
275 acCollectData(cleanISBN(record.isbn()), rdetailhandleAC);
280 function rdetailCheckDeleted(r) {
281 var br = r.getResultObject()[0];
282 if( isTrue(br.deleted()) ) {
283 hideMe($('rdetail_place_hold'));
284 $('rdetail_more_actions_selector').disabled = true;
285 unHideMe($('rdetail_deleted_exp'));
289 function rdetailSetExtrasSelector() {
290 if(!grabUser()) return;
291 unHideMe($('rdetail_more_actions'));
293 var req = new Request(
294 FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
295 req.callback(rdetailAddBookbags);
299 function rdetailAddBookbags(r) {
301 var containers = r.getResultObject();
302 var selector = $('rdetail_more_actions_selector');
305 doSelectorActions(selector);
307 for( var i = 0; i != containers.length; i++ ) {
309 var container = containers[i];
310 insertSelectorVal( selector, index++, container.name(),
311 "container_" + container.id(), rdetailAddToBookbag, 1 );
314 nextContainerIndex = index;
318 function rdetailNewBookbag() {
319 var name = prompt($('rdetail_bb_new').innerHTML,"");
323 if( id = containerCreate( name ) ) {
324 alert($('rdetail_bb_success').innerHTML);
325 var selector = $('rdetail_more_actions_selector');
326 insertSelectorVal( selector, nextContainerIndex++, name,
327 "container_" + id, rdetailAddToBookbag, 1 );
328 setSelector( selector, 'start' );
333 function rdetailAddToBookbag() {
334 var selector = $('rdetail_more_actions_selector');
335 var id = selector.options[selector.selectedIndex].value;
336 setSelector( selector, 'start' );
338 if( containerCreateItem( id.substring(10), record.doc_id() )) {
339 alert($('rdetail_bb_item_success').innerHTML);
344 var rdetailMarcFetched = false;
345 function rdetailShowExtra(type, args) {
347 hideMe($('rdetail_copy_info_div'));
348 hideMe($('rdetail_reviews_div'));
349 hideMe($('rdetail_toc_div'));
350 hideMe($('rdetail_anotes_div'));
351 hideMe($('rdetail_excerpt_div'));
352 hideMe($('rdetail_preview_div'));
353 hideMe($('rdetail_marc_div'));
354 hideMe($('cn_browse'));
355 hideMe($('rdetail_cn_browse_div'));
356 hideMe($('rdetail_notes_div'));
358 removeCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
359 removeCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
360 removeCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
361 removeCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
362 removeCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
363 removeCSSClass($('rdetail_preview_link'), 'rdetail_extras_selected');
364 removeCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
365 removeCSSClass($('rdetail_annotation_link'), 'rdetail_extras_selected');
366 removeCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
371 unHideMe($('rdetail_copy_info_div'));
372 addCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
376 addCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
377 unHideMe($('rdetail_reviews_div'));
381 addCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
382 unHideMe($('rdetail_excerpt_div'));
386 addCSSClass($('rdetail_preview_link'), 'rdetail_extras_selected');
387 unHideMe($('rdetail_preview_div'));
388 rdetailDisplayPreview();
392 addCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
393 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 );
430 function rdetailBuildCNList() {
432 var select = $('cn_browse_selector');
435 for( var cn in callnumberCache ) arr.push( cn );
438 if( arr.length == 0 ) {
439 hideMe($('rdetail_cn_browse_select_div'));
443 for( var i in arr ) {
445 var opt = new Option(cn);
446 select.options[index++] = opt;
448 select.onchange = rdetailGatherCN;
451 function rdetailGatherCN() {
452 var cn = getSelectorVal($('cn_browse_selector'));
453 rdetailShowCNBrowse( cn, getLocation(), getDepth(), true );
454 setSelector( $('cn_browse_selector'), cn );
458 function rdetailShowCNBrowse( cn, loc, depth, fromOnclick ) {
461 unHideMe($('cn_browse_none'));
462 hideMe($('rdetail_cn_browse_select_div'));
466 unHideMe($('rdetail_cn_browse_select_div'));
467 rdetailBuildCNList();
468 setSelector( $('cn_browse_selector'), cn );
469 hideMe($('rdetail_copy_info_div'));
470 hideMe($('rdetail_reviews_div'));
471 hideMe($('rdetail_toc_div'));
472 hideMe($('rdetail_marc_div'));
473 unHideMe($('rdetail_cn_browse_div'));
474 unHideMe($('cn_browse'));
475 if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
476 cnBrowseGo(cn, loc, depth);
479 function rdetailhandleAC(data) {
481 if( data.reviews.html ) {
482 $('rdetail_review_container').innerHTML = data.reviews.html;
483 unHideMe($('rdetail_reviews_link'));
486 if( data.toc.html ) {
487 $('rdetail_toc_div').innerHTML = data.toc.html;
488 unHideMe($('rdetail_toc_link'));
491 if( data.excerpt.html ) {
492 $('rdetail_excerpt_div').innerHTML = data.excerpt.html;
493 unHideMe($('rdetail_excerpt_link'));
496 if( data.anotes.html ) {
497 $('rdetail_anotes_div').innerHTML = data.anotes.html;
498 unHideMe($('rdetail_anotes_link'));
502 function rdetailShowReviews(r) {
503 hideMe($('rdetail_extras_loading'));
504 var res = r.getResultObject();
505 var par = $('rdetail_reviews_div');
506 var template = par.removeChild($('rdetail_review_template'));
507 if( res && res.length > 0 ) {
508 unHideMe($('rdetail_reviews_link'));
509 for( var i = 0; i != res.length; i++ ) {
511 if( rev.text && rev.info ) {
512 var node = template.cloneNode(true);
513 $n(node, 'review_header').appendChild(text(rev.info));
514 $n(node, 'review_text').appendChild(text(rev.text));
515 par.appendChild(node);
522 function rdetailShowTOC(r) {
523 hideMe($('rdetail_extras_loading'));
524 var resp = r.getResultObject();
526 unHideMe($('rdetail_toc_link'));
527 $('rdetail_toc_div').innerHTML = resp;
532 function rdetailBuildInfoRows() {
534 var method = FETCH_COPY_COUNTS_SUMMARY;
535 if (rdetailShowCopyLocation)
536 method = FETCH_COPY_LOCATION_COUNTS_SUMMARY;
538 if( rdetailShowLocal )
539 req = new Request(method, record.doc_id(), getLocation(), getDepth())
541 req = new Request(method, record.doc_id());
542 req.callback(_rdetailBuildInfoRows);
546 function _rdetailRows(node) {
548 if( rdetailShowLocal && getLocation() != globalOrgTree.id() ) {
550 var loc = findOrgUnit(getLocation());
553 if( !orgIsMine(node, loc) ) return;
557 for( var i = 0; i < globalOrgTree.children().length; i++ ) {
558 var org = findOrgUnit(globalOrgTree.children()[i]);
559 if( orgIsMine(org, loc) ) {
567 if(!node && findOrgType(globalOrgTree.ou_type()).can_have_vols())
568 node = globalOrgTree;
571 /* don't show hidden orgs */
575 if(!isXUL() && !isTrue(node.opac_visible())) return;
577 var row = copyRow.cloneNode(true);
578 row.id = "cp_info_" + node.id();
580 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
581 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
582 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
583 var actions = $n(row, 'rdetail_actions_cell');
585 var p = libtd.getElementsByTagName('a')[0];
586 libtd.insertBefore(text(node.name()), p);
587 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
589 if(!findOrgType(node.ou_type()).can_have_vols()) {
591 row.removeChild(cntd);
592 row.removeChild(cpctd);
593 row.removeChild(actions);
594 row.setAttribute('novols', '1');
596 libtd.setAttribute("colspan", numStatuses + 3 );
597 libtd.colSpan = numStatuses + 3;
598 addCSSClass(row, 'copy_info_region_row');
601 copyRowParent.appendChild(row);
603 } else { node = globalOrgTree; }
605 for( var c in node.children() )
606 _rdetailRows(node.children()[c]);
609 function rdetailCNPrint(orgid, cn) {
610 var div = cpdBuildPrintWindow( record, orgid);
611 var template = div.removeChild($n(div, 'cnrow'));
612 var rowNode = $("cp_info_" + orgid);
613 cpdStylePopupWindow(div);
614 openWindow(div.innerHTML);
617 var localCNFound = false;
619 function _rdetailBuildInfoRows(r) {
621 if (rdetailShowCopyLocation)
622 unHideMe( $n( $('rdetail_copy_info_table'), 'rdetail_copylocation_header' ) );
624 removeChildren(copyRowParent);
628 var summary = r.getResultObject();
632 for( var i = 0; i < summary.length; i++ ) {
634 var arr = summary[i];
635 globalCNCache[arr[1]] = 1;
636 var thisOrg = findOrgUnit(arr[0]);
637 var rowNode = $("cp_info_" + thisOrg.id());
638 if(!rowNode) continue;
640 if(rowNode.getAttribute("used")) {
642 if( rowNode.nextSibling ) {
643 sib = rowNode.nextSibling;
644 o ='cp_info_'+thisOrg.id()+'_';
645 /* push the new row on as the last row for this org unit */
646 while( sib && sib.id.match(o) ) {
647 sib = sib.nextSibling;
650 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), sib);
652 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
654 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
657 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
658 n.appendChild(text(thisOrg.name()));
659 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
660 rowNode.id = "cp_info_" + thisOrg.id() + '_' + (++ctr);
663 rowNode.setAttribute("used", "1");
666 var cpc_temp = rowNode.removeChild(
667 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
669 var statuses = arr[2];
671 if (rdetailShowCopyLocation) {
677 rdetailApplyStatuses(rowNode, cpc_temp, statuses);
680 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) {
689 //if(isLocal) unHideMe(rowNode);
692 rdetailSetPath( thisOrg, isLocal );
693 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal, thisOrg, cl );
695 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
698 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
702 function rdetailBuildBrowseInfo(row, cn, local, orgNode, cl) {
705 var cache = callnumberCache[cn];
706 if( cache ) cache.count++;
707 else callnumberCache[cn] = { count : 1 };
710 var depth = getDepth();
711 if( !local ) depth = findOrgDepth(globalOrgTree);
713 $n(row, 'rdetail_callnumber_cell').appendChild(text(cn));
715 if (rdetailShowCopyLocation) {
716 var cl_cell = $n(row, 'rdetail_copylocation_cell');
717 cl_cell.appendChild(text(cl));
722 _debug('setting action clicks for cn ' + cn);
724 var dHref = 'javascript:rdetailVolumeDetails('+
725 '{copy_location : "'+cl+'", rowid : "'+row.id+'", cn :"'+cn+'", depth:"'+depth+'", org:"'+orgNode.id()+'", local: '+local+'});';
727 var bHref = 'javascript:rdetailShowCNBrowse("' + cn + '", '+orgNode.id()+', "'+depth+'");';
729 unHideMe( $n(row, 'details') )
730 $n(row, 'details').setAttribute('href', dHref);
731 unHideMe( $n(row, 'browse') )
732 $n(row, 'browse').setAttribute('href', bHref);
735 unHideMe($n(row, 'hold_div'));
736 $n(row, 'hold').onclick = function() {
737 var req = new Request(FETCH_VOLUME_BY_INFO, cn, record.doc_id(), orgNode.id());
740 var vol = r.getResultObject();
741 holdsDrawEditor({type: 'V', volumeObject : vol});
750 // sets the path to org as 'active' and displays the path if it's local
751 function rdetailSetPath(org, local) {
752 if( findOrgDepth(org) == 0 ) return;
753 var row = $("cp_info_" + org.id());
754 row.setAttribute("hasinfo", "1");
756 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
762 //Append all the statuses for a give summary to the
764 function rdetailApplyStatuses( row, template, statuses ) {
765 for( var j in _statusPositions ) {
766 var stat = _statusPositions[j];
767 var val = statuses[stat.id()];
768 var nn = template.cloneNode(true);
769 if(val) nn.appendChild(text(val));
770 else nn.appendChild(text(0));
776 var _statusPositions = {};
778 //Add one td (creating a new column) to the copy summary
779 //table for each opac_visible copy status
781 function rdetailBuildStatusColumns() {
783 rdetailGrabCopyStatuses();
784 var parent = statusRow;
785 var template = parent.removeChild(G.ui.rdetail.cp_status);
788 for( i = 0; i < cp_statuses.length; i++ ) {
790 var c = cp_statuses[i];
791 if( c && isTrue(c.opac_visible()) ) {
793 _statusPositions[i] = c;
794 var node = template.cloneNode(true);
795 var data = findNodeByName( node, config.names.rdetail.cp_status);
797 data.appendChild(text(name));
798 parent.appendChild(node);
803 for(x in _statusPositions) numStatuses++;
806 function rdetailGrabCopyStatuses() {
807 if(cp_statuses) return cp_statuses;
808 var req = new Request(FETCH_COPY_STATUSES);
810 cp_statuses = req.result();
811 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
814 function _rdetailSortStatuses(a, b) {
815 return parseInt(a.id()) - parseInt(b.id());
819 * XXX Need to adopt a more typical approach to showing loading status
821 function rdetailCheckForGBPreview() {
823 if (!googleBookPreview) return;
824 var GBPp = document.createElement('p');
825 GBPp.appendChild( document.createTextNode('Loading... ' ) );
827 $('rdetail_preview_div').appendChild(GBPp);
828 searchForGBPreview( cleanISBN(record.isbn()) );
834 * @param {DOM object} query The form element containing the
835 * input parameters "isbns"
837 function searchForGBPreview( isbn ) {
839 // Delete any previous Google Booksearch JSON queries.
840 var GBPJsonScript = document.getElementById("GBPJsonScript");
842 GBPJsonScript.parentNode.removeChild(GBPJsonScript);
844 // Add a script element with the src as the user's Google Booksearch query.
845 // JSON output is specified by including the alt=json-in-script argument
846 // and the callback function is also specified as a URI argument.
847 var GBPScriptElement = document.createElement("script");
849 GBPScriptElement.setAttribute("id", "GBPJsonScript");
850 GBPScriptElement.setAttribute("src",
851 "http://books.google.com/books?bibkeys=" +
852 isbn + "&jscmd=viewapi&callback=GBPreviewCallback");
853 GBPScriptElement.setAttribute("type", "text/javascript");
854 // make the request to Google booksearch
855 document.documentElement.firstChild.appendChild(GBPScriptElement);
859 * This function is the call-back function for the JSON scripts which
860 * executes a Google book search response.
862 * XXX I18N of text needed
864 * @param {JSON} booksInfo is the JSON object pulled from the Google books service.
866 function GBPreviewCallback(GBPBookInfo) {
867 // Clear any old data to prepare to display the Loading... message.
868 var GBPreviewDiv = document.getElementById("rdetail_preview_div");
871 for ( i in GBPBookInfo ) {
872 GBPBook = GBPBookInfo[i];
879 if ( GBPBook.preview != "noview" ) {
880 if ( GBPBook.preview == 'full' ) {
881 setText( $('rdetail_preview_link'), 'Full Text' );
882 $('rdetail_preview_link_a').title = 'See the full text of this book.';
885 // Add a button below the book cover image to load the preview.
886 GBPBadge = document.createElement( 'img' );
887 GBPBadge.src = 'http://books.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif';
888 GBPBadge.title = 'Show a preview of this book from Google Book Search';
889 GBPBadge.style.border = 0;
890 GBPBadgelink = document.createElement( 'a' );
891 GBPBadgelink.href = 'javascript:rdetailShowExtra("preview");';
892 GBPBadgelink.appendChild( GBPBadge );
893 $('rdetail_image_cell').appendChild( GBPBadgelink );
895 unHideMe( $('rdetail_preview_link' ) );
896 $('rdetail_preview_div').style.height = 600;
901 * This is called when the user clicks on the 'Preview' link. We assume
902 * a preview is available from Google if this link was made visible.
904 * XXX I18N of Google Book Preview language attribute needed
906 function rdetailDisplayGBPreview() {
907 GBPreviewPane = $('rdetail_preview_div');
908 if ( GBPreviewPane.getAttribute('loaded') == null || GBPreviewPane.getAttribute('loaded') == "false" ) {
909 google.load("books", "0", {"callback" : rdetailGBPViewerLoadCallback, "language": "en"} );
910 GBPreviewPane.setAttribute('loaded', 'true');
914 function rdetailGBPViewerLoadCallback() {
915 var GBPViewer = new google.books.DefaultViewer(document.getElementById('rdetail_preview_div'));
916 GBPViewer.load('ISBN:' + cleanISBN(record.isbn()) );