moving class searches over to new search method
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 27 Feb 2006 23:39:48 +0000 (23:39 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 27 Feb 2006 23:39:48 +0000 (23:39 +0000)
added sorting and sort direction params
added some basic sorting options to advanced page

git-svn-id: svn://svn.open-ils.org/ILS/trunk@3218 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/js/advanced.js
Open-ILS/web/opac/skin/default/js/mresult.js
Open-ILS/web/opac/skin/default/js/rresult.js
Open-ILS/web/opac/skin/default/xml/advanced/advanced_wizard.xml
Open-ILS/web/opac/skin/default/xml/common/js_common.xml

index aaf052e..c0087ea 100644 (file)
@@ -16,6 +16,9 @@ var PARAM_TOPRANK             = "tr";                 /* this highest ranking rank */
 var PARAM_AUTHTIME     = "at";                 /* inactivity timeout in seconds */
 var PARAM_ADVTERM              = "adv";                        /* advanced search term */
 var PARAM_ADVTYPE              = "adt";                        /* the advanced search type */
+var PARAM_RTYPE                = "rt";
+var PARAM_SORT                 = "s";
+var PARAM_SORT_DIR     = "sd";
 
 /* URL param values (see comments above) */
 var TERM;  
@@ -35,6 +38,9 @@ var ADVTERM;
 var ADVTYPE;
 var MRID;
 var RID;
+var RTYPE;
+var SORT;
+var SORT_DIR;
 
 /* cookie values */
 var SBEXTRAS; 
@@ -44,11 +50,10 @@ var SKIN;
 /* cookies */
 var COOKIE_SB = "sbe";
 var COOKIE_SES = "ses";
-var COOKIE_IDS = "ids";
+var COOKIE_IDS = "ids"; /* list of mrecord ids */
 var COOKIE_FONT = "fnt";
 var COOKIE_SKIN = "skin";
-
-/* these are the actual param values - set on page load */
+var COOKIE_RIDS = "rids"; /* list of record ids */
 
 /* pages */
 var MRESULT            = "mresult";
@@ -58,6 +63,7 @@ var MYOPAC            = "myopac";
 var ADVANCED   = "advanced";
 var HOME                       = "home";
 var BBAGS              = "bbags";
+var REQITEMS   = "reqitems";
 
 /* search type (STYPE) options */
 var STYPE_AUTHOR       = "author";
@@ -66,6 +72,21 @@ var STYPE_SUBJECT    = "subject";
 var STYPE_SERIES       = "series";
 var STYPE_KEYWORD      = "keyword";
 
+/* record-level search types */
+var RTYPE_MRID         = "mrid";
+var RTYPE_COOKIE       = "cookie";
+var RTYPE_AUTHOR       = STYPE_AUTHOR;
+var RTYPE_SUBJECT      = STYPE_SUBJECT;
+var RTYPE_TITLE        = STYPE_TITLE;
+var RTYPE_SERIES       = STYPE_SERIES;
+var RTYPE_KEYWORD      = STYPE_KEYWORD;
+
+var SORT_TYPE_AUTHOR           = STYPE_AUTHOR; 
+var SORT_TYPE_TITLE            = STYPE_TITLE;
+var SORT_TYPE_PUBDATE  = "pubdate";
+var SORT_DIR_ASC                       = "asc";
+var SORT_DIR_DESC                      = "desc";
+
 /* types of advanced search */
 var ADVTYPE_MULTI = 'ml';
 var ADVTYPE_MARC       = 'ma';
@@ -128,6 +149,7 @@ config.page[RRESULT]                = "rresult.xml";
 config.page[MYOPAC]            = "myopac.xml";
 config.page[RDETAIL]           = "rdetail.xml";
 config.page[BBAGS]             = "bbags.xml";
+config.page[REQITEMS]  = "reqitems.xml";
 
 /* themes */
 config.themes = {};
@@ -193,7 +215,7 @@ config.ids.altcanvas = {};
        have a staff counterpart and should have ".staff" appended to the method 
        before the method is called when in XUL mode */
 
-var FETCH_MRCOUNT                                      = "open-ils.search:open-ils.search.biblio.class.count:1";
+var FETCH_MRIDS_                                       = "open-ils.search:open-ils.search.biblio.metabib.class.search:1";
 var FETCH_MRIDS                                        = "open-ils.search:open-ils.search.biblio.class:1";
 var FETCH_MRIDS_FULL                           = "open-ils.search:open-ils.search.biblio.class.full:1";
 var FETCH_MRMODS                                       = "open-ils.search:open-ils.search.biblio.metarecord.mods_slim.retrieve";
index 142cdbf..caa95db 100644 (file)
@@ -15,7 +15,7 @@ function Request(type) {
                this.request.addParam(arguments[x]);
 }
 
-Request.prototype.callback = function(cal) { this.request.setCompleteCallback(cal); }
+Request.prototype.callback = function(cal) {this.request.setCompleteCallback(cal);}
 Request.prototype.send         = function(block){this.request.send(block);}
 Request.prototype.result       = function(){return this.request.getResultObject();}
 
@@ -70,10 +70,9 @@ function findCurrentPage() {
 function initParams() {
        var cgi = new CGI();    
 
-       TERM    = cgi.param(PARAM_TERM);
-       STYPE   = cgi.param(PARAM_STYPE);
-       FORM    = cgi.param(PARAM_FORM);
-
+       TERM            = cgi.param(PARAM_TERM);
+       STYPE           = cgi.param(PARAM_STYPE);
+       FORM            = cgi.param(PARAM_FORM);
        LOCATION        = parseInt(cgi.param(PARAM_LOCATION));
        ORIGLOC = parseInt(cgi.param(PARAM_ORIGLOC));
        DEPTH           = parseInt(cgi.param(PARAM_DEPTH));
@@ -86,6 +85,9 @@ function initParams() {
        AUTHTIME        = parseInt(cgi.param(PARAM_AUTHTIME));
        ADVTERM = cgi.param(PARAM_ADVTERM);
        ADVTYPE = cgi.param(PARAM_ADVTYPE);
+       RTYPE           = cgi.param(PARAM_RTYPE);
+       SORT            = cgi.param(PARAM_SORT);
+       SORT_DIR        = cgi.param(PARAM_SORT_DIR);
 
        /* set up some sane defaults */
        if(isNaN(LOCATION))     LOCATION        = 1;
@@ -127,6 +129,9 @@ function getFontSize(){return FONTSIZE;};
 function getSkin(){return SKIN;};
 function getAdvTerm(){return ADVTERM;}
 function getAdvType(){return ADVTYPE;}
+function getRtype(){return RTYPE;}
+function getSort(){return SORT;}
+function getSortDir(){return SORT_DIR;}
 
 
 function findBasePath() {
@@ -190,6 +195,9 @@ function  buildOPACLink(args, slim, ssl) {
        string += _appendParam(AUTHTIME,        PARAM_AUTHTIME, args, getAuthtime, string);
        string += _appendParam(ADVTERM, PARAM_ADVTERM, args, getAdvTerm, string);
        string += _appendParam(ADVTYPE, PARAM_ADVTYPE, args, getAdvType, string);
+       string += _appendParam(RTYPE,           PARAM_RTYPE, args, getRtype, string);
+       string += _appendParam(SORT,            PARAM_SORT, args, getSort, string);
+       string += _appendParam(SORT_DIR,        PARAM_SORT_DIR, args, getSortDir, string);
 
        return string.replace(/\&$/,'').replace(/\?\&/,"?");    
 }
@@ -220,6 +228,7 @@ function buildTitleLink(rec, link) {
        args.page = RRESULT;
        args[PARAM_OFFSET] = 0;
        args[PARAM_MRID] = rec.doc_id();
+       args[PARAM_RTYPE] = RTYPE_MRID;
        link.setAttribute("href", buildOPACLink(args));
 }
 
index 1675855..8428a14 100644 (file)
@@ -37,18 +37,22 @@ function advInit() {
 function advWizardRun() {
        var contains = $('advanced.wizard.contains').value;
        var nocontains = $('advanced.wizard.nocontains').value; 
-       var exact = $('advanced.wizard.exact').value; 
-       var form = getSelectorVal($('advanced.wizard.form_selector'));
-       var type = getSelectorVal($('search_type_selector'));
+       var exact       = $('advanced.wizard.exact').value; 
+       var form                = getSelectorVal($('advanced.wizard.form_selector'));
+       var type                = getSelectorVal($('search_type_selector'));
+       var sort                = getSelectorVal($('advanced.wizard.sort_by'));
+       var sortdir     = getSelectorVal($('advanced.wizard.sort_dir'));
 
        var arg = {};
        arg.page = MRESULT;
-       arg[PARAM_FORM] = form;
-       arg[PARAM_STYPE] = type;
-       arg[PARAM_OFFSET] = 0;
-       arg[PARAM_DEPTH]        = depthSelGetDepth();
+       arg[PARAM_FORM]         = form;
+       arg[PARAM_STYPE]                = type;
+       arg[PARAM_OFFSET]               = 0;
+       arg[PARAM_DEPTH]                = depthSelGetDepth();
        arg[PARAM_LOCATION]     = depthSelGetNewLoc();
-       arg[PARAM_TERM] = advBuildSearch( contains, nocontains, exact );
+       arg[PARAM_TERM]         = advBuildSearch( contains, nocontains, exact );
+       arg[PARAM_SORT]         = (sort.match(/relevance/i)) ? null : sort;
+       arg[PARAM_SORT_DIR]     = sortdir;
 
        goTo(buildOPACLink(arg));
 }
index 0635e14..4d62060 100644 (file)
@@ -23,17 +23,19 @@ function mresultDoSearch() {
 
        table = G.ui.result.main_table;
 
-       while( table.parentNode.rows.length <= (getDisplayCount() + 1) )  /* add an extra row so IE and safari won't complain */
+       /* add an extra row so IE and safari won't complain */
+       while( table.parentNode.rows.length <= (getDisplayCount() + 1) )  
                table.appendChild(G.ui.result.row_template.cloneNode(true));
 
+       /*
        if(getOffset() == 0 || getHitCount() == null ) {
                if( getAdvTerm() && !getTerm() ) {
                        if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
                        if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvMARCIds();
                        if(getAdvType() == ADVTYPE_ISBN ) mresultCollectAdvISBNIds();
                        if(getAdvType() == ADVTYPE_ISSN ) mresultCollectAdvISSNIds();
-               }
-               else {
+
+               else {
                        mresultCollectIds(FETCH_MRIDS_FULL); 
                        ADVTERM = "";
                        ADVTYPE = "";
@@ -43,32 +45,28 @@ function mresultDoSearch() {
                if( getAdvTerm() && !getTerm() ) {
                        if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
                        if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvIds();
-               }
-               else {
+
+               else {
                        mresultCollectIds(FETCH_MRIDS);
                        ADVTERM = "";
                        ADVTYPE = "";
                }
        }
+       */
+
+       if( getAdvTerm() && !getTerm() ) {
+               if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
+               if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvMARCIds();
+               if(getAdvType() == ADVTYPE_ISBN ) mresultCollectAdvISBNIds();
+               if(getAdvType() == ADVTYPE_ISSN ) mresultCollectAdvISSNIds();
+
+       } else {
+               _mresultCollectIds(); 
+               ADVTERM = "";
+               ADVTYPE = "";
+       }
 }
 
-/*
-function mresultGetCount() {
-       var form = (getForm() == "all") ? null : getForm();
-       var req = new Request(FETCH_MRCOUNT, 
-                       getStype(), getTerm(), getLocation(), getDepth(), form );
-       req.callback(mresultHandleCount);
-       req.send();
-}
-
-function mresultHandleCount(r) {
-       HITCOUNT = parseInt(r.getResultObject());
-       alert('mresultHandleCount()');
-       runEvt('result', 'hitCountReceived');
-}
-*/
-
-
 function mresultLoadCachedSearch() {
        if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
                var c = JSON2js(cookieManager.read(COOKIE_IDS));
@@ -80,7 +78,6 @@ function mresultTryCachedSearch() {
        mresultLoadCachedSearch();
        if(     getOffset() != 0 && records[getOffset()] != null && 
                        records[resultFinalPageIndex()] != null) {
-
                runEvt('result', 'hitCountReceived');
                mresultCollectRecords(); 
                return true;
@@ -90,6 +87,7 @@ function mresultTryCachedSearch() {
 
 
 /* performs the actual search */
+/*
 function mresultCollectIds(method) {
        if(!mresultTryCachedSearch()) {
                var form = (getForm() == "all") ? null : getForm();
@@ -99,6 +97,24 @@ function mresultCollectIds(method) {
                req.send();
        }
 }
+*/
+
+function _mresultCollectIds() {
+       if( getOffset() == 0 || !mresultTryCachedSearch() ) {
+               var form = (getForm() == "all") ? null : getForm();
+               var req = new Request(FETCH_MRIDS_, getStype(), 
+                       {       term            : getTerm(), 
+                               sort            : getSort(), 
+                               sort_dir        : getSortDir(),
+                               org_unit : getLocation(),
+                               depth           : getDepth(),
+                               limit           : mresultPreCache,
+                               offset  : getOffset(),
+                               format  : (getForm()=="all") ? null : getForm() } );
+               req.callback(mresultHandleMRIds);
+               req.send();
+       }
+}
 
 
 function mresultCollectAdvIds() {
index 2b14daa..5856c27 100644 (file)
@@ -18,17 +18,31 @@ function rresultDoSearch() {
 }
 
 function rresultCollectIds() {
-       var form = (getForm() == "all") ? null : getForm();
-       var req = new Request(FETCH_RIDS, getMrid(), form );
-       req.callback( rresultHandleRIds );
-       req.send();
+       var ids;
+       switch(getRtype()) {
+               case RTYPE_COOKIE:
+                       ids = JSON2js(cookieManager.read(COOKIE_RIDS));
+                       _rresultHandleIds( ids, ids.length );
+                       break;
+
+               case RTYPE_MRID :
+               defaut:
+                       var form = (getForm() == "all") ? null : getForm();
+                       var req = new Request(FETCH_RIDS, getMrid(), form );
+                       req.callback( rresultHandleRIds );
+                       req.send();
+       }
 }
 
 function rresultHandleRIds(r) {
        var res = r.getResultObject();
-       HITCOUNT = parseInt(res.count);
+       _rresultHandleIds(res.ids, res.count);
+}
+
+function _rresultHandleIds(ids, count) {
+       HITCOUNT = parseInt(count);
        runEvt('result', 'hitCountReceived');
-       runEvt('result', 'idsReceived', res.ids);
+       runEvt('result', 'idsReceived', ids);
 }
 
 function rresultCollectRecords(ids) {
index b5d6a04..6424d89 100644 (file)
@@ -1,4 +1,4 @@
-<table class='data_grid' width='80%'>
+<table class='data_grid data_grid_center' width='80%'>
        <thead>
                <tr><td colspan='2'>&opac.advanced.wizard.title;</td></tr>
        </thead>
                        </td>
                </tr>
                <tr>
+                       <td>
+                               <span>Sort results by </span>
+                               <select id='advanced.wizard.sort_by' 
+                                       onchange='
+                                       if(this.selectedIndex == 0) 
+                                               $("advanced.wizard.sort_dir").disabled = true;
+                                       else $("advanced.wizard.sort_dir").disabled = false;'>
+                                       <option value=''>Relevance</option>
+                                       <option value='title'>Title</option>
+                                       <option value='author'>Author</option>
+                                       <!--
+                                       <option value='pubdate'>Publication Date</option>
+                                       -->
+                               </select>
+                       </td>
+                       <td>
+                               <span>Sort Direction </span>
+                               <select id='advanced.wizard.sort_dir' disabled='disabled'>
+                                       <option value='asc'>Normal</option>
+                                       <option value='desc'>Reverse</option>
+                               </select>
+                       </td>
+               </tr>
+               <tr>
                        <td colspan='2' align='center'>
                                <input type='submit' onclick='advWizardRun();' value='&common.submit;'> </input>
                        </td>
index 832a23d..fe8eb1b 100644 (file)
@@ -4,7 +4,9 @@
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/utils.js'> </script>
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/config.js'> </script>
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/CGI.js'> </script>
+       <!--
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/Cookie.js'> </script>
+       -->
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/Cookies.js'> </script>
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/md5.js'> </script>