Beginnings of BibTemplate powered search results, and copy availability display on...
authorkbeswick <kbeswick@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 23 Mar 2010 15:05:51 +0000 (15:05 +0000)
committerkbeswick <kbeswick@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 23 Mar 2010 15:05:51 +0000 (15:05 +0000)
page.

git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/branches/rel_1_6_0@841 6d9bc8c9-1ec2-4278-b937-99fde70a366f

web/opac/skin/btresult/js/result_common.js [new file with mode: 0644]
web/opac/skin/btresult/xml/result/result_table.xml [new file with mode: 0644]

diff --git a/web/opac/skin/btresult/js/result_common.js b/web/opac/skin/btresult/js/result_common.js
new file mode 100644 (file)
index 0000000..6d375cb
--- /dev/null
@@ -0,0 +1,747 @@
+//require bibtemplate
+dojo.require('openils.BibTemplate');
+
+var recordsHandled = 0;
+var recordsCache = [];
+var lowHitCount = 4;
+var isbnList = '';
+var googleBooksLink = true;
+
+var resultFetchAllRecords = false;
+var resultCompiledSearch = null;
+
+/* set up the event handlers */
+if( findCurrentPage() == MRESULT || findCurrentPage() == RRESULT ) {
+       G.evt.result.hitCountReceived.push(resultSetHitInfo);
+//     G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
+       G.evt.result.recordReceived.push(resultDisplayRecord);
+//     G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
+       G.evt.result.allRecordsReceived.push(resultBuildCaches, resultDrawSubjects, 
+      resultDrawAuthors, resultDrawSeries, function(){unHideMe($('result_info_2'))},
+         fetchGoogleBooksLink);
+
+       attachEvt('result','lowHits',resultLowHits);
+       attachEvt('result','zeroHits',resultZeroHits);
+       attachEvt( "common", "locationUpdated", resultSBSubmit );
+       /* do this after we have ID's so the rank for mr pages will be correct */
+       attachEvt("result", "preCollectRecords", resultPaginate);
+}
+
+function resultSBSubmit(){searchBarSubmit();}
+
+/* returns the last 'index' postion ocurring in this page */
+function resultFinalPageIndex() {
+       if(getHitCount() < (getOffset() + getDisplayCount())) 
+               return getHitCount() - 1;
+       return getOffset() + getDisplayCount() - 1;
+}
+
+
+
+
+/* generic search method */
+function resultCollectSearchIds( type, method, handler ) {
+
+       var sort                = (getSort() == SORT_TYPE_REL) ? null : getSort(); 
+       var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
+
+       var item_type;
+       var item_form;
+       var args = {};
+
+       if( type ) {
+               var form = parseForm(getForm());
+               item_type = form.item_type;
+               item_form = form.item_form;
+
+       } else {
+               item_type = (getItemType()) ? getItemType().split(/,/) : null;
+               item_form = (getItemForm()) ? getItemForm().split(/,/) : null;
+       }
+
+       var limit = (resultFetchAllRecords) ? 1000 : getDisplayCount();
+
+       if( getOffset() > 0 ) {
+               if( getHitCount() > 0 && (getOffset() + getDisplayCount()) > getHitCount() ) 
+                       limit = getHitCount() - getOffset();
+       }
+
+       var lasso = getLasso();
+
+       if (lasso) args.org_unit = -lasso;
+       else args.org_unit = getLocation();
+
+       args.depth    = getDepth();
+       args.limit    = limit;
+       args.offset   = getOffset();
+       args.visibility_limit = 3000;
+    args.default_class = getStype();
+
+       if(sort) args.sort = sort;
+       if(sortdir) args.sort_dir = sortdir;
+       if(item_type) args.item_type    = item_type;
+       if(item_form) args.item_form    = item_form;
+    if(getAvail()) args.available = 1;
+
+
+       if(getAudience()) args.audience  = getAudience().split(/,/);
+       if(getLitForm()) args.lit_form  = getLitForm().split(/,/);
+       if(getLanguage()) args.language = getLanguage().split(/,/);
+       if(getBibLevel()) args.bib_level        = getBibLevel().split(/,/);
+       if(getCopyLocs()) args.locations        = getCopyLocs().split(/,/);
+    if(getPubdBefore()) args.before = getPubdBefore();
+    else if(getPubdAfter()) args.after = getPubdAfter();
+    else if(getPubdBetween()) args.between = getPubdBetween().split(/,/);
+
+       _debug('Search args: ' + js2JSON(args));
+       _debug('Raw query: ' + getTerm());
+
+       var req = new Request(method, args, getTerm(), 1);
+       req.callback(handler);
+       req.send();
+}
+
+
+
+
+
+/* set the search result info, number of hits, which results we're 
+       displaying, links to the next/prev pages, etc. */
+function resultSetHitInfo() { 
+
+       var lasso = getLasso();
+       if (!lasso) {
+               /* tell the user where the results are coming from */
+               var baseorg = findOrgUnit(getLocation());
+               var depth = getDepth();
+               var mydepth = findOrgDepth(baseorg);
+               if( findOrgDepth(baseorg) != depth ) {
+                       var tmporg = baseorg;
+                       while( mydepth > depth ) {
+                               mydepth--;
+                               tmporg = findOrgUnit(tmporg.parent_ou());
+                       }
+                       unHideMe($('including_results_for'));
+                       $('including_results_location').appendChild(text(tmporg.name()));
+               }
+       }
+
+
+       try{searchTimer.stop()}catch(e){}
+
+       //if( findCurrentPage() == MRESULT ) {
+       if( findCurrentPage() == MRESULT || 
+
+               (findCurrentPage() == RRESULT &&
+                       (
+                               getRtype() == RTYPE_TITLE ||
+                               getRtype() == RTYPE_AUTHOR ||
+                               getRtype() == RTYPE_SUBJECT ||
+                               getRtype() == RTYPE_SERIES ||
+                               getRtype() == RTYPE_KEYWORD 
+                       )
+
+               ) ) {
+
+               if(getHitCount() <= lowHitCount && getTerm())
+                       runEvt('result', 'lowHits');
+       }
+
+       if(getHitCount() == 0) {
+               runEvt('result', 'zeroHits');
+               return;
+       }
+
+
+       var pages = getHitCount() / getDisplayCount();
+       if(pages % 1) pages = parseInt(pages) + 1;
+
+       
+
+       var cpage = (getOffset()/getDisplayCount()) + 1;
+
+       G.ui.result.current_page.appendChild(text(cpage));
+       G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
+
+       $('current_page2').appendChild(text(cpage));
+       $('num_pages2').appendChild(text(pages + ")")); /* the ) is dumb */
+
+       /* set the offsets */
+       var offsetEnd = getDisplayCount() + getOffset();  
+       if( getDisplayCount() > (getHitCount() - getOffset()))  
+               offsetEnd = getHitCount();
+
+       G.ui.result.offset_end.appendChild(text(offsetEnd));
+       G.ui.result.offset_start.appendChild(text(getOffset() + 1));
+
+       $('offset_end2').appendChild(text(offsetEnd));
+       $('offset_start2').appendChild(text(getOffset() + 1));
+
+       G.ui.result.result_count.appendChild(text(getHitCount()));
+       unHideMe(G.ui.result.info);
+
+       $('result_count2').appendChild(text(getHitCount()));
+       unHideMe($('result_info_div2'));
+}
+
+function resultLowHits() {
+       showCanvas();
+       unHideMe($('result_low_hits'));
+       if(getHitCount() > 0)
+               unHideMe($('result_low_hits_msg'));
+
+    var words = [];
+    for(var key in resultCompiledSearch.searches) 
+        words.push(resultCompiledSearch.searches[key].term);
+
+       var sreq = new Request(CHECK_SPELL, words.join(' '));
+       sreq.callback(resultSuggestSpelling);
+       sreq.send();
+
+    for(var key in resultCompiledSearch.searches) {
+               var areq = new Request(FETCH_CROSSREF, key, resultCompiledSearch.searches[key].term);
+               areq.callback(resultLowHitXRef);
+               areq.send();
+       }
+
+       if( !(getForm() == null || getForm() == 'all' || getForm() == "") ) {
+               var a = {};
+               a[PARAM_FORM] = "all";
+               $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
+               unHideMe($('low_hits_remove_format'));
+       }
+
+       resultSuggestSearchClass();
+
+       if(getTerm()) resultExpandSearch(); /* advanced search */
+}
+
+var lowHitsXRefSet = {};
+var lowHitsXRefLink;
+var lowHitsXRefLinkParent;
+function resultLowHitXRef(r) {
+       if(!lowHitsXRefLink){
+               lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
+               lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
+       }
+       var res = r.getResultObject();
+       var arr = res.from;
+       arr.concat(res.also);
+       if(arr && arr.length > 0) {
+               unHideMe($('low_hits_cross_ref'));
+               var word;
+               var c = 0;
+               while( word = arr.shift() ) {
+
+            if (lowHitsXRefSet[word] == 1) continue;
+            lowHitsXRefSet[word] = 1;
+
+                       if(c++ > 20) break;
+                       var a = {};
+                       a[PARAM_TERM] = word;
+                       var template = lowHitsXRefLink.cloneNode(true);
+                       template.setAttribute('href',buildOPACLink(a));
+                       template.appendChild(text(word));
+                       lowHitsXRefLinkParent.appendChild(template);
+                       lowHitsXRefLinkParent.appendChild(text(' '));
+               }
+       }
+}
+
+function resultZeroHits() {
+       showCanvas();
+       unHideMe($('result_low_hits'));
+       unHideMe($('result_zero_hits_msg'));
+       //if(getTerm()) resultExpandSearch(); /* advanced search */
+}
+
+function resultExpandSearch() {
+       var top = findOrgDepth(globalOrgTree);
+       if(getDepth() == top) return;
+       unHideMe($('low_hits_expand_range'));
+       var par = $('low_hits_expand_link').parentNode;
+       var template = par.removeChild($('low_hits_expand_link'));
+
+       var bottom = getDepth();
+       while( top < bottom ) {
+               var a = {};
+               a[PARAM_DEPTH] = top;
+               var temp = template.cloneNode(true);
+               temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
+               temp.setAttribute('href',buildOPACLink(a));
+               par.appendChild(temp);
+               top++;
+       }
+}
+
+function resultSuggestSearchClass() {
+       var stype = getStype();
+       if(stype == STYPE_KEYWORD) return;
+       var a = {}; var ref;
+       unHideMe($('low_hits_search_type'));
+       if(stype != STYPE_TITLE) {
+               ref = $('low_hits_title_search');
+               unHideMe(ref);
+               a[PARAM_STYPE] = STYPE_TITLE;
+               ref.setAttribute('href',buildOPACLink(a));
+       }
+       if(stype != STYPE_AUTHOR) {
+               ref = $('low_hits_author_search');
+               unHideMe(ref);
+               a[PARAM_STYPE] = STYPE_AUTHOR;
+               ref.setAttribute('href',buildOPACLink(a));
+       }
+       if(stype != STYPE_SUBJECT) {
+               ref = $('low_hits_subject_search');
+               unHideMe(ref);
+               a[PARAM_STYPE] = STYPE_SUBJECT;
+               ref.setAttribute('href',buildOPACLink(a));
+       }
+       if(stype != STYPE_KEYWORD) {
+               ref = $('low_hits_keyword_search');
+               unHideMe(ref);
+               a[PARAM_STYPE] = STYPE_KEYWORD;
+               ref.setAttribute('href',buildOPACLink(a));
+       }
+       if(stype != STYPE_SERIES) {
+               ref = $('low_hits_series_search');
+               unHideMe(ref);
+               a[PARAM_STYPE] = STYPE_SERIES;
+               ref.setAttribute('href',buildOPACLink(a));
+       }
+}
+
+function resultSuggestSpelling(r) {
+       var res = r.getResultObject();
+       var phrase = getTerm();
+       var words = phrase.split(/ /);
+
+       var newterm = "";
+
+       for( var w = 0; w < words.length; w++ ) {
+               var word = words[w];
+               var blob = grep(res, function(i){return (i.word == word);});
+               if( blob ) blob = blob[0];
+               else continue;
+               if( blob.word == word ) {
+                       if( blob.suggestions && blob.suggestions[0] ) {
+                               newterm += " " + blob.suggestions[0];
+                               unHideMe($('did_you_mean'));
+                       } else {
+                               newterm += " " + word;
+                       }
+               }
+       }
+
+       var arg = {};
+       arg[PARAM_TERM] = newterm;
+       $('spell_check_link').setAttribute('href', buildOPACLink(arg));
+       $('spell_check_link').appendChild(text(newterm));
+}
+
+
+function resultPaginate() {
+       var o = getOffset();
+
+       if( !(  ((o) + getDisplayCount()) >= getHitCount()) ) {
+
+               var args = {};
+               args[PARAM_OFFSET]      = o + getDisplayCount();
+               args[PARAM_SORT]                = SORT;
+               args[PARAM_SORT_DIR] = SORT_DIR;
+               args[PARAM_RLIST]               = new CGI().param(PARAM_RLIST);
+
+               G.ui.result.next_link.setAttribute("href", buildOPACLink(args)); 
+               addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
+
+               $('next_link2').setAttribute("href", buildOPACLink(args)); 
+               addCSSClass($('next_link2'), config.css.result.nav_active);
+
+               args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
+
+               /* when hit count is divisible by display count, we have to adjust */
+               if( getHitCount() % getDisplayCount() == 0 ) 
+                       args[PARAM_OFFSET] -= getDisplayCount();
+
+        /*
+               G.ui.result.end_link.setAttribute("href", buildOPACLink(args)); 
+               addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
+
+               $('end_link2').setAttribute("href", buildOPACLink(args)); 
+               addCSSClass($('end_link2'), config.css.result.nav_active);
+        */
+       }
+
+       if( o > 0 ) {
+
+               var args = {};
+               args[PARAM_SORT]                = SORT;
+               args[PARAM_SORT_DIR] = SORT_DIR;
+               args[PARAM_RLIST]               = new CGI().param(PARAM_RLIST);
+
+               args[PARAM_OFFSET] = o - getDisplayCount();
+               G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args)); 
+               addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
+
+               $('prev_link2').setAttribute( "href", buildOPACLink(args)); 
+               addCSSClass($('prev_link2'), config.css.result.nav_active);
+
+               args[PARAM_OFFSET] = 0;
+               G.ui.result.home_link.setAttribute( "href", buildOPACLink(args)); 
+               addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
+
+               $('search_home_link2').setAttribute( "href", buildOPACLink(args)); 
+               addCSSClass($('search_home_link2'), config.css.result.nav_active);
+       }
+
+       if(getDisplayCount() < getHitCount()) {
+               unHideMe($('start_end_links_span'));
+               unHideMe($('start_end_links_span2'));
+   }
+
+       showCanvas();
+       try{searchTimer.stop()}catch(e){}
+}
+
+function buildunAPISpan (span, type, id) {
+       var cgi = new CGI();
+       var d = new Date();
+
+       addCSSClass(span,'unapi-id');
+
+       span.setAttribute(
+               'title',
+               'tag:' + cgi.server_name + ',' +
+                       d.getFullYear() +
+                       ':' + type + '/' + id
+       );
+}
+
+function unhideGoogleBooksLink (data) {
+    for ( var i in data ) {
+        //if (data[i].preview == 'noview') continue;
+
+        var gbspan = $n(document.documentElement, 'googleBooksLink-' + i);
+        var gba = $n(gbspan, "googleBooks-link");
+
+        gba.setAttribute(
+            'href',
+            data[i].info_url
+        );
+        removeCSSClass( gbspan, 'hide_me' );
+    }
+}
+
+/* display the record info in the record display table 'pos' is the 
+               zero based position the record should have in the display table */
+function resultDisplayRecord(rec, pos, is_mr) {
+
+       if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
+       recordsHandled++;
+       recordsCache.push(rec);
+
+       var r = table.rows[pos + 1];
+       var currentISBN = cleanISBN(rec.isbn());
+
+       //instantiate bibtemplate
+       var here = findOrgUnit(getLocation());
+       new openils.BibTemplate({ root: r, record : rec.doc_id(), org_unit : here.shortname() }).render();
+
+
+    if (googleBooksLink) {
+           var gbspan = $n(r, "googleBooksLink");
+        if (currentISBN) {
+            gbspan.setAttribute(
+                'name',
+                gbspan.getAttribute('name') + '-' + currentISBN
+            );
+
+            if (isbnList) isbnList += ', ';
+            isbnList += currentISBN;
+        }
+    }
+
+/*
+       try {
+               var rank = parseFloat(ranks[pos + getOffset()]);
+               rank            = parseInt( rank * 100 );
+               var relspan = $n(r, "relevancy_span");
+               relspan.appendChild(text(rank));
+               unHideMe(relspan.parentNode);
+       } catch(e){ }
+*/
+
+       var pic = $n(r, config.names.result.item_jacket);
+       pic.setAttribute("src", buildISBNSrc(currentISBN));
+
+       var title_link = $n(r, config.names.result.item_title);
+       var author_link = $n(r, config.names.result.item_author);
+
+       if( is_mr )  {
+               var onlyrec = onlyrecord[ getOffset() + pos ];
+               if(onlyrec) {
+                       buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', onlyrec);
+
+                       var args = {};
+                       args.page = RDETAIL;
+                       args[PARAM_OFFSET] = 0;
+                       args[PARAM_RID] = onlyrec;
+                       args[PARAM_MRID] = rec.doc_id();
+                       pic.parentNode.setAttribute("href", buildOPACLink(args));
+                       title_link.setAttribute("href", buildOPACLink(args));
+                       //title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
+                       
+               } else {
+                       buildunAPISpan($n(r,'unapi'), 'metabib-metarecord', rec.doc_id());
+
+                       buildTitleLink(rec, title_link); 
+                       var args = {};
+                       args.page = RRESULT;
+                       args[PARAM_OFFSET] = 0;
+                       args[PARAM_MRID] = rec.doc_id();
+                       pic.parentNode.setAttribute("href", buildOPACLink(args));
+               }
+
+       } else {
+               buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', rec.doc_id());
+
+               buildTitleDetailLink(rec, title_link); 
+               var args = {};
+               args.page = RDETAIL;
+               args[PARAM_OFFSET] = 0;
+               args[PARAM_RID] = rec.doc_id();
+               pic.parentNode.setAttribute("href", buildOPACLink(args));
+
+               unHideMe($n(r,'place_hold_span'));
+               $n(r,'place_hold_link').setAttribute(
+                       'href','javascript:holdsDrawEditor({record:"'+rec.doc_id()+'",type:"T"});');
+       }
+
+       buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
+
+       if(! is_mr ) {
+       
+               if(!isNull(rec.edition()))      {
+                       unHideMe( $n(r, "result_table_extra_span"));
+                       $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
+               }
+
+       }
+
+       resultBuildFormatIcons( r, rec, is_mr );
+
+       unHideMe(r);
+       
+       runEvt("result", "recordDrawn", rec.doc_id(), title_link);
+
+       /*
+       if(resultPageIsDone())  {
+               runEvt('result', 'allRecordsReceived', recordsCache);
+       }
+       */
+}
+
+function _resultFindRec(id) {
+       for( var i = 0; i != recordsCache.length; i++ ) {
+               var rec = recordsCache[i];
+               if( rec && rec.doc_id() == id )
+                       return rec;
+       }
+       return null;
+}
+
+
+function resultBuildFormatIcons( row, rec, is_mr ) {
+
+       var ress = rec.types_of_resource();
+
+       for( var i in ress ) {
+
+               var res = ress[i];
+               if(!res) continue;
+
+               var link = $n(row, res + "_link");
+               link.title = res;
+               var img = link.getElementsByTagName("img")[0];
+               removeCSSClass( img, config.css.dim );
+
+               var f = getForm();
+               if( f != "all" ) {
+                       if( f == modsFormatToMARC(res) ) 
+                               addCSSClass( img, "dim2_border");
+               }
+
+               var args = {};
+               args[PARAM_OFFSET] = 0;
+
+               if(is_mr) {
+                       args.page = RRESULT;
+                       args[PARAM_TFORM] = modsFormatToMARC(res);
+                       args[PARAM_MRID] = rec.doc_id();
+
+               } else {
+                       args.page = RDETAIL
+                       args[PARAM_RID] = rec.doc_id();
+               }
+
+               link.setAttribute("href", buildOPACLink(args));
+
+       }
+}
+
+function fetchGoogleBooksLink () {
+    if (isbnList && googleBooksLink) {
+        var scriptElement = document.createElement("script");
+        scriptElement.setAttribute("id", "jsonScript");
+        scriptElement.setAttribute("src",
+            "http://books.google.com/books?bibkeys=" + 
+            escape(isbnList) + "&jscmd=viewapi&callback=unhideGoogleBooksLink");
+        scriptElement.setAttribute("type", "text/javascript");
+        // make the request to Google Book Search
+        document.documentElement.firstChild.appendChild(scriptElement);
+    }
+}
+
+function resultPageIsDone(pos) {
+
+       return (recordsHandled == getDisplayCount() 
+               || recordsHandled + getOffset() == getHitCount());
+}
+
+var resultCCHeaderApplied = false;
+
+/* -------------------------------------------------------------------- */
+/* dynamically add the copy count rows based on the org type 'countsrow' 
+       is the row into which we will add TD's to hold the copy counts 
+       This code generates copy count cells with an id of
+       'copy_count_cell_<depth>_<pagePosition>'  */
+function resultAddCopyCounts(rec, pagePosition) {
+
+       var r = table.rows[pagePosition + 1];
+       var countsrow = $n(r, config.names.result.counts_row );
+       var ccell = $n(countsrow, config.names.result.count_cell);
+
+       var nodes = orgNodeTrail(findOrgUnit(getLocation()));
+       var node = nodes[0];
+       var type = findOrgType(node.ou_type());
+       ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
+       ccell.title = type.opac_label();
+       //addCSSClass(ccell, config.css.result.cc_cell_even);
+
+       var lastcell = ccell;
+       var lastheadcell = null;
+
+       var cchead = null;
+       var ccheadcell = null;
+       if(!resultCCHeaderApplied && !getLasso()) {
+               ccrow = $('result_thead_row');
+               ccheadcell =  ccrow.removeChild($n(ccrow, "result_thead_ccell"));
+               var t = ccheadcell.cloneNode(true);
+               lastheadcell = t;
+               t.appendChild(text(type.opac_label()));
+               ccrow.appendChild(t);
+               resultCCHeaderApplied = true;
+       }
+
+       if(nodes[1]) {
+
+               var x = 1;
+               var d = findOrgDepth(nodes[1]);
+               var d2 = findOrgDepth(nodes[nodes.length -1]);
+
+               for( var i = d; i <= d2 ; i++ ) {
+       
+                       ccell = ccell.cloneNode(true);
+
+                       //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
+                       //else addCSSClass(ccell, "copy_count_cell_even");
+
+                       var node = nodes[x++];
+                       var type = findOrgType(node.ou_type());
+       
+                       ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
+                       ccell.title = type.opac_label();
+                       countsrow.insertBefore(ccell, lastcell);
+                       lastcell = ccell;
+
+                       if(ccheadcell) {
+                               var t = ccheadcell.cloneNode(true);
+                               t.appendChild(text(type.opac_label()));
+                               ccrow.insertBefore(t, lastheadcell);
+                               lastheadcell = t;
+                       }
+               }
+       }
+
+       unHideMe($("search_info_table"));
+}
+
+/* collect copy counts for a record using method 'methodName' */
+function resultCollectCopyCounts(rec, pagePosition, methodName) {
+       if(rec == null || rec.doc_id() == null) return;
+
+       var loc = getLasso();
+       if (loc) loc = -loc;
+       else loc= getLocation();
+
+       var req = new Request(methodName, loc, rec.doc_id(), getForm() );
+       req.request.userdata = [ rec, pagePosition ];
+       req.callback(resultHandleCopyCounts);
+       req.send();
+}
+
+function resultHandleCopyCounts(r) {
+       runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject()); 
+}
+
+
+/* XXX Needs to understand Lasso copy counts... */
+/* display the collected copy counts */
+function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
+       if(copy_counts == null || rec == null) return;
+
+       if (getLasso()) {
+               var copy_counts_lasso = {
+                       transcendant : null,
+                       count : 0,
+                       unshadow : 0,
+                       available : 0,
+                       depth : -1,
+                       org_unit : getLasso()
+               };
+
+               for (var i in copy_counts) {
+                       copy_counts_lasso.transcendant = copy_counts[i].transcendant;
+                       copy_counts_lasso.count += parseInt(copy_counts[i].count);
+                       copy_counts_lasso.unshadow += parseInt(copy_counts[i].unshadow);
+                       copy_counts_lasso.available += parseInt(copy_counts[i].available);
+               }
+
+               copy_counts = [ copy_counts_lasso ];
+       }
+
+       var i = 0;
+       while(copy_counts[i] != null) {
+               var cell = $("copy_count_cell_" + i +"_" + pagePosition);
+               var cts = copy_counts[i];
+               cell.appendChild(text(cts.available + " / " + cts.count));
+
+               if(isXUL()) {
+                       /* here we style opac-invisible records for xul */
+
+                       if( cts.depth == 0 ) {
+                               if(cts.transcendant == null && cts.unshadow == 0) {
+                                       _debug("found an opac-shadowed record: " + rec.doc_id());
+                                       var row = cell.parentNode.parentNode.parentNode.parentNode.parentNode; 
+                                       if( cts.count == 0 ) 
+                                               addCSSClass( row, 'no_copies' );
+                                       else 
+                                               addCSSClass( row, 'shadowed' );
+                               }
+                       }
+               }
+               i++;
+       }
+}
+
+
diff --git a/web/opac/skin/btresult/xml/result/result_table.xml b/web/opac/skin/btresult/xml/result/result_table.xml
new file mode 100644 (file)
index 0000000..724aca4
--- /dev/null
@@ -0,0 +1,253 @@
+<!-- Search results are spit into this table -->
+
+<div id='result_table_div' xmlns:xi="http://www.w3.org/2001/XInclude">
+
+       <table id='res_table'> 
+
+               <!-- for some reason, this is the only way i can force the cell widths -->
+               <thead id='result_thead'>
+                       <tr>
+                               <td class='result_table_pic_header'></td>
+                               <td> </td>
+                       </tr>
+               </thead>
+
+               <tbody id='result_table'>
+                       <tr>
+
+                               <td class='result_table_row'>
+                                       <!--#include virtual="result_info.xml"-->
+                               </td>
+                       </tr>
+
+                       <!-- Template for displaying a search result.  This row template is cloned and inserted
+                                       for each result returned -->
+
+                       <tr id='result_table_template' class='hide_me'>
+
+                               <!-- Jacket image goes here -->
+
+                               <td class='result_table_row' align='left'>
+                                       <table class='result_table_subtable'>
+                                               <tbody class='result_table_subtbody'>
+
+                                                       <tr style='height: 1em' name='counts_row'>
+
+                                                               <td  rowspan='3' class='result_table_pic_header'>
+                                                                       <a><img name='item_jacket' class='result_table_pic'/></a>
+                                                               </td>
+
+                                                               <td class='result_table_title_cell' name='result_table_title_cell'>
+                                                                       <!-- Title goes here -->
+                                                                       <a title="&result.table.keyword;" name='item_title' class='search_link' type='opac/slot-data' query='datafield[tag=245]' id='rresult_title'>
+                                                                               <!-- Title goes here -->
+                                                                               <script type='opac/slot-format'><![CDATA[
+                                                                                               var out = '';
+                                                                                               var list = dojo.query( 'subfield', item );
+                                                                                               for (var i = 0; i < list.length; i++) {
+                                                                                                       out += dojox.data.dom.textContent(list[i]) + ' ';
+                                                                                               }
+                                                                                       return normalize(truncate(out, 65));
+                                                                               ]]></script>
+                                                                       </a>
+                                                               </td>
+
+                                                               <!-- Copy this td for each copy count appended -->
+                                                               <!-- TODO - move this style to the external style sheet -->
+                                                               <td style="background-color: #E0F0E0; padding: 10px; text-align: left; width: 35%" rowspan='3' nowrap='nowrap' name="copy_count_cell" class='copy_count_cell' type='opac/slot-data' query='volumes volume copies'> 
+                                                                       <script type='opac/slot-format'><![CDATA[
+                                                                               var out = '';
+                                                                               var list = dojo.query ( 'copy', item );
+
+                         dojo.forEach (list, function (copy) {
+                      out += "<div><b>" + dojox.data.dom.textContent(dojo.query('status', copy)[0]) + "</b> @ " + dojox.data.dom.textContent(dojo.query('circlib', copy)[0]) + "</div>";
+                      out += "<div>" + dojox.data.dom.textContent(dojo.query('location', copy)[0]) + " - "; 
+                      // don't display for dummy copies for electronic stuff?
+                      out += dojo.attr(item.parentNode, 'label');
+                      out += "</div>";
+                    });
+
+                                                                               //check if online resource
+                                                                               var uriList = dojo.query('uris', item.parentNode).query('uri');
+
+                                                                               if (uriList.length > 0) {
+                                                                                       dojo.forEach (uriList, function (uri) {
+                                                                                               //dojo.place(dojo.create("a", { href: dojo.attr(uri,'href'), class: 'search_link', innerHTML: (dojo.attr(uri, 'use_restriction') || dojo.attr(uri, 'label'))}), dojo.byId('copy_count_cell'));
+                                                                                       out += "<a class='search_link' href=\"" + dojo.attr(uri, 'href') + "\">" + truncate((dojo.attr(uri, 'use_restriction') || dojo.attr(uri, 'label')), 40) + "</a><br/>";
+                                                                                       });
+                                                                               }
+
+                                                                               return out;
+                                                                       ]]></script>
+                                                               </td>
+
+                                                       </tr>
+               
+                                                       <tr style='height: 1em' >
+                                                               <td class='result_table_author_cell'>
+                                                                       <a title="&result.table.author;" name='item_author' class='search_link' type='opac/slot-data' query='datafield[tag=100], datafield[tag=110]' id='rresult_author'> 
+                                                                               <!-- Author goes here -->
+                                                                               <script type='opac/slot-format'><![CDATA[
+                                                                                       return dojox.data.dom.textContent(item);
+                                                                               ]]></script>
+                                                                       </a>
+                                                                       <div>
+                                                                       <span name='result_table_extra_span'>
+                                                                               <span name='result_table_pub_box' style='padding-left: 10px;'> 
+                                                                                       <span name='result_table_edition_span' style='padding-left: 10px;'></span> |
+                                                                                       <span name='result_table_pub_span' type='opac/slot-data' query='datafield[tag=260]'> 
+                                                                                               <script type='opac/slot-format'><![CDATA[
+                                                                                                       return dojox.data.dom.textContent(item);
+                                                                                               ]]></script>
+                                                                                       </span> |
+                                                                                       <span name='result_table_phys_span' type='opac/slot-data' query='datafield[tag=300]'> 
+                                                                                               <script type='opac/slot-format'><![CDATA[
+                                                                                                       return dojox.data.dom.textContent(item);
+                                                                                               ]]></script>
+                                                                                       </span>
+                                                                               </span>
+                                                                       </span>
+                                                                       </div>
+                                                               </td>
+                                                       </tr>
+
+                                                       <tr style='height:1em;' >
+                                                               <td name='result_table_format_cell' class='result_table_format_cell'>
+
+                                                                       <a name='text_link' class='search_link'> 
+                                                                               <img src='../../../../images/tor/text.jpg' class='dim tor_pic' />
+                                                                       </a>
+
+                                                                       <a name='sound recording-nonmusical_link' class='search_link'> 
+                                                                               <img src='../../../../images/tor/sound recording-nonmusical.jpg' class='dim tor_pic' />
+                                                                       </a>
+
+                                                                       <a name='moving image_link' class='search_link'> 
+                                                                               <img src='../../../../images/tor/moving image.jpg' class='dim tor_pic' />
+                                                                       </a>
+
+                                                                       <a name='software, multimedia_link' class='search_link'> 
+                                                                               <img src='../../../../images/tor/software, multimedia.jpg' class='dim tor_pic' />
+                                                                       </a>
+
+                                                                       <a name='sound recording-musical_link' class='search_link'> 
+                                                                               <img src='../../../../images/tor/sound recording-musical.jpg' class='dim tor_pic' />
+                                                                       </a>
+
+                                                                       <a name='cartographic_link' class='search_link'> 
+                                                                               <img src='../../../../images/tor/cartographic.jpg' class='dim tor_pic' />
+                                                                       </a>
+
+                                                                       <a name='mixed material_link' class='search_link'> 
+                                                                               <img src='../../../../images/tor/mixed material.jpg' class='dim tor_pic' />
+                                                                       </a>
+
+                                                                       <a name='notated music_link' class='search_link'> 
+                                                                               <img src='../../../../images/tor/notated music.jpg' class='dim tor_pic' />
+                                                                       </a>
+
+                                                                       <a name='sound recording_link' class='search_link'> 
+                                                                               <img src='../../../../images/tor/sound recording.jpg' class='dim tor_pic' />
+                                                                       </a>
+
+                                                                       <a name='still image_link' class='search_link'> 
+                                                                               <img src='../../../../images/tor/still images.jpg' class='dim tor_pic' />
+                                                                       </a>
+
+                                                                       <a name='three dimensional object_link' class='search_link'> 
+                                                                               <img src='../../../../images/tor/three dimensional object.jpg' class='dim tor_pic' />
+                                                                       </a>
+
+                                                                       <span class='hide_me' 
+                                                                               style='color: #9999FF; padding-left: 10px; font-size: 7pt; font-weight: 300;'> 
+                                                                               <span>&common.relevancy; </span><span name='relevancy_span'> </span>
+                                                                       </span>
+
+                                                                       <span class='hide_me' name='place_hold_span'>
+                                                                               <a style='padding-left: 8px;' href='javascript:void(0);' 
+                                                                                       class='classic_link' name='place_hold_link'>&opac.holds.placeHold;</a>
+                                                                       </span>
+
+                                                                       <!-- Empty span used for creating unAPI links -->
+                                                                       <abbr style='padding-left: 8px;' name="unapi" class="unapi-id">
+                                                                               <!-- unAPI URI goes here -->
+                                                                       </abbr>
+
+                                                                       <!-- Empty span used for creating Google Book Search-->
+                                                                       <span name="googleBooksLink" class="hide_me">
+                                                                               <a style='padding-left: 8px;' class='classic_link' name="googleBooks-link">&result.googleBooks.browse;</a>
+                                                                       </span>
+
+
+                                                               </td>
+                                                       </tr>
+
+                                               </tbody>
+                                       </table>
+                               </td>
+                       </tr>
+               </tbody>
+       </table>
+
+
+   <!-- ====================== -->
+   <table style='width: 100%; margin-top: 12px;' id='result_info_2' class='hide_me'>
+      <tbody>
+               
+             <tr class='color_4' style='height: 1em;'>
+                     
+                <td style='vertical-align: top;'  id='next_prev_links2'>
+                        
+                   <span class='hide_me' id='result_info_div2' style='font-size: 9pt;'>
+                      <span> &common.results; </span> 
+                      <b id='offset_start2'> </b>
+                      <span> - </span>
+                      <b id='offset_end2'> </b>
+                      <span> &common.ofAtLeast; </span>
+                      <b id='result_count2'> </b>
+                      <span style='padding-left: 6px;'> (page </span>
+                      <span id='current_page2'> </span>
+                      <span> &common.of; </span>
+                      <span id='num_pages2'> </span>
+                   </span>
+                           
+                   <span id='start_end_links_span2' class='hide_me' 
+                      style='padding-left: 40px;' >
+                   <a class='search_page_nav_link' id='search_home_link2' 
+                      title="&rdetail.page.results;">&rdetail.start;</a><a class='search_page_nav_link' 
+                      id='prev_link2' title='&rdetail.page.previous;'>&#171;</a>
+            
+                   <span class='search_page_nav_link' id='page_numbers2'> </span>
+                      <a  class='search_page_nav_link' id='next_link2' 
+                         title='&rdetail.page.next;'>&#187;</a>
+                      <!--
+                      <a class='search_page_nav_link' 
+                         id='end_link2' title="&rdetail.page.last;">&rdetail.end;</a>
+                      -->
+                   </span>
+                        
+                </td>
+                        
+                <td  colspan='5' 
+                   style='padding-bottom: 4px; text-align:center; vertical-align: top; border-bottom: 1px solid #E0E0E0;'>
+               <!--
+                   <span id='search_info_table2' style='font-size: 8pt;'>
+                   <b>Available copies / Total copies </b>
+                   </span>
+               -->
+                </td>
+             </tr>
+      </tbody>
+   </table>
+   <!-- ====================== -->
+
+
+       <script language='javascript' type='text/javascript'>
+               config.names.result.format_cell = 'result_table_format_cell';
+               config.names.result.format_link = 'resource_link'
+               config.names.result.format_pic = 'format_pic'
+       </script>
+
+</div>
+
+