Target facet
[pazpar2-moved-to-github.git] / www / demo / search.js
index c60dcc4..517f597 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: search.js,v 1.30 2007-01-16 19:21:05 quinn Exp $
+/* $Id: search.js,v 1.36 2007-01-17 14:21:29 quinn Exp $
  * ---------------------------------------------------
  * Javascript container
  */
@@ -222,10 +222,24 @@ function displayname(name)
        return 'ISBN';
     else if (name == 'md-publisher')
        return 'Publisher';
+    else if (name == 'md-url')
+       return 'URL';
     else
        return name;
 }
 
+function hyperlink_field(name)
+{
+    if (name == 'md-author')
+       return 'au';
+    else if (name == 'md-subject')
+       return 'su';
+    else if (name == 'md-url')
+       return 'URL';
+    else
+       return 0;
+}
+
 function  paint_details_tr(name, dn)
 {
     //emit a table row
@@ -233,6 +247,7 @@ function  paint_details_tr(name, dn)
     var ln = create_element('b', dname);
     var tln = document.createElement('td');
     tln.setAttribute('width', 70);
+    tln.setAttribute('valign', 'top');
     tln.appendChild(ln);
     var tr = document.createElement('tr');
     tr.appendChild(tln);
@@ -242,6 +257,7 @@ function  paint_details_tr(name, dn)
 
 function paint_details(body, xml)
 {
+    // This is some ugly display code. Replace with your own ting o'beauty
     clear_cell(body);
     //body.appendChild(document.createElement('br'));
     var nodes = xml.childNodes[0].childNodes;
@@ -272,8 +288,27 @@ function paint_details(body, xml)
                continue;
        var value = nodes[i].childNodes[0].nodeValue;
        if (dn.childNodes[0])
-           value = '; ' + value;
-       var nv = document.createTextNode(value);
+           dn.appendChild(document.createTextNode('; '));
+       var hyl = hyperlink_field(name);
+       var nv;
+       if (hyl)
+       {
+           nv = create_element('a', value);
+           if (hyl == 'URL')
+           {
+               nv.setAttribute('href', value);
+               nv.setAttribute('target', '_blank');
+           }
+           else
+           {
+               nv.setAttribute('href', '#');
+               nv.setAttribute('term', value);
+               nv.setAttribute('searchfield', hyl);
+               nv.onclick = function() { hyperlink_search(this); return false; };
+           }
+       }
+       else
+           nv = document.createTextNode(value);
        dn.appendChild(nv);
     }
     if (dn)
@@ -299,8 +334,6 @@ function show_details()
        return;
     }
 
-    // This is some ugly display code. Replace with your own ting o'beauty
-
     var idn = xml.getElementsByTagName('recid');
     if (!idn[0])
        return;
@@ -308,14 +341,24 @@ function show_details()
     cur_id = id;
     cur_rec = xml;
 
+    var nodes = document.getElementsByName('listrecord');
+    var i;
+    for (i = 0; i < nodes.length; i++)
+    {
+       var dets = nodes[i].getElementsByTagName('div');
+       if (dets[0])
+           dets[0].style.display = 'none';
+    }
+
     var body = document.getElementById('rec_' + id);
     if (!body)
        return;
     paint_details(body, xml);
 }
 
-function hyperlink_search(field, obj)
+function hyperlink_search(obj)
 {
+    var field = obj.getAttribute('searchfield');
     var term = obj.getAttribute('term');
     var queryfield  = document.getElementById('query');
     queryfield.value = field + '=' + term;
@@ -325,14 +368,6 @@ function hyperlink_search(field, obj)
 function fetch_details(id)
 {
     cur_id = -1;
-    var nodes = document.getElementsByName('listrecord');
-    var i;
-    for (i = 0; i < nodes.length; i++)
-    {
-       var dets = nodes[i].getElementsByTagName('div');
-       if (dets[0])
-           dets[0].style.display = 'none';
-    }
     if (id == cur_id)
     {
        cur_id = -1;
@@ -413,7 +448,7 @@ function show_records()
            record_div.setAttribute('name', 'listrecord');
 
             var record_cell = create_element('a', title);
-            record_cell.setAttribute('href', '#');
+            record_cell.setAttribute('href', '#' + id);
            record_cell.setAttribute('onclick', 'fetch_details(' + id + '); return false');
             record_div.appendChild(record_cell);
            if (author)
@@ -422,7 +457,8 @@ function show_records()
                var al = create_element('a', author);
                al.setAttribute('href', '#');
                al.setAttribute('term', author);
-               al.onclick = function() { hyperlink_search('au', this); return false; };
+               al.setAttribute('searchfield', 'au');
+               al.onclick = function() { hyperlink_search(this); return false; };
                record_div.appendChild(al);
            }
            if (count > 1)
@@ -480,6 +516,8 @@ function refine_query (obj) {
        query_cell.value += ' and su=(' + term + ')';
     else if (cur_termlist == 'author')
        query_cell.value += ' and au=(' + term + ')';
+    else if (cur_termlist == 'date')
+       query_cell.value += ' and date=' + term;
 
     start_search();
 }
@@ -541,7 +579,8 @@ function check_termlist()
     var url = "search.pz2?" +
         "command=termlist" +
        "&session=" + session +
-       "&name=" + facet_name;
+       "&name=" + facet_name +
+       "&num=12";
     xtermlist = GetXmlHttpObject();
     xtermlist.onreadystatechange=show_termlist;
     xtermlist.open("GET", url);