Removing bug in the record method.
[pazpar2-moved-to-github.git] / js / pz2.js
index cf34cb7..4d7f784 100644 (file)
--- a/js/pz2.js
+++ b/js/pz2.js
@@ -1,5 +1,5 @@
 /*
-** $Id: pz2.js,v 1.63 2007-10-30 13:41:05 jakub Exp $
+** $Id: pz2.js,v 1.68 2007-12-20 13:09:40 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.',
@@ -463,23 +466,25 @@ pz2.prototype =
             }
         );
     },
-    record: function(id, offset, params)
+    record: function(id, offset, pass_params)
     {
         // we may call record with no previous search if in proxy mode
         if( !this.searchStatusOK && this.useSessions)
            throw new Error(
             'Pz2.js: record command has to be preceded with a search command.'
-            ); 
-        if ( params == undefined )
-            params = {};
+            );
+        var params = {};
+        if ( pass_params != undefined )
+            params = pass_params;
 
+        var callback;
         if ( params.callback != undefined ) {
             callback = params.callback;
         } else {
             callback = this.recordCallback;
         }
         
-        // what is that?
+        var handle;
         if ( params['handle'] == undefined )
             handle = {};
         else
@@ -531,8 +536,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;                            
                             }
@@ -560,7 +566,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;
+                                    }
                                 }
                             }
                         }