big pilostuff
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 12 May 2005 21:40:08 +0000 (21:40 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 12 May 2005 21:40:08 +0000 (21:40 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@713 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/javascript/opac/AbstractRecordResultPage.js
Open-ILS/src/javascript/opac/GlobalInit.js
Open-ILS/src/javascript/opac/MRResultPage.js
Open-ILS/src/javascript/opac/RecordResultPage.js
Open-ILS/src/javascript/util/RemoteRequest.js
Open-ILS/src/javascript/util/UserSession.js

index 372e9f1..10f517b 100644 (file)
@@ -34,13 +34,16 @@ AbstractRecordResultPage.prototype.init = function() {
        this.sidebarBox         = getById("record_sidebar_box");
 
 
-       this.hitsPerPage                = 8;     /* how many hits are displayed per page */
+       if(!this.hitsPerPage)
+               this.hitsPerPage                = 10;    /* how many hits are displayed per page */
+
        this.resetPage();
 
        this.statusBar                  = getById("top_status_bar_table");
        this.theadDrawn         = false;
        this.bigOlBox                   = getById("big_ol_box");
 
+
 }
 
 
@@ -62,11 +65,51 @@ AbstractRecordResultPage.prototype.resetPage = function() {
                spot2.appendChild(this.progressBar.percentDiv);
        this.received = 0;
 
+       RemoteRequest.cancelAll();
+
        this.requestBatch = new RequestBatch();
        this.finalized = false;
        this.builtLinks = false;
+
+       this.hitsPerPageSelector = getById('hits_per_page');
+
+       var obj = this;
+       this.hitsPerPageSelector.onchange = function() {
+
+               var hits;
+               var hits_obj = obj.hitsPerPageSelector.options[
+                       obj.hitsPerPageSelector.selectedIndex]; 
+
+               if(hits_obj == null)
+                       return;
+
+               hits = hits_obj.value
+
+               debug("Hits per page set to " + hits );
+
+               obj.hitsPerPage = parseInt(hits);       
+
+
+               var location = globalSelectedLocation;
+               if(location == null) location = globalLocation.id();
+
+               url_redirect(obj.URLRefresh());
+       }
+
+
+       for( var i in this.hitsPerPageSelector.options ) {
+
+               var hits_obj = obj.hitsPerPageSelector.options[i];
+               if(hits_obj == null) continue;
+               var hits = hits_obj.value;
+
+               if( this.hitsPerPage == parseInt(hits) ) 
+                       this.hitsPerPageSelector.options[i].selected = true;
+       }
+
 }
 
+
 AbstractRecordResultPage.prototype.resetSearch = function() {
        this.recordIDs                          = new Array();
        this.ranks                                      = new Array();
@@ -145,8 +188,29 @@ AbstractRecordResultPage.prototype.displayRecord =
        this.progressBar.manualNext();
 
        var id = parseInt(page_id);
-       var title_row = table_row_find_or_create(this.recordBox, id * 2 + 1 );
-       var author_row = table_row_find_or_create(this.recordBox, id * 2 + 2 );
+       var title_row = table_row_find_or_create(this.recordBox, id * 3 + 1 );
+       var author_row = table_row_find_or_create(this.recordBox, id * 3 + 2 );
+       var misc_row = table_row_find_or_create(this.recordBox, id * 3 + 3 );
+
+       add_css_class(misc_row, "record_misc_row");
+       add_css_class(title_row, "record_title_row");
+
+
+
+       var c = misc_row.insertCell(0);
+       /* shove in a div for each of the types of resource */
+       for( var i = 0; i!= 9; i++) {
+               var div = createAppElement("div");
+               div.innerHTML = "&nbsp;";
+               add_css_class(div, "record_resource_div");
+               c.appendChild(div);
+       }
+
+       c.className = "record_misc_cell";
+       var resources = record.types_of_resource();
+
+       for( var i in resources ) 
+               this.buildResourcePic( c, resources[i]);
 
        author_row.id = "record_result_author_row_" + id;
        title_row.id = "record_result_title_row_" + id;
@@ -162,29 +226,8 @@ AbstractRecordResultPage.prototype.displayRecord =
        /* ------------------------------------ */
 
 
-       var isbn = record.isbn();
-       if(isbn) isbn = isbn.replace(/\s+/,"");
-       else isbn = "";
-
        var pic_cell = title_row.insertCell(0);
-       pic_cell.setAttribute("rowspan","2");
-       pic_cell.rowSpan = 2;
-
-
-       var rankBox = "";
-       if( this.ranks.length > 0 ) {
-               var x = (parseInt(this.page) * parseInt(this.hitsPerPage)) + parseInt(page_id);
-               var per = parseInt(this.ranks[x] / this.ranks[0] * 100.0);
-               rankBox = "<div class='relevance_box'><div style='width:" + 
-                       per + "%' class='relevance'>&nbsp;</div></div>";
-       }
-                       
-
-       /* pull from amazon for now... */
-       pic_cell.innerHTML = rankBox + 
-               "<img height='50' width='45' src='http://images.amazon.com/images/P/" 
-               + isbn + ".01.MZZZZZZZ.jpg'>";
-
+       this.buildRecordImage( pic_cell, record, page_id );
 
        var title_cell = title_row.insertCell(title_row.cells.length);
        title_cell.id = "record_result_title_box_" + id;
@@ -196,27 +239,45 @@ AbstractRecordResultPage.prototype.displayRecord =
 
 
        /* limit the length of the title and author lines */
-       var tlength = 100;
+       var tlength = 80;
 
+       var title = "";
        if( record.title() ) {
                if(record.title().length > tlength) {
                        record.title(record.title().substr(0,tlength));
                        record.title(record.title() + "...");
                }
-               record.title(normalize(record.title()));
+               title = normalize(record.title());
        }
 
+       var author = "";
        if( record.author() ) {
                if(record.author().length > tlength) {
                        record.author( record.author().substr(0,tlength));
                        record.author(record.author() + "...");
                }
-               record.author(normalize(record.author()));
-       }       
+               author = normalize(record.author());
+       }
 
-       title_cell.appendChild(this.mkLink(record.doc_id(), "title", record.title()));
+       title_cell.appendChild(this.mkLink(record.doc_id(), "title", title ));
        author_cell.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
-       author_cell.appendChild(this.mkLink(record.doc_id(), "author", record.author()));
+       author_cell.appendChild(this.mkLink(record.doc_id(), "author", author ));
+
+       if(instanceOf(this, RecordResultPage)) {
+               var span = createAppElement("span");
+               span.style.marginLeft = "10px";
+
+               if(record.pubdate() || record.edition())
+                       span.appendChild(createAppTextNode(" -- "));
+
+               if(record.pubdate())
+                       span.appendChild(createAppTextNode(" " + record.pubdate()));
+
+               if(record.edition())
+                       span.appendChild(createAppTextNode(" " + record.edition()));
+
+                       author_cell.appendChild(span);
+       }
 
        var classname = "result_even";
        if((page_id%2) != 0) 
@@ -224,10 +285,11 @@ AbstractRecordResultPage.prototype.displayRecord =
 
        add_css_class(title_row, classname);
        add_css_class(author_row, classname);
+       add_css_class(misc_row, classname);
 
        /* now grab the record authors and subjects */
-       if( record.author() ) {
-               this.authorBox.addItem( this.mkAuthorLink(record.author()), record.author() );
+       if( author ) {
+               this.authorBox.addItem( this.mkAuthorLink(author) , author);
        }
 
        /* gather the subjects.  subjects are either a string or an array of
@@ -237,6 +299,11 @@ AbstractRecordResultPage.prototype.displayRecord =
        for( var sub in arr ) {
 
                var ss = arr[sub];
+
+               /* only taking first part of subject (non-topic, etc.) */
+               if( ss.constructor == Array)
+                       ss = ss[0];
+
                if( ss.constructor != Array )
                        ss = [ss];
 
@@ -378,8 +445,8 @@ AbstractRecordResultPage.prototype.displayCopyCounts =
                var cell = createAppElement("td");
                add_css_class(cell, "copy_count_cell");
                cell.innerHTML = copy_counts[i].available + " / " + copy_counts[i].count;
-               cell.setAttribute("rowspan","2");
-               cell.rowSpan = 2;
+               cell.setAttribute("rowspan","3");
+               cell.rowSpan = 3;
                titlerow.appendChild(cell);
        }
 
@@ -471,4 +538,139 @@ AbstractRecordResultPage.prototype.buildNextLinks = function() {
 }
 
 
+AbstractRecordResultPage.prototype.buildResourcePic = function(c, resource) {
+
+       var pic = createAppElement("img");
+       var big_pic_div = createAppElement("div");
+
+
+       pic.setAttribute("src", "/images/" + resource + ".jpg");
+       pic.className = "record_resource_pic";
+       pic.setAttribute("width", "20");
+       pic.setAttribute("height", "20");
+       pic.setAttribute("title", resource);
+
+
+       var index;
+
+       switch(resource) {
+
+               case "text":
+                       index = 0;
+                       break;
+
+               case "moving image":
+                       index = 1;
+                       break;
+
+               case "sound recording":
+                       index = 2;
+                       break;
+
+               case "software, multimedia":
+                       index = 3;
+                       break;
+
+               case "still images":
+                       index = 4;
+                       break;
+
+               case "cartographic":
+                       index = 5;
+                       break;
+
+               case "mixed material":
+                       index = 6;
+                       break;
+
+               case "notated music":
+                       index = 7;
+                       break;
+
+               case "three dimensional object":
+                       index = 8;
+                       break;
+
+               default:
+                       index = 0;
+       }
+
+       c.childNodes[index].innerHTML = "";
+       c.childNodes[index].appendChild(pic);
+}
+
+AbstractRecordResultPage.prototype.buildRecordImage = function(pic_cell, record, page_id) {
+
+       var isbn = record.isbn();
+       if(isbn) isbn = isbn.replace(/\s+/,"");
+       else isbn = "";
+
+       pic_cell.setAttribute("rowspan","3");
+       pic_cell.rowSpan = 3;
+
+       pic_cell.noWrap = 'nowrap';
+       pic_cell.setAttribute("nowrap", "nowrap");
+
+       pic_cell.width = "60";
+       pic_cell.className = "record_image_cell";
+
+
+       var rankBox;
+       if( this.ranks.length > 0 ) {
+               var x = (parseInt(this.page) * parseInt(this.hitsPerPage)) + parseInt(page_id);
+               var per = parseInt(this.ranks[x] / this.ranks[0] * 100.0);
+
+               debug("Per is " + per);
+               per = 100 - parseInt(per);
+
+               rankBox = createAppElement("div");
+               add_css_class(rankBox, "relevance_box");
+
+               var d = createAppElement("div");
+               d.setAttribute("height", per + "%");
+               d.style.height = per + "%";
+
+               add_css_class(d, "relevance");
+               rankBox.appendChild(d);
+
+               rankBox.setAttribute("title", (100 - parseInt(per)) + "% Relevant");
+       }
+
+       /* use amazon for now */
+       var img_src = "http://images.amazon.com/images/P/" +isbn + ".01.MZZZZZZZ.jpg";
+       var big_div = createAppElement("div");
+       add_css_class(big_div, "record_image_big hide_me");
+
+       var big_pic = createAppElement("img");
+       var pic = createAppElement("img");
+       
+       big_pic.setAttribute("src", img_src);
+       big_pic.setAttribute("border", "0");
+       pic.setAttribute("src", img_src);
+       add_css_class(big_pic, "record_image");
+       add_css_class(pic, "record_image");
+
+       pic.setAttribute("width", "45");
+       pic.setAttribute("height", "50");
+       pic.style.width = "45";
+       pic.style.height = "50";
+
+       if(IE) 
+               big_div.style.left = 0;
+
+
+       var anch = this.mkLink(record.doc_id(), "img" );
+       anch.appendChild(big_pic);
+       big_div.appendChild(anch);
+       pic_cell.appendChild(big_div);
+
+       pic_cell.appendChild(pic);
+
+       if(rankBox)
+               pic_cell.appendChild(rankBox);
+
+       pic.onmouseover = function() {showMe(big_div);}
+       big_div.onmouseout = function(){hideMe(big_div);}
+
+}
 
index 384be69..44e9406 100644 (file)
@@ -106,17 +106,22 @@ function GlobalInitLoad() {
        globalUser = UserSession.instance();
 
        var ses = null;
-       if(isXUL()) 
+       var org = null;
+
+       if(isXUL()) {
                ses = G['auth_ses'][0]; /* G is shoved in by XUL */
+               org = G['user_ou']; /* the desired location of the user */
+       }
 
        if(globalUser.verifySession(ses)) {
-               globalUser.grabOrgUnit();
+               globalUser.grabOrgUnit(org);
 
        } else  {
                globalUser = null;
                globalLocation = globalOrgTree;
                globalSearchDepth = findOrgDepth(globalOrgTree.ou_type());
        }
+
 }
 
 
index 7f80e23..606f89e 100644 (file)
@@ -83,6 +83,17 @@ MRResultPage.prototype.addMenuItems = function(menu, record) {
                        xulEvtMRResultDisplayed( menu, record );
 }
 
+MRResultPage.prototype.URLRefresh = function() {
+
+       return [ 
+                               "target",                                       "mr_result",
+                               "mr_search_type",                       this.stype,
+                               "mr_search_query",              this.string,
+                               "mr_search_location",   this.searchLocation,
+                               "mr_search_depth",              this.searchDepth,       
+                               "page",                                         0
+                               ];
+}
 
 MRResultPage.prototype.mkLink = function(id, type, value) {
 
@@ -93,15 +104,27 @@ MRResultPage.prototype.mkLink = function(id, type, value) {
                case "title":
                        href = createAppElement("a");
                        add_css_class(href,"record_result_title_link");
-                       href.setAttribute("href","?target=record_result&page=0&mrid=" + id );
+                       href.setAttribute("href",
+                               "?target=record_result&page=0&mrid=" + id + 
+                               "&hits_per_page=" + this.hitsPerPage);
                        href.appendChild(createAppTextNode(value));
                        break;
 
+       case "img":
+                       href = createAppElement("a");
+                       add_css_class(href,"record_result_title_link");
+                       href.setAttribute("href",
+                               "?target=record_result&page=0&mrid=" + id +
+                               "&hits_per_page=" + this.hitsPerPage);
+                       break;
+
+
                case "author":
                        href = createAppElement("a");
                        add_css_class(href,"record_result_author_link");
-                       href.setAttribute("href","?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
-                                             encodeURIComponent(value));
+                       href.setAttribute("href",
+                               "?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
+                            encodeURIComponent(value));
                        href.appendChild(createAppTextNode(value));
                        break;
 
@@ -124,6 +147,10 @@ MRResultPage.prototype.doSearch = function() {
        var stype                       = paramObj.__mr_search_type;
        var location            = paramObj.__mr_search_location;
        var depth                       = paramObj.__mr_search_depth;
+       var hitsper                     = paramObj.__hits_per_page;
+
+       if(hitsper)
+               this.hitsPerPage = parseInt(hitsper);
 
        debug("mr search params string " + string + " stype " + stype +
                        " location " + location + " depth " + depth );
@@ -250,6 +277,7 @@ MRResultPage.prototype.doMRSearch = function() {
        request.setCompleteCallback(
                function(req) {
                        var result = req.getResultObject();
+                       if(result == null) return;
                        result.count = obj.hitCount;
                        obj.gatherIDs(result) 
                        obj.collectRecords();
index 7e490ab..ba5a7c2 100644 (file)
@@ -36,6 +36,14 @@ RecordResultPage.prototype.next = function() {
 }
 
 
+
+RecordResultPage.prototype.URLRefresh = function() {
+       paramObj.__page = 0;
+       return build_param_array();
+}
+
+
+
 RecordResultPage.prototype.prev = function() {
        paramObj.__page = parseInt(paramObj.__page) - 1;
        var paramArray = build_param_array();
@@ -95,6 +103,12 @@ RecordResultPage.prototype.mkLink = function(id, type, value) {
                        href.appendChild(createAppTextNode(value));
                        break;
 
+       case "img":
+                       href = createAppElement("a");
+                       add_css_class(href,"record_result_image_link");
+                       href.setAttribute("href","?target=record_detail&page=0&mrid=" + id );
+                       break;
+
                default:
                        throw new EXArg("Unknown link type: " + type );
        }
@@ -128,6 +142,26 @@ RecordResultPage.prototype.doSearch = function() {
        debug( "Key Value Array \n" + js2JSON( paramObj ) );
 
        this.page                       = parseInt(paramObj.__page);
+       var hitsper                     = paramObj.__hits_per_page;
+
+       /*
+       if(hitsper)
+               this.hitsPerPage = parseInt(hitsper);
+
+       debug("******* Hits per = " + this.hitsPerPage);
+
+       this.hitsPerPageSelector = getById('hits_per_page');
+       for( var i in this.hitsPerPageSelector.options ) {
+               var hits_obj = this.hitsPerPageSelector.options[i];
+               if(hits_obj == null) continue;
+               var hits = hits_obj.value;
+               debug(hits);
+               if( this.hitsPerPage == parseInt(hits) ) {
+                       this.hitsPerPageSelector.options[i].selected = true;
+                       debug("Setting selected on selector with hits " + hits);
+               }
+       }
+       */
 
        if(this.page == null)
                this.page = 0;
index fa89366..b9a769b 100644 (file)
@@ -1,6 +1,5 @@
 
 var XML_HTTP_GATEWAY = "gateway";
-//var XML_HTTP_SERVER = "spacely.georgialibraries.org";
 var XML_HTTP_SERVER = "gapines.org";
 var XML_HTTP_MAX_TRIES = 3;
 
@@ -31,6 +30,15 @@ RemoteRequest.numPending = function() {
        return RemoteRequest.pending.length;
 }
 
+RemoteRequest.cancelAll = function() {
+       for( var x in RemoteRequest.pending ) {
+               if( RemoteRequest.pending[x] != null ) {
+                       debug("Cancelling request...");
+                       RemoteRequest.pending[x].cancelled = true;
+               }
+       }
+}
+
 
 /* ----------------------------------------------------------------------- */
 /* Generic request manager */
@@ -55,6 +63,14 @@ RequestBatch.prototype.pending = function() {
        return this.requests.length;
 }
 
+/* cancels all requests in this batch that have not already been sent */
+RequestBatch.prototype.cancel = function() {
+       for(var i in this.requests) {
+               if(this.requests[i] != null)
+                       this.requests.cancelled = true;
+       }
+}
+
 /* ----------------------------------------------------------------------- */
 /* Request object */
 function RemoteRequest( service, method ) {
@@ -67,6 +83,7 @@ function RemoteRequest( service, method ) {
 
        this.type               = "POST"; /* default */
        this.id                 = service + method + Math.random();
+       this.cancelled = false;
 
        var i = 2;
        this.params = ""; 
@@ -128,6 +145,7 @@ RemoteRequest.prototype.setCompleteCallback = function(callback) {
                if( obj.readyState == 4 ) {
 
                        try {
+                               if(object.cancelled) return;
                                callback(object);
                        } catch(E) {
 
@@ -176,6 +194,8 @@ RemoteRequest.prototype.setSecure = function(bool) {
   */
 RemoteRequest.prototype.send = function(blocking) {
 
+       if(this.cancelled) return;
+
        if( this.sendCount == 0)
                RemoteRequest.pending.push(this);
        else 
@@ -228,6 +248,8 @@ RemoteRequest.prototype.isReady = function() {
 
 /* returns the JSON->js result object  */
 RemoteRequest.prototype.getResultObject = function() {
+       if(this.cancelled) return null;
+
        var text = this.xmlhttp.responseText;
        var obj = JSON2js(text);
 
index 0fb7faa..355f152 100644 (file)
@@ -132,7 +132,9 @@ UserSession.prototype.login = function( username, password ) {
 
 
 /* grab this users org unit */
-UserSession.prototype.grabOrgUnit = function() {
+/* if new_org_id is provided, it is used instead of the home_ou 
+       of the user */
+UserSession.prototype.grabOrgUnit = function(org) {
        var session = this.getSessionId();
        if(!session) {
                throw new EXLogic(
@@ -148,8 +150,11 @@ UserSession.prototype.grabOrgUnit = function() {
        request.send(true);
        this.userObject = request.getResultObject();
        
-       this.orgUnit = findOrgUnit(this.userObject.home_ou());
-       globalSearchDepth = findOrgDepth(this.orgUnit.ou_type());
+       if(org) 
+               this.orgUnit = org;
+       else    
+               this.orgUnit = findOrgUnit(this.userObject.home_ou());
+
        globalSelectedDepth = findOrgDepth(this.orgUnit.ou_type());
        globalPage.updateSelectedLocation(this.orgUnit);
        globalPage.updateCurrentLocation(this.orgUnit);