Removed quoted var.
[pazpar2-moved-to-github.git] / js / pz2.js
index 97e6956..925c2c1 100644 (file)
--- a/js/pz2.js
+++ b/js/pz2.js
@@ -1,5 +1,5 @@
 /*
-** $Id: pz2.js,v 1.62 2007-10-02 12:09:40 jakub Exp $
+** $Id: pz2.js,v 1.67 2007-11-13 13:07:28 jakub Exp $
 ** pz2.js - pazpar2's javascript client library.
 */
 
@@ -50,6 +50,7 @@ var pz2 = function ( paramArray )
     this.errorHandler = paramArray.errorhandler || null;
     
     // function callbacks
+    this.initCallback = paramArray.oninit || null;
     this.statCallback = paramArray.onstat || null;
     this.showCallback = paramArray.onshow || null;
     this.termlistCallback = paramArray.onterm || null;
@@ -191,6 +192,8 @@ pz2.prototype =
                             },
                             context.keepAlive
                         );
+                        if ( context.initCallback )
+                            context.initCallback();
                     }
                     else
                         context.throwError('Init failed. Malformed WS resonse.',
@@ -417,18 +420,19 @@ pz2.prototype =
                     for (i = 0; i < hits.length; i++) {
                         show.hits[i] = new Array();
                        show.hits[i]['location'] = new Array();
+                       var locCount = 0;
                         for ( j = 0; j < hits[i].childNodes.length; j++) {
-                           var locCount = 0;
                             if ( hits[i].childNodes[j].nodeType 
                                 == Node.ELEMENT_NODE ) {
                                if (hits[i].childNodes[j].nodeName 
                                     == 'location') {
                                    var locNode = hits[i].childNodes[j];
                                    var id = locNode.getAttribute('id');
-                                   show.hits[i]['location'][id] = {
+                                   show.hits[i]['location'][locCount] = {
                                        "id": locNode.getAttribute("id"),
                                        "name": locNode.getAttribute("name")
                                    };
+                                    locCount++;
                                }
                                else {
                                    var nodeName = 
@@ -530,8 +534,9 @@ pz2.prototype =
                                 != 'location' ) {
                                 var nodeName = 
                                     recordNode.childNodes[i].nodeName;
-                                var nodeText = 
-                                    recordNode.childNodes[i]
+                                var nodeText = '';
+                                if (recordNode.childNodes[i].firstChild)
+                                    nodeText = recordNode.childNodes[i]
                                         .firstChild.nodeValue;
                                 record[nodeName] = nodeText;                            
                             }
@@ -559,7 +564,21 @@ pz2.prototype =
                                         nodeText = 
                                             locationNodes[i].childNodes[j]
                                                 .firstChild.nodeValue;
-                                    record["location"][i][nodeName] = nodeText;                            
+                                    // this is stupid
+                                    if (nodeName == 'md-subject') {
+                                        if (record["location"][i][nodeName]) {
+                                            record["location"][i][nodeName]
+                                                .push(nodeText)
+                                        } else {
+                                            record["location"][i][nodeName] 
+                                                = new Array();
+                                            record["location"][i][nodeName]
+                                                .push(nodeText)
+                                        }
+                                    } else {
+                                        record["location"][i][nodeName] 
+                                            = nodeText;
+                                    }
                                 }
                             }
                         }