Further pz2.js updates.
authorJakub Skoczen <jakub@indexdata.dk>
Fri, 9 Mar 2007 14:01:49 +0000 (14:01 +0000)
committerJakub Skoczen <jakub@indexdata.dk>
Fri, 9 Mar 2007 14:01:49 +0000 (14:01 +0000)
www/pz2_js/client_pz2.js
www/pz2_js/index.html
www/pz2_js/pz2.js

index 1ba9389..aaa5bab 100644 (file)
@@ -1,12 +1,25 @@
-function init() {
-    my_paz = new pz2( { "onshow": my_onshow,
-                        "onstat": my_onstat,
-                        "onterm": my_onterm,
-                        "termlist": "subject,author",
-                        "onbytarget": my_onbytarget,
-                        "onrecord": my_onrecord } );
-}
+// very simple client that shows a basic usage of the pz2.js
+
+// create a parameters array and pass it to the pz2's constructor
+// then register the form submit event with the pz2.search function
+
+my_paz = new pz2( { "onshow": my_onshow,
+                    "onstat": my_onstat,
+                    "onterm": my_onterm,
+                    "termlist": "subject,author",
+                    "onbytarget": my_onbytarget,
+                    "onrecord": my_onrecord } );
 
+// wait until the DOM is rady (could have been defined in the HTML)
+$(document).ready( function() { document.search.onsubmit = onFormSubmitEventHandler; } );
+
+function onFormSubmitEventHandler() {
+    my_paz.search(document.search.query.value, 15, 'relevance');
+    return false;
+}
+//
+// pz2.js event handlers:
+//
 function my_onshow(data) {
     var body = document.getElementById("body");
     body.innerHTML = "";
@@ -48,11 +61,13 @@ function my_onterm(data) {
 }
 
 function my_onrecord(data) {
+    details = data;
     recordDiv = document.getElementById(data.recid);
     recordDiv.innerHTML = "<table><tr><td><b>Ttle</b> : </td><td>" + data["md-title"] +
                             "</td></tr><tr><td><b>Date</b> : </td><td>" + data["md-date"] +
                             "</td></tr><tr><td><b>Author</b> : </td><td>" + data["md-author"] +
-                            "</td></tr><tr><td><b>Subject</b> : </td><td>" + data["md-subject"] + "</td></tr></table>";
+                            "</td></tr><tr><td><b>Subject</b> : </td><td>" + data["md-subject"] + 
+                            "</td></tr><tr><td><b>Location</b> : </td><td>" + data["location"][0].name + "</td></tr></table>";
 
 }
 
index 46108c8..5f90366 100644 (file)
@@ -1,16 +1,16 @@
 <html>
  <head>
   <style type="text/css"></style>
+  <script type="text/javascript" src="jquery.js"></script>
   <script type="text/javascript" src="pz2.js"></script>
   <script type="text/javascript" src="client_pz2.js"></script>
-  <script type="text/javascript" src="jquery.js"></script>
  </head>
-<body onload="init();">
+<body>
  <table width="100%" border="0" cellpadding="2" cellspacing="2">
   <tr>
    <td width="250" height="100" align="center"><b>pz2.js test</b></td>
    <td>
-    <form name="search" onsubmit="my_paz.search(this.query.value, 15, 'title'); return false;">
+    <form id="searchForm" name="search">
      <b>Search:</b>
      <input id="query" type="text" size="50"/>
      <input type="submit" value="Go"/>
index e8924b0..5725858 100644 (file)
@@ -254,7 +254,23 @@ pz2.prototype = {
                         if ( recordNode.childNodes[i].nodeType == Node.ELEMENT_NODE ) {
                             var nodeName = recordNode.childNodes[i].nodeName;
                             var nodeText = recordNode.childNodes[i].firstChild.nodeValue;
-                            record[nodeName] = nodeText;
+                            record[nodeName] = nodeText;                            
+                        }
+                    }
+                    // the location is hard coded
+                    var locationNodes = recordNode.getElementsByTagName("location");
+                    record["location"] = new Array();
+                    for ( i = 0; i < locationNodes.length; i++ ) {
+                        record["location"][i] = {
+                            "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 = locationNodes[i].childNodes[j].firstChild.nodeValue;
+                                record["location"][i][nodeName] = nodeText;                            
+                            }
                         }
                     }
                     __myself.recordCallback(record);