added zero/low hits stuff to the search result code
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 17 Nov 2005 14:46:19 +0000 (14:46 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 17 Nov 2005 14:46:19 +0000 (14:46 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@2054 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/common/js/config.js
Open-ILS/web/opac/common/js/opac_utils.js
Open-ILS/web/opac/skin/default/css/layout.css
Open-ILS/web/opac/skin/default/js/mresult.js
Open-ILS/web/opac/skin/default/js/result_common.js
Open-ILS/web/opac/skin/default/xml/altcanvas.xml
Open-ILS/web/opac/skin/default/xml/mresult.xml
Open-ILS/web/opac/skin/default/xml/result_common.xml

index 0ffbf6f..feda65d 100644 (file)
@@ -200,6 +200,7 @@ var UPDATE_USERNAME                         = "open-ils.actor:open-ils.actor.user.username.update";
 var UPDATE_PASSWORD                            = "open-ils.actor:open-ils.actor.user.password.update";
 var UPDATE_EMAIL                                       = "open-ils.actor:open-ils.actor.user.email.update";
 var RENEW_CIRC                                         = "open-ils.circ:open-ils.circ.renew";
+var CHECK_SPELL                                        = "open-ils.search:open-ils.search.spell_check";
 /* ---------------------------------------------------------------------------- */
 
 
@@ -254,6 +255,8 @@ createEvt("result", "allRecordsReceived");  /* f(mvrsArray) : add other page stuf
 createEvt("rdetail", "recordDrawn");                   /* f() : the record has been drawn */
 
 createEvt("common", "loggedIn");                                       /* f() : user has just logged in */
+createEvt('result', 'zeroHits');
+createEvt('result', 'lowHits');
 
 
 
index 17b06cd..87a4d8c 100644 (file)
@@ -562,6 +562,26 @@ function findRecord(id,type) {
        return req.result();
 }
 
+function Timer(name, node){
+       this.name = name;
+       this.count = 1;
+       this.node = node;
+}
+Timer.prototype.start = 
+       function(){_timerRun(this.name);}
+Timer.prototype.stop = 
+       function(){this.done = true;}
+function _timerRun(tname) {
+       var _t;
+       eval('_t='+tname);
+       if(_t.done) return;
+       var str = ' . ';
+       if( (_t.count % 5) == 0 ) 
+               str = _t.count / 5;
+       _t.node.appendChild(text(str));
+       setTimeout("_timerRun('"+tname+"');", 200);
+       _t.count++;
+}
 
 
 
index 9b50e17..bc3ea2f 100644 (file)
@@ -14,6 +14,9 @@ table { border-collapse: collapse; }
 .data_grid thead td { border-bottom: 1px solid #808080; }
 .data_grid tbody td { border: 1px solid #E0E0E0; padding: 5px; }
 
+.classic_link { text-decoration: underline; color: blue;}
+.classic_link:visited { text-decoration: underline; color: blue;}
+
 
 
 .encircled { border: 1px solid black; }
@@ -167,4 +170,4 @@ border-left: 1px solid #E0E0E0; border-top: 1px solid #E0E0E0; border-bottom: 1p
 .myopac_update_cell { border: 3px solid #E0E0E0; width:100%; padding-top: 4px; padding-bottom: 4px;}
 .myopac_update_span { padding: 5px;}
 
-
+#result_low_hits { border-top: 2px solid #A7EA9D; text-align: center; }
index af117ac..bb45b10 100644 (file)
@@ -3,6 +3,7 @@ var ranks = {};
 var onlyrecord = {};
 var table;
 var idsCookie = new cookieObject("ids", 1, "/", COOKIE_IDS);
+var searchTimer;
 
 attachEvt("common", "unload", mresultUnload);
 attachEvt("common", "run", mresultDoSearch);
@@ -14,8 +15,11 @@ function mresultUnload() { removeChildren(table); table = null;}
 
 function mresultDoSearch() {
 
-       if(getOffset() == 0)
-               setTimeout("swapCanvas($('loading_alt'))",100);
+       if(getOffset() == 0) {
+               swapCanvas($('loading_alt'));
+               searchTimer = new Timer('searchTimer',$('loading_alt_span'));
+               searchTimer.start();
+       }
 
        table = G.ui.result.main_table;
 
@@ -95,7 +99,7 @@ function mresultSetRecords(idstruct) {
 }
 
 function mresultCollectRecords() {
-       runEvt("result", "preCollectRecords");
+       if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
        var i = 0;
        for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
                if(isNull(records[x])) break;
index 96c5b3d..6132f65 100644 (file)
@@ -1,6 +1,7 @@
 
 var recordsHandled = 0;
 var recordsCache = [];
+var lowHitCount = 4;
 
 /* set up the event handlers */
 G.evt.result.hitCountReceived.push(resultSetHitInfo);
@@ -8,6 +9,9 @@ G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
 G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
 G.evt.result.allRecordsReceived.push(resultBuildCaches, resultDrawSubjects, resultDrawAuthors, resultDrawSeries);
 
+attachEvt('result','lowHits',resultLowHits);
+attachEvt('result','zeroHits',resultZeroHits);
+
 attachEvt( "common", "locationUpdated", resultSBSubmit );
 function resultSBSubmit(){searchBarSubmit();}
 
@@ -24,6 +28,13 @@ function resultFinalPageIndex() {
 /* set the search result info, number of hits, which results we're 
        displaying, links to the next/prev pages, etc. */
 function resultSetHitInfo() { 
+       if(getHitCount() <= lowHitCount)
+               runEvt('result', 'lowHits');
+       if(getHitCount() == 0) {
+               runEvt('result', 'zeroHits');
+               return;
+       }
+
        var c;  
        if( getDisplayCount() > (getHitCount() - getOffset()))  c = getHitCount();
        else c = getDisplayCount() + getOffset();
@@ -40,6 +51,134 @@ function resultSetHitInfo() {
        unHideMe(G.ui.result.info);
 }
 
+function resultLowHits() {
+       try{searchTimer.stop()}catch(e){}
+       showCanvas();
+       unHideMe($('result_low_hits'));
+       if(getHitCount() > 0)
+               unHideMe($('result_low_hits_msg'));
+
+       var sreq = new Request(CHECK_SPELL, getTerm());
+       sreq.callback(resultSuggestSpelling);
+       sreq.send();
+
+       var words = getTerm().split(' ');
+       var word;
+       while( word = words.shift() ) {
+               var areq = new Request(FETCH_CROSSREF, getStype(), getTerm() );
+               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'));
+       }
+}
+
+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(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() {
+       unHideMe($('result_zero_hits_msg'));
+       resultExpandSearch();
+       resultSuggestSearchClass();
+}
+
+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();
+       if(res) {
+               unHideMe($('did_you_mean'));
+               var arg = {};
+               arg[PARAM_TERM] = res;
+               $('spell_check_link').setAttribute(
+                       'href', buildOPACLink(arg) );
+               $('spell_check_link').appendChild(text(res));
+       }
+}
+
 
 function resultPaginate() {
        var o = getOffset();
@@ -69,14 +208,15 @@ function resultPaginate() {
        }
        if(getDisplayCount() < getHitCount())
                unHideMe($('start_end_links_span'));
+
+       showCanvas();
+       try{searchTimer.stop()}catch(e){}
 }
 
 
 /* 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) {
-       showCanvas();
-       try{killPinwheel();}catch(E){}
 
        if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
        recordsHandled++;
index 411c59e..2cc0292 100644 (file)
 
        <div id='loading_alt' class='hide_me non_canvas' style='margin-top: 6px;'>
                <div style='margin-top: 30px; text-align: left; font-weight: 700;' class='color_3'>
-                       <span > Loading </span>
-                       <span id='loading_alt_span'> </span>
-                       <script language='javascript'>
-                               var __id;
-                               var __count = 300;
-                               var __dot;
-                               var __idx = 0;
-                               var __slashes = [ '-', '\\\\', '|', '/' ];
-                               function __loading() { 
-                                       if( __count-- == 0 ) return;
-                                       __dot = __slashes[__idx++];
-                                       if(__idx == 4) __idx = 0;
-                                       __id = setTimeout(
-                                               "appendClear($('loading_alt_span'), text('"+__dot+"'));__loading();", 100);
-                               }
-                               __loading();
-                               function __killPinwheel(){ __count = 0; }
-                       </script>
+                       <span id='loading_alt_span'> Searching </span>
                </div>
        </div>
 
index ae2b1e2..a64b06c 100644 (file)
                                        </td>
                                        <td id='main_right_cell'>
                                                <div id='canvas' class='canvas'>
-                                               <xi:include href="searchbar.xml"/>
-                                               <xi:include href="statusbar.xml"/>
-                                               <xi:include href="altcanvas.xml"/>
-                                               <xi:include href="result_common.xml"/>
-                                       </div>
-                                       <br/>
-                                       <xi:include href="tips.xml"/>
+                                                       <xi:include href="searchbar.xml"/>
+                                                       <xi:include href="statusbar.xml"/>
+                                                       <xi:include href="altcanvas.xml"/>
+                                                       <xi:include href="result_common.xml"/>
+                                               </div>
+                                               <br/>
+                                               <xi:include href="tips.xml"/>
                                        </td>
                                </tr>
                        </tbody>
index b4cd625..e082d0c 100644 (file)
@@ -30,6 +30,8 @@
        </script>
 
        <xi:include href="result_table.xml"/>
+       <xi:include href='result_lowhits.xml'/>
+
 </div>