-/* $Id: search.js,v 1.29 2007-01-16 18:19:50 quinn Exp $
+/* $Id: search.js,v 1.34 2007-01-17 02:15:12 quinn Exp $
* ---------------------------------------------------
* Javascript container
*/
var xml = xpingSession.responseXML;
var error = xml.getElementsByTagName("error");
if (error[0])
- {
- var msg = error[0].childNodes[0].nodeValue;
- alert(msg);
location = "?";
- return;
- }
setTimeout(ping_session, 50000);
}
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
+ var dname = displayname(name);
+ 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);
+ tr.appendChild(dn);
+ return tr;
+}
+
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;
var i;
var table = document.createElement('table');
table.setAttribute('cellpadding', 2);
+ var dn = 0;
+ var lastname = '';
for (i = 0; i < nodes.length; i++)
{
if (nodes[i].nodeType != 1)
var name = nodes[i].nodeName;
if (name == 'recid' || name == 'md-title')
continue;
- name = displayname(name);
+ if (name != lastname)
+ {
+ if (dn)
+ {
+ var tr = paint_details_tr(lastname, dn);
+ table.appendChild(tr);
+ }
+ dn = document.createElement('td');
+ lastname = name;
+ }
+
if (!nodes[i].childNodes[0])
continue;
var value = nodes[i].childNodes[0].nodeValue;
- var lbl = create_element('b', name );
- var lbln = document.createElement('td');
- lbln.setAttribute('width', 70);
- lbln.appendChild(lbl);
- var val = create_element('td', value);
- var tr = document.createElement('tr');
- tr.appendChild(lbln);
- tr.appendChild(val);
+ if (dn.childNodes[0])
+ 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)
+ {
+ var tr = paint_details_tr(lastname, dn);
table.appendChild(tr);
}
body.appendChild(table);
return;
}
- // This is some ugly display code. Replace with your own ting o'beauty
-
var idn = xml.getElementsByTagName('recid');
if (!idn[0])
return;
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;
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;
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)
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)