-/* $Id: search.js,v 1.1 2006-12-29 10:22:09 sondberg Exp $
+/* $Id: search.js,v 1.6 2007-01-04 20:00:58 quinn Exp $
* ---------------------------------------------------
* Javascript container
*/
var showtimer;
var termtimer;
var stattimer;
-var startrec;
-var session_cells = Array('query');
+var session_cells = Array('query', 'startrec', 'action_type');
var old_session = session_read();
+var url_surveillence;
+
+
+function initialize ()
+{
+ start_session();
+ session_check();
+}
+
function GetXmlHttpObject()
{
return objXMLHttp
}
+function SendXmlHttpObject(obj, url, handler)
+{
+ obj.onreadystatechange=handler;
+ obj.open("GET", url);
+ obj.send(null);
+}
+
function session_started()
{
if (xinitSession.readyState != 4)
var sesid = xml.getElementsByTagName("session")[0].childNodes[0].nodeValue;
document.getElementById("status").innerHTML = "Live";
session = sesid;
+ setTimeout(ping_session, 50000);
}
function start_session()
xinitSession.onreadystatechange=session_started;
xinitSession.open("GET", url);
xinitSession.send(null);
+
+ //url_surveillence = setInterval(session_check, 200);
+}
+
+function ping_session()
+{
+ if (!session)
+ return;
+ var url = "search.pz2?command=ping&session=" + session;
+ SendXmlHttpObject(xpingSession = GetXmlHttpObject(), url, session_pinged);
+}
+
+function session_pinged()
+{
+ if (xpingSession.readyState != 4)
+ return;
+ 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);
}
function targets_loaded()
xloadTargets.send(null);
}
+
+function update_action (new_action) {
+ document.search.action_type.value = new_action;
+}
+
+
function show_records()
{
if (xshow.readyState != 4)
var merged = Number(xml.getElementsByTagName('merged')[0].childNodes[0].nodeValue);
var start = Number(xml.getElementsByTagName('start')[0].childNodes[0].nodeValue);
var num = Number(xml.getElementsByTagName('num')[0].childNodes[0].nodeValue);
+ var clients = Number(xml.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue);
body.innerHTML = '<b>Records : ';
body.innerHTML += (start + 1) + ' to ' + (start + num) +
' of ' + merged + ' (total hits: ' + total + ')</b>';
if (start + num < merged)
body.innerHTML += ' <a href="" ' +
- 'onclick="startrec=' + (start + 20) +
- ';check_search(); return false;">Next</a>';
+ 'onclick="document.search.startrec.value=' + (start + 20) +
+ ";update_action('page')" +
+ ';check_search(); update_history(); return false;">Next</a>';
if (start > 0)
body.innerHTML += ' <a href="" ' +
- 'onclick="startrec=' + (start - 20) +
- ';check_search(); return false;">Previous</a>';
+ 'onclick="document.search.startrec.value=' + (start - 20) +
+ ";update_action('page')" +
+ ';check_search(); update_history();return false;">Previous</a>';
body.innerHTML += '<br/>';
for (i = 0; i < hits.length; i++)
body.innerHTML += '</p>';
}
shown++;
- if (shown < 5)
- searchtimer = setTimeout(check_search, 1000);
- else
- searchtimer = setTimeout(check_search, 2000);
+ if (clients > 0)
+ {
+ if (shown < 5)
+ searchtimer = setTimeout(check_search, 1000);
+ else
+ searchtimer = setTimeout(check_search, 2000);
+ }
}
if (!termtimer)
termtimer = setTimeout(check_termlist, 1000);
clearTimeout(searchtimer);
var url = "search.pz2?" +
"command=show" +
- "&start=" + startrec +
+ "&start=" + document.search.startrec.value +
"&num=15" +
"&session=" + session +
"&block=1";
var xml = xtermlist.responseXML;
var body = document.getElementById("termlist");
var hits = xml.getElementsByTagName("term");
+ var clients =
+ Number(xml.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue);
if (!hits[0])
{
termtimer = setTimeout(check_termlist, 1000);
body.innerHTML += '<a href="#" onclick="refine_query(this)">' +
namen[0].childNodes[0].nodeValue +
'</a>';
- /*
- body.innerHTML += ' (';
- var freqn = hits[i].getElementsByTagName("frequency");
- if (freqn[0])
- body.innerHTML += freqn[0].childNodes[0].nodeValue;
- body.innerHTML += ')<br>';
- */
body.innerHTML += '<br>';
}
- termtimer = setTimeout(check_termlist, 2000);
+ if (clients > 0)
+ termtimer = setTimeout(check_termlist, 2000);
}
}
-
function check_termlist()
{
var url = "search.pz2?" +
"command=termlist" +
- "&session=" + session;
+ "&session=" + session +
+ "&name=" + "subject";
xtermlist = GetXmlHttpObject();
xtermlist.onreadystatechange=show_termlist;
xtermlist.open("GET", url);
var xml = xstat.responseXML;
var body = document.getElementById("stat");
var nodes = xml.childNodes[0].childNodes;
+ var clients =
+ Number(xml.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue);
if (!nodes[0])
{
stattimer = setTimeout(check_stat, 500);
body.innerHTML += ' ' + name + '=' + value;
}
body.innerHTML += ')';
- stattimer = setTimeout(check_stat, 2000);
+ if (clients > 0)
+ stattimer = setTimeout(check_stat, 2000);
}
}
document.getElementById("body").innerHTML = '';
update_history();
shown = 0;
- startrec = 0;
+ document.search.startrec.value = 0;
}
function session_check ()
{
var session = session_read();
+ var action = document.search.action_type.value;
clearInterval(url_surveillence);
if ( session != unescape(old_session) )
{
session_restore(session);
- start_search();
-
+
+ if (action == 'search') {
+ start_search();
+ } else if (action == 'page') {
+ check_search();
+ } else {
+ alert('Unregocnized action_type: ' + action);
+ return;
+ }
}
url_surveillence = setInterval(session_check, 200);
}
-
-
-var url_surveillence = setInterval(session_check, 200);
-