1 dojo.require('openils.BibTemplate');
2 dojo.requireLocalization("openils.opac", "opac");
3 var opac_strings = dojo.i18n.getLocalization("openils.opac", "opac");
5 var recordsHandled = 0;
8 var isbnList = new Array();
9 var googleBooksLink = true;
10 var OpenLibraryLinks = true;
12 var resultFetchAllRecords = false;
13 var resultCompiledSearch = null;
15 /* set up the event handlers */
16 if( findCurrentPage() == MRESULT || findCurrentPage() == RRESULT ) {
17 G.evt.result.hitCountReceived.push(resultSetHitInfo);
18 G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
19 G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
20 G.evt.result.allRecordsReceived.push( function(){unHideMe($('result_info_2'))}, fetchOpenLibraryLinks, fetchGoogleBooksLink, fetchChiliFreshReviews);
22 attachEvt('result','lowHits',resultLowHits);
23 attachEvt('result','zeroHits',resultZeroHits);
24 attachEvt( "common", "locationUpdated", resultSBSubmit );
25 /* do this after we have ID's so the rank for mr pages will be correct */
26 attachEvt("result", "preCollectRecords", resultPaginate);
29 function resultSBSubmit(){searchBarSubmit();}
31 /* returns the last 'index' postion ocurring in this page */
32 function resultFinalPageIndex() {
33 if(getHitCount() < (getOffset() + getDisplayCount()))
34 return getHitCount() - 1;
35 return getOffset() + getDisplayCount() - 1;
41 /* generic search method */
42 function resultCollectSearchIds( type, method, handler ) {
44 var sort = (getSort() == SORT_TYPE_REL) ? null : getSort();
45 var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
52 var form = parseForm(getForm());
53 item_type = form.item_type;
54 item_form = form.item_form;
57 item_type = (getItemType()) ? getItemType().split(/,/) : null;
58 item_form = (getItemForm()) ? getItemForm().split(/,/) : null;
61 var limit = (resultFetchAllRecords) ? 1000 : getDisplayCount();
63 if( getOffset() > 0 ) {
64 if( getHitCount() > 0 && (getOffset() + getDisplayCount()) > getHitCount() )
65 limit = getHitCount() - getOffset();
68 var lasso = getLasso();
70 if (lasso) args.org_unit = -lasso;
71 else args.org_unit = getLocation();
73 args.depth = getDepth();
75 args.offset = getOffset();
76 args.visibility_limit = 3000;
77 args.default_class = getStype();
79 if(sort) args.sort = sort;
80 if(sortdir) args.sort_dir = sortdir;
81 if(item_type) args.item_type = item_type;
82 if(item_form) args.item_form = item_form;
83 if(getAvail()) args.available = 1;
86 if(getFacet()) args.facets = getFacet();
88 if(getAudience()) args.audience = getAudience().split(/,/);
89 if(getLitForm()) args.lit_form = getLitForm().split(/,/);
90 if(getLanguage()) args.language = getLanguage().split(/,/);
91 if(getBibLevel()) args.bib_level = getBibLevel().split(/,/);
92 if(getCopyLocs()) args.locations = getCopyLocs().split(/,/);
93 if(getPubdBefore()) args.before = getPubdBefore();
94 else if(getPubdAfter()) args.after = getPubdAfter();
95 else if(getPubdBetween()) args.between = getPubdBetween().split(/,/);
97 _debug('Search args: ' + js2JSON(args));
98 _debug('Raw query: ' + getTerm());
100 var my_ou = findOrgUnit(args.org_unit);
101 if (my_ou && my_ou.shortname()) {
102 var atomfeed = "/opac/extras/opensearch/1.1/" + my_ou.shortname() + "/atom-full/" + getStype() + '?searchTerms=' + getTerm();
103 if (args.facets) { atomfeed += ' ' + args.facets; }
104 if (sort) { atomfeed += '&searchSort=' + sort; }
105 if (sortdir) { atomfeed += '&searchSortDir=' + sortdir; }
106 dojo.create('link', {"rel":"alternate", "href":atomfeed, "type":"application/atom+xml"}, dojo.query('head')[0]);
109 var req = new Request(method, args, getTerm(), 1);
110 req.callback(handler);
118 /* set the search result info, number of hits, which results we're
119 displaying, links to the next/prev pages, etc. */
120 function resultSetHitInfo() {
122 var lasso = getLasso();
124 /* tell the user where the results are coming from */
125 var baseorg = findOrgUnit(getLocation());
126 var depth = getDepth();
127 var mydepth = findOrgDepth(baseorg);
128 if( findOrgDepth(baseorg) != depth ) {
129 var tmporg = baseorg;
130 while( mydepth > depth ) {
132 tmporg = findOrgUnit(tmporg.parent_ou());
134 unHideMe($('including_results_for'));
135 $('including_results_location').appendChild(text(tmporg.name()));
140 try{searchTimer.stop()}catch(e){}
142 //if( findCurrentPage() == MRESULT ) {
143 if( findCurrentPage() == MRESULT ||
145 (findCurrentPage() == RRESULT &&
147 getRtype() == RTYPE_TITLE ||
148 getRtype() == RTYPE_AUTHOR ||
149 getRtype() == RTYPE_SUBJECT ||
150 getRtype() == RTYPE_SERIES ||
151 getRtype() == RTYPE_KEYWORD
156 if(getHitCount() <= lowHitCount && getTerm())
157 runEvt('result', 'lowHits');
160 if(getHitCount() == 0) {
161 runEvt('result', 'zeroHits');
166 var pages = getHitCount() / getDisplayCount();
167 if(pages % 1) pages = parseInt(pages) + 1;
171 var cpage = (getOffset()/getDisplayCount()) + 1;
173 G.ui.result.current_page.appendChild(text(cpage));
174 G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
176 $('current_page2').appendChild(text(cpage));
177 $('num_pages2').appendChild(text(pages + ")")); /* the ) is dumb */
179 /* set the offsets */
180 var offsetEnd = getDisplayCount() + getOffset();
181 if( getDisplayCount() > (getHitCount() - getOffset()))
182 offsetEnd = getHitCount();
184 G.ui.result.offset_end.appendChild(text(offsetEnd));
185 G.ui.result.offset_start.appendChild(text(getOffset() + 1));
187 $('offset_end2').appendChild(text(offsetEnd));
188 $('offset_start2').appendChild(text(getOffset() + 1));
190 G.ui.result.result_count.appendChild(text(getHitCount()));
191 unHideMe(G.ui.result.info);
193 $('result_count2').appendChild(text(getHitCount()));
194 unHideMe($('result_info_div2'));
197 function resultLowHits() {
199 unHideMe($('result_low_hits'));
200 if(getHitCount() > 0)
201 unHideMe($('result_low_hits_msg'));
204 for(var key in resultCompiledSearch.searches)
205 words.push(resultCompiledSearch.searches[key].term);
207 var sreq = new Request(CHECK_SPELL, words.join(' '));
208 sreq.callback(resultSuggestSpelling);
211 for(var key in resultCompiledSearch.searches) {
212 var areq = new Request(FETCH_CROSSREF, key, resultCompiledSearch.searches[key].term);
213 areq.callback(resultLowHitXRef);
217 if( !(getForm() == null || getForm() == 'all' || getForm() == "") ) {
219 a[PARAM_FORM] = "all";
220 $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
221 unHideMe($('low_hits_remove_format'));
224 resultSuggestSearchClass();
226 if(getTerm()) resultExpandSearch(); /* advanced search */
229 var lowHitsXRefSet = {};
231 var lowHitsXRefLinkParent;
232 function resultLowHitXRef(r) {
233 if(!lowHitsXRefLink){
234 lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
235 lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
237 var res = r.getResultObject();
239 arr.concat(res.also);
240 if(arr && arr.length > 0) {
241 unHideMe($('low_hits_cross_ref'));
244 while( word = arr.shift() ) {
246 if (lowHitsXRefSet[word] == 1) continue;
247 lowHitsXRefSet[word] = 1;
251 a[PARAM_TERM] = word;
252 var template = lowHitsXRefLink.cloneNode(true);
253 template.setAttribute('href',buildOPACLink(a));
254 template.appendChild(text(word));
255 lowHitsXRefLinkParent.appendChild(template);
256 lowHitsXRefLinkParent.appendChild(text(' '));
261 function resultZeroHits() {
263 unHideMe($('result_low_hits'));
264 unHideMe($('result_zero_hits_msg'));
265 //if(getTerm()) resultExpandSearch(); /* advanced search */
268 function resultExpandSearch() {
269 var top = findOrgDepth(globalOrgTree);
270 if(getDepth() == top) return;
271 unHideMe($('low_hits_expand_range'));
272 var par = $('low_hits_expand_link').parentNode;
273 var template = par.removeChild($('low_hits_expand_link'));
275 var bottom = getDepth();
276 while( top < bottom ) {
278 a[PARAM_DEPTH] = top;
279 var temp = template.cloneNode(true);
280 temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
281 temp.setAttribute('href',buildOPACLink(a));
282 par.appendChild(temp);
287 function resultSuggestSearchClass() {
288 var stype = getStype();
289 if(stype == STYPE_KEYWORD) return;
291 unHideMe($('low_hits_search_type'));
292 if(stype != STYPE_TITLE) {
293 ref = $('low_hits_title_search');
295 a[PARAM_STYPE] = STYPE_TITLE;
296 ref.setAttribute('href',buildOPACLink(a));
298 if(stype != STYPE_AUTHOR) {
299 ref = $('low_hits_author_search');
301 a[PARAM_STYPE] = STYPE_AUTHOR;
302 ref.setAttribute('href',buildOPACLink(a));
304 if(stype != STYPE_SUBJECT) {
305 ref = $('low_hits_subject_search');
307 a[PARAM_STYPE] = STYPE_SUBJECT;
308 ref.setAttribute('href',buildOPACLink(a));
310 if(stype != STYPE_KEYWORD) {
311 ref = $('low_hits_keyword_search');
313 a[PARAM_STYPE] = STYPE_KEYWORD;
314 ref.setAttribute('href',buildOPACLink(a));
316 if(stype != STYPE_SERIES) {
317 ref = $('low_hits_series_search');
319 a[PARAM_STYPE] = STYPE_SERIES;
320 ref.setAttribute('href',buildOPACLink(a));
324 function resultSuggestSpelling(r) {
325 var res = r.getResultObject();
326 var phrase = getTerm();
327 var words = phrase.split(/ /);
331 for( var w = 0; w < words.length; w++ ) {
333 var blob = grep(res, function(i){return (i.word == word);});
334 if( blob ) blob = blob[0];
336 if( blob.word == word ) {
337 if( !blob.found && blob.suggestions && blob.suggestions[0] ) {
338 newterm += " " + blob.suggestions[0];
339 unHideMe($('did_you_mean'));
341 newterm += " " + word;
347 arg[PARAM_TERM] = newterm;
348 $('spell_check_link').setAttribute('href', buildOPACLink(arg));
349 $('spell_check_link').appendChild(text(newterm));
353 function resultPaginate() {
356 if( !( ((o) + getDisplayCount()) >= getHitCount()) ) {
359 args[PARAM_OFFSET] = o + getDisplayCount();
360 args[PARAM_SORT] = SORT;
361 args[PARAM_SORT_DIR] = SORT_DIR;
362 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
364 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
365 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
367 $('next_link2').setAttribute("href", buildOPACLink(args));
368 addCSSClass($('next_link2'), config.css.result.nav_active);
370 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
372 /* when hit count is divisible by display count, we have to adjust */
373 if( getHitCount() % getDisplayCount() == 0 )
374 args[PARAM_OFFSET] -= getDisplayCount();
377 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
378 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
380 $('end_link2').setAttribute("href", buildOPACLink(args));
381 addCSSClass($('end_link2'), config.css.result.nav_active);
388 args[PARAM_SORT] = SORT;
389 args[PARAM_SORT_DIR] = SORT_DIR;
390 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
392 args[PARAM_OFFSET] = o - getDisplayCount();
393 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
394 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
396 $('prev_link2').setAttribute( "href", buildOPACLink(args));
397 addCSSClass($('prev_link2'), config.css.result.nav_active);
399 args[PARAM_OFFSET] = 0;
400 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
401 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
403 $('search_home_link2').setAttribute( "href", buildOPACLink(args));
404 addCSSClass($('search_home_link2'), config.css.result.nav_active);
407 if(getDisplayCount() < getHitCount()) {
408 unHideMe($('start_end_links_span'));
409 unHideMe($('start_end_links_span2'));
413 try{searchTimer.stop()}catch(e){}
416 function buildunAPISpan (span, type, id) {
420 addCSSClass(span,'unapi-id');
424 'tag:' + cgi.server_name + ',' +
426 ':' + type + '/' + id
430 function unhideGoogleBooksLink (data) {
431 for (var i = 0; i < data.items.length; i++) {
432 var item = data.items[i];
435 for (var j = 0; j < item.volumeInfo.industryIdentifiers.length; j++) {
436 // XXX: As of 11-17-2011, some items do not return their own ISBN
437 // as an identifier, so this code fails. For example:
438 // https://www.googleapis.com/books/v1/volumes?q=isbn:0743243560&callback=unhideGoogleBooksLink
439 // It seems the only way around this would be doing a separate
440 // search for each result rather than one search for the whole
441 // page. Informal testing seems to indicate that these books
442 // are generally Google-unfriendly (no previews, not embeddable),
443 // so we will live without them for now.
444 var ident = item.volumeInfo.industryIdentifiers[j].identifier;
445 gbspan = $n(document.documentElement, 'googleBooksLink-' + ident);
448 if (!gbspan) continue;
450 var gba = $n(gbspan, "googleBooks-link");
454 item.volumeInfo.infoLink
455 // XXX: we might consider constructing the above link ourselves,
456 // as the link provided populates the search box with our original
457 // multi-item search. Something like:
458 // 'http://books.google.com/books?id=' + item.id
459 // Postive: cleaner display
460 // Negative: more fragile (link format subject to change; likely
461 // enough to matter?)
463 removeCSSClass( gbspan, 'hide_me' );
467 /* display the record info in the record display table 'pos' is the
468 zero based position the record should have in the display table */
469 function resultDisplayRecord(rec, pos, is_mr) {
471 fieldmapper.IDL.load(['mvr']);
472 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
474 recordsCache.push(rec);
476 var r = table.rows[pos + 1];
477 var currentISBN = cleanISBN(rec.isbn());
480 isbnList.push(currentISBN);
481 if (OpenLibraryLinks) {
482 var olspan = $n(r, 'openLibraryLink');
483 olspan.setAttribute('name', olspan.getAttribute('name') +
488 if (googleBooksLink) {
489 var gbspan = $n(r, "googleBooksLink");
490 // Google never has dashes in the ISBN, records sometimes do;
491 // remove them to match results list
492 // XXX: consider making part of cleanISBN(), or we can work around
493 // this if we move to one request per record
496 gbspan.getAttribute('name') + '-' + currentISBN.toString().replace(/-/g,"")
502 if (currentISBN && chilifresh && chilifresh != '(none)') {
503 var cfrow = $n(r, "chilifreshReview");
505 removeCSSClass( cfrow, 'hide_me' );
507 var cflink = $n(r, "chilifreshReviewLink");
511 'isbn_' + currentISBN
514 var cfdiv = $n(r, "chilifreshReviewResult");
518 'chili_review_' + currentISBN
525 var rank = parseFloat(ranks[pos + getOffset()]);
526 rank = parseInt( rank * 100 );
527 var relspan = $n(r, "relevancy_span");
528 relspan.appendChild(text(rank));
529 unHideMe(relspan.parentNode);
533 var pic = $n(r, config.names.result.item_jacket);
535 pic.setAttribute("src", buildJacketSrc(rec.doc_id()));
537 pic.setAttribute("src", "/opac/images/blank.png");
540 var title_link = $n(r, config.names.result.item_title);
541 var author_link = $n(r, config.names.result.item_author);
545 onlyrec = onlyrecord[ getOffset() + pos ];
547 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', onlyrec);
551 args[PARAM_OFFSET] = 0;
552 args[PARAM_RID] = onlyrec;
553 args[PARAM_MRID] = rec.doc_id();
554 pic.parentNode.setAttribute("href", buildOPACLink(args));
555 title_link.setAttribute("href", buildOPACLink(args));
556 title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
559 buildunAPISpan($n(r,'unapi'), 'metabib-metarecord', rec.doc_id());
561 buildTitleLink(rec, title_link);
564 args[PARAM_OFFSET] = 0;
565 args[PARAM_MRID] = rec.doc_id();
566 pic.parentNode.setAttribute("href", buildOPACLink(args));
569 unHideMe($n(r,'place_hold_span'));
570 $n(r,'place_hold_link').onclick = function() { resultDrawHoldsWindow(rec.doc_id(), 'M'); }
574 onlyrec = rec.doc_id();
575 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', rec.doc_id());
577 buildTitleDetailLink(rec, title_link);
580 args[PARAM_OFFSET] = 0;
581 args[PARAM_RID] = rec.doc_id();
582 pic.parentNode.setAttribute("href", buildOPACLink(args));
584 unHideMe($n(r,'place_hold_span'));
585 $n(r,'place_hold_link').onclick = function() { resultDrawHoldsWindow(rec.doc_id(), 'T'); }
588 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
592 if(!isNull(rec.edition())) {
593 unHideMe( $n(r, "result_table_extra_span"));
594 $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
596 if(!isNull(rec.pubdate())) {
597 unHideMe( $n(r, "result_table_extra_span"));
598 unHideMe($n(r, "result_table_pub_span"));
599 $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
601 if(!isNull(rec.publisher()) ) {
602 unHideMe( $n(r, "result_table_extra_span"));
603 unHideMe($n(r, "result_table_pub_span"));
604 $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
607 if(!isNull(rec.physical_description()) ) {
608 unHideMe( $n(r, "result_table_extra_span"));
609 var t = " " + rec.physical_description();
610 //$n(r, "result_table_phys_span").appendChild( text(t.replace(/:.*/g,'')));
611 $n(r, "result_table_phys_span").appendChild( text(t));
616 resultBuildFormatIcons( r, rec, is_mr );
622 org_unit : findOrgUnit(getLocation()).shortname(),
627 bt_params = dojo.mixin( bt_params, { record : onlyrec } );
629 bt_params = dojo.mixin( bt_params, { metarecord : onlyrec } );
632 if (findOrgType(findOrgUnit(getLocation()).ou_type()).can_have_vols())
633 unHideMe($n(r,'local_callnumber_list'));
635 new openils.BibTemplate( bt_params ).render();
639 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
642 if(resultPageIsDone()) {
643 runEvt('result', 'allRecordsReceived', recordsCache);
648 function resultDrawHoldsWindow(hold_target, hold_type) {
649 var src = location.href;
651 if(forceLoginSSL && src.match(/^http:/)) {
653 src = src.replace(/^http:/, 'https:');
655 if(src.match(/&hold_target=/)) {
656 src.replace(/&hold_target=(\d+)/, hold_target);
659 src += '&hold_target=' + hold_target;
665 holdsDrawEditor({record:hold_target, type:hold_type});
671 function _resultFindRec(id) {
672 for( var i = 0; i != recordsCache.length; i++ ) {
673 var rec = recordsCache[i];
674 if( rec && rec.doc_id() == id )
681 function resultBuildFormatIcons( row, rec, is_mr ) {
683 var ress = rec.types_of_resource();
685 for( var i in ress ) {
690 var link = $n(row, res + "_link");
692 var img = link.getElementsByTagName("img")[0];
693 removeCSSClass( img, config.css.dim );
697 if( f == modsFormatToMARC(res) )
698 addCSSClass( img, "dim2_border");
702 args[PARAM_OFFSET] = 0;
706 args[PARAM_TFORM] = modsFormatToMARC(res);
707 args[PARAM_MRID] = rec.doc_id();
711 args[PARAM_RID] = rec.doc_id();
714 link.setAttribute("href", buildOPACLink(args));
719 function fetchOpenLibraryLinks() {
720 if (isbnList.length > 0 && OpenLibraryLinks) {
721 /* OpenLibrary supports a number of different identifiers:
724 * OpenLibrary ID: olid:<openlibrary-ID>
726 * We'll just fire off ISBNs for now.
730 dojo.forEach(isbnList, function(isbn) {
731 isbns += 'isbn:' + isbn + '|';
733 isbns = isbns.replace(/.$/, '');
737 "url": "/opac/extras/ac/proxy/json/" + isbns,
739 "load": function (data) { renderOpenLibraryLinks(data); }
744 function renderOpenLibraryLinks(response) {
747 /* Iterate over each identifier we requested */
748 for (var item_id in response) {
750 var isbn = item_id.replace(/^isbn:/, '');
751 /* Iterate over each matching item; OpenLibrary supplies access info:
752 * * match: "exact" or "similar"
753 * * status: "full access" or "lendable"
755 dojo.forEach(response[item_id].items, function(item) {
756 ol_ebooks[isbn] = {};
757 if (item.match == 'exact') {
758 if (item.status == 'full access') {
759 ol_ebooks[isbn]['exact_full'] = item.itemURL;
761 ol_ebooks[isbn]['exact_lendable'] = item.itemURL;
764 if (item.status == 'full access') {
765 ol_ebooks[isbn]['similar_full'] = item.itemURL;
767 ol_ebooks[isbn]['similar_lendable'] = item.itemURL;
772 /* If there are no books to read or borrow, move on */
773 if (!ol_ebooks[isbn]) {
777 /* Now populate the results page with our ebook goodness*/
778 /* Go for the jugular - exact match with full access */
779 if (ol_ebooks[isbn]['exact_full']) {
780 createOpenLibraryLink(
781 isbn, ol_ebooks[isbn]['exact_full'], 'Read online'
786 /* Fall back to slightly less palatable options */
787 else if (ol_ebooks[isbn]['exact_lendable']) {
788 createOpenLibraryLink(
789 isbn, ol_ebooks[isbn]['exact_lendable'], 'Borrow online'
793 if (ol_ebooks[isbn]['similar_full']) {
794 createOpenLibraryLink(
795 isbn, ol_ebooks[isbn]['similar_full'], 'Read similar online'
797 } else if (ol_ebooks[isbn]['similar_lendable']) {
798 createOpenLibraryLink(
799 isbn, ol_ebooks[isbn]['similar_lendable'], 'Borrow similar online'
805 function createOpenLibraryLink(isbn, url, text) {
806 var ol_span = $n(document.documentElement, 'openLibraryLink-' + isbn);
808 var ol_a_span = dojo.create('a', {
810 "class": "classic_link"
814 "src": "/opac/images/openlibrary.gif"
817 dojo.create('br', null, ol_a_span);
818 ol_a_span.appendChild(dojo.doc.createTextNode(text));
819 dojo.removeClass(ol_span, 'hide_me');
822 function fetchGoogleBooksLink () {
823 if (isbnList.length > 0 && googleBooksLink) {
824 var scriptElement = document.createElement("script");
825 scriptElement.setAttribute("id", "jsonScript");
826 scriptElement.setAttribute("src",
827 "https://www.googleapis.com/books/v1/volumes?q=" +
828 escape('isbn:' + isbnList.join(' | isbn:')) + "&callback=unhideGoogleBooksLink");
829 scriptElement.setAttribute("type", "text/javascript");
830 // make the request to Google Book Search
831 document.documentElement.firstChild.appendChild(scriptElement);
835 function fetchChiliFreshReviews() {
836 if (chilifresh && chilifresh != '(none)') {
837 try { chili_init(); } catch(E) { console.log(E + '\n'); }
841 function resultPageIsDone(pos) {
843 return (recordsHandled == getDisplayCount()
844 || recordsHandled + getOffset() == getHitCount());
847 var resultCCHeaderApplied = false;
849 /* -------------------------------------------------------------------- */
850 /* dynamically add the copy count rows based on the org type 'countsrow'
851 is the row into which we will add TD's to hold the copy counts
852 This code generates copy count cells with an id of
853 'copy_count_cell_<depth>_<pagePosition>' */
854 function resultAddCopyCounts(rec, pagePosition) {
856 var r = table.rows[pagePosition + 1];
857 var countsrow = $n(r, config.names.result.counts_row );
858 var ccell = $n(countsrow, config.names.result.count_cell);
860 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
862 var orgHiding = checkOrgHiding();
864 for (var i = 0; i < nodes.length; i++) {
865 if (orgHiding.depth == findOrgDepth(nodes[i])) {
871 var node = nodes[start_here];
872 var type = findOrgType(node.ou_type());
873 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
874 ccell.title = type.opac_label();
875 //addCSSClass(ccell, config.css.result.cc_cell_even);
877 var lastcell = ccell;
878 var lastheadcell = null;
881 var ccheadcell = null;
882 if(!resultCCHeaderApplied && !getLasso()) {
883 ccrow = $('result_thead_row');
884 ccheadcell = ccrow.removeChild($n(ccrow, "result_thead_ccell"));
885 var t = ccheadcell.cloneNode(true);
887 t.appendChild(text(type.opac_label()));
888 ccrow.appendChild(t);
889 resultCCHeaderApplied = true;
892 if(nodes[start_here+1]) {
894 var x = start_here+1;
895 var d = findOrgDepth(nodes[start_here+1]);
896 var d2 = findOrgDepth(nodes[nodes.length -1]);
898 for( var i = d; i <= d2 ; i++ ) {
900 ccell = ccell.cloneNode(true);
902 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
903 //else addCSSClass(ccell, "copy_count_cell_even");
905 var node = nodes[x++];
906 var type = findOrgType(node.ou_type());
908 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
909 ccell.title = type.opac_label();
910 countsrow.insertBefore(ccell, lastcell);
914 var t = ccheadcell.cloneNode(true);
915 t.appendChild(text(type.opac_label()));
916 ccrow.insertBefore(t, lastheadcell);
922 unHideMe($("search_info_table"));
925 /* collect copy counts for a record using method 'methodName' */
926 function resultCollectCopyCounts(rec, pagePosition, methodName) {
927 if(rec == null || rec.doc_id() == null) return;
929 var loc = getLasso();
931 else loc= getLocation();
933 var req = new Request(methodName, loc, rec.doc_id(), getForm() );
934 req.request.userdata = [ rec, pagePosition ];
935 req.callback(resultHandleCopyCounts);
939 function resultHandleCopyCounts(r) {
940 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
944 /* XXX Needs to understand Lasso copy counts... */
945 /* display the collected copy counts */
946 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
947 if(copy_counts == null || rec == null) return;
950 var copy_counts_lasso = {
956 org_unit : getLasso()
959 for (var i in copy_counts) {
960 copy_counts_lasso.transcendant = copy_counts[i].transcendant;
961 copy_counts_lasso.count += parseInt(copy_counts[i].count);
962 copy_counts_lasso.unshadow += parseInt(copy_counts[i].unshadow);
963 copy_counts_lasso.available += parseInt(copy_counts[i].available);
966 copy_counts = [ copy_counts_lasso ];
970 while(copy_counts[i] != null) {
971 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
973 var cts = copy_counts[i];
974 cell.appendChild(text(cts.available + " / " + cts.count));
977 /* here we style opac-invisible records for xul */
979 if( cts.depth == 0 ) {
980 if(cts.transcendant == null && cts.unshadow == 0) {
981 _debug("found an opac-shadowed record: " + rec.doc_id());
982 var row = cell.parentNode.parentNode.parentNode.parentNode.parentNode;
984 addCSSClass( row, 'no_copies' );
986 addCSSClass( row, 'shadowed' );