Handling situation when the location node is empty.
[pazpar2-moved-to-github.git] / js / pz2.js
index 062e124..723b176 100644 (file)
--- a/js/pz2.js
+++ b/js/pz2.js
@@ -1,5 +1,5 @@
 /*
-** $Id: pz2.js,v 1.14 2007-05-16 07:53:32 jakub Exp $
+** $Id: pz2.js,v 1.17 2007-05-18 12:38:48 jakub Exp $
 ** pz2.js - pazpar2's javascript client library.
 */
 
@@ -313,7 +313,8 @@ pz2.prototype = {
                     __myself.showCounter++;
                    var delay = __myself.showTime;
                    if (__myself.showCounter > __myself.showFastCount)
-                           delay *= 2;
+                           //delay *= 2;
+                            delay += __myself.showCounter * __myself.dumpFactor;
                     if (activeClients > 0)
                         __myself.showTimer = setTimeout("__myself.show()", delay);
                 }
@@ -344,13 +345,14 @@ pz2.prototype = {
                         record['xslDoc'] = __myself.xslDoc;
                     } else {
                         for ( i = 0; i < recordNode.childNodes.length; i++) {
-                            if ( recordNode.childNodes[i].nodeType == Node.ELEMENT_NODE ) {
+                            if ( recordNode.childNodes[i].nodeType == Node.ELEMENT_NODE
+                                    && recordNode.childNodes[i].nodeName != 'location' ) {
                                 var nodeName = recordNode.childNodes[i].nodeName;
                                 var nodeText = recordNode.childNodes[i].firstChild.nodeValue;
                                 record[nodeName] = nodeText;                            
                             }
                         }
-                        // the location is hard coded
+                        // the location might be empty!!
                         var locationNodes = recordNode.getElementsByTagName("location");
                         record["location"] = new Array();
                         for ( i = 0; i < locationNodes.length; i++ ) {
@@ -358,14 +360,13 @@ pz2.prototype = {
                                 "id": locationNodes[i].getAttribute("id"),
                                 "name": locationNodes[i].getAttribute("name")
                             };
+                            
                             for ( j = 0; j < locationNodes[i].childNodes.length; j++) {
                                 if ( locationNodes[i].childNodes[j].nodeType == Node.ELEMENT_NODE ) {
                                     var nodeName = locationNodes[i].childNodes[j].nodeName;
-                                    var nodeText;
+                                    var nodeText = '';
                                     if (locationNodes[i].childNodes[j].firstChild)
                                             nodeText = locationNodes[i].childNodes[j].firstChild.nodeValue;
-                                    else
-                                            nodeText = '';
                                     record["location"][i][nodeName] = nodeText;                            
                                 }
                             }
@@ -508,17 +509,22 @@ pzHttpRequest.prototype =
     {
         this.callback = callback;
         
+        var getUrl = this.url;
         var paramArr = new Array();
+
         for ( var key in params ) {
             paramArr.push(key + '=' + escape(params[key]));
         }
 
+        if ( paramArr.length )
+            getUrl += '?' + paramArr.join('&');
+
         var context = this;
-        this.request.open( 'GET', this.url+'?'+paramArr.join('&'), true );
+        this.request.open( 'GET', getUrl, true );
         this.request.onreadystatechange = function () {
             context._handleResponse();
         }
-        this.request.send();
+        this.request.send(null);
     },
 
     _handleResponse: function ()