projects
/
pazpar2-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Query refinement works again.
[pazpar2-moved-to-github.git]
/
www
/
demo
/
search.js
diff --git
a/www/demo/search.js
b/www/demo/search.js
index
c996c1b
..
e4f6dab
100644
(file)
--- a/
www/demo/search.js
+++ b/
www/demo/search.js
@@
-1,4
+1,4
@@
-/* $Id: search.js,v 1.15 2007-01-10 12:20:51 sondberg Exp $
+/* $Id: search.js,v 1.20 2007-01-11 12:47:19 sondberg Exp $
* ---------------------------------------------------
* Javascript container
*/
* ---------------------------------------------------
* Javascript container
*/
@@
-60,7
+60,7
@@
function session_started()
return;
var xml = xinitSession.responseXML;
var sesid = xml.getElementsByTagName("session")[0].childNodes[0].nodeValue;
return;
var xml = xinitSession.responseXML;
var sesid = xml.getElementsByTagName("session")[0].childNodes[0].nodeValue;
- document.getElementById("status").innerHTML = "Live";
+ assign_text(document.getElementById("status"), 'Live');
session = sesid;
setTimeout(ping_session, 50000);
}
session = sesid;
setTimeout(ping_session, 50000);
}
@@
-111,7
+111,8
@@
function targets_loaded()
alert(msg);
return;
}
alert(msg);
return;
}
- document.getElementById("targetstatus").innerHTML = "Targets loaded";
+
+ assign_text(document.getElementById("targetstatus"), 'Targets loaded');
}
function load_targets()
}
function load_targets()
@@
-121,7
+122,7
@@
function load_targets()
clearTimeout(searchtimer);
clearTimeout(stattimer);
clearTimeout(showtimer);
clearTimeout(searchtimer);
clearTimeout(stattimer);
clearTimeout(showtimer);
- document.getElementById("stat").innerHTML = "";
+ clear_cell(document.getElementById("stat"));
if (!fn)
{
alert("Please enter a target definition file name");
if (!fn)
{
alert("Please enter a target definition file name");
@@
-131,7
+132,7
@@
function load_targets()
"command=load" +
"&session=" + session +
"&name=" + fn;
"command=load" +
"&session=" + session +
"&name=" + fn;
- document.getElementById("targetstatus").innerHTML = "Loading targets...";
+ assign_text(document.getElementById("targetstatus"), 'Loading targets...');
xloadTargets = GetXmlHttpObject();
xloadTargets.onreadystatechange=targets_loaded;
xloadTargets.open("GET", url);
xloadTargets = GetXmlHttpObject();
xloadTargets.onreadystatechange=targets_loaded;
xloadTargets.open("GET", url);
@@
-162,14
+163,17
@@
function make_pager (hits, offset, max) {
var p = off / max + 1;
var page_elem = create_element('a', p);
var p = off / max + 1;
var page_elem = create_element('a', p);
- var newline_node = document.createTextNode('\n');
+ var newline_node = document.createTextNode(' ');
if ((offset >= off) && (offset < (off + max))) {
page_elem.className = 'select';
}
page_elem.setAttribute('href', '#');
if ((offset >= off) && (offset < (off + max))) {
page_elem.className = 'select';
}
page_elem.setAttribute('href', '#');
- page_elem.setAttribute('onclick', 'update_offset(' + off + ')');
+ page_elem.setAttribute('off', off);
+ page_elem.onclick = function () {
+ update_offset(this.getAttribute('off'));
+ };
div_elem.appendChild(page_elem);
div_elem.appendChild(newline_node);
div_elem.appendChild(page_elem);
div_elem.appendChild(newline_node);
@@
-180,6
+184,7
@@
function make_pager (hits, offset, max) {
function update_offset (offset) {
function update_offset (offset) {
+ clearTimeout(searchtimer);
document.search.startrec.value = offset;
update_action('page');
check_search();
document.search.startrec.value = offset;
update_action('page');
check_search();
@@
-203,6
+208,18
@@
function clear_cell (cell) {
}
}
+function append_text(cell, text) {
+ text_node = document.createTextNode(text);
+ cell.appendChild(text_node);
+}
+
+
+function assign_text (cell, text) {
+ clear_cell(cell);
+ append_text(cell, text);
+}
+
+
function show_records()
{
if (xshow.readyState != 4)
function show_records()
{
if (xshow.readyState != 4)
@@
-216,7
+233,7
@@
function show_records()
if (!hits[0]) // We should never get here with blocking operations
{
if (!hits[0]) // We should never get here with blocking operations
{
- body.innerHTML = "No records yet";
+ assign_text(body, 'No records yet');
searchtimer = setTimeout(check_search, 250);
}
else
searchtimer = setTimeout(check_search, 250);
}
else
@@
-291,14
+308,17
@@
function check_search()
function refine_query (obj) {
function refine_query (obj) {
+ var term = obj.getAttribute('term');
+ var cur_termlist = obj.getAttribute('facet');
var query_cell = document.getElementById('query');
var query_cell = document.getElementById('query');
- var term = obj.innerHTML;
term = term.replace(/[\(\)]/g, '');
term = term.replace(/[\(\)]/g, '');
+
if (cur_termlist == 'subject')
query_cell.value += ' and su=(' + term + ')';
else if (cur_termlist == 'author')
query_cell.value += ' and au=(' + term + ')';
if (cur_termlist == 'subject')
query_cell.value += ' and su=(' + term + ')';
else if (cur_termlist == 'author')
query_cell.value += ' and au=(' + term + ')';
+
start_search();
}
start_search();
}
@@
-312,6
+332,7
@@
function show_termlist()
var i;
var xml = xtermlist.responseXML;
var body = facet_list[cur_facet][1];
var i;
var xml = xtermlist.responseXML;
var body = facet_list[cur_facet][1];
+ var facet_name = facet_list[cur_facet][0];
var hits = xml.getElementsByTagName("term");
var clients =
Number(xml.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue);
var hits = xml.getElementsByTagName("term");
var clients =
Number(xml.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue);
@@
-327,16
+348,21
@@
function show_termlist()
}
else
{
}
else
{
- body.innerHTML = '';
+ clear_cell(body);
for (i = 0; i < hits.length; i++)
{
var namen = hits[i].getElementsByTagName("name");
if (namen[0])
for (i = 0; i < hits.length; i++)
{
var namen = hits[i].getElementsByTagName("name");
if (namen[0])
- var refine_cell = create_element('a',
- namen[0].childNodes[0].nodeValue);
+ var term = namen[0].childNodes[0].nodeValue;
+ var refine_cell = create_element('a', term);
refine_cell.setAttribute('href', '#');
refine_cell.setAttribute('href', '#');
- refine_cell.setAttribute('onclick', 'refine_query(this)');
+ refine_cell.setAttribute('term', term);
+ refine_cell.setAttribute('facet', facet_name);
+ refine_cell.onclick = function () {
+ refine_query(this);
+ return false;
+ };
body.appendChild(refine_cell);
}
body.appendChild(refine_cell);
}
@@
-374,7
+400,7
@@
function show_stat()
}
else
{
}
else
{
- body.innerHTML = "(";
+ assign_text(body, '(');
for (i = 0; i < nodes.length; i++)
{
if (nodes[i].nodeType != 1)
for (i = 0; i < nodes.length; i++)
{
if (nodes[i].nodeType != 1)
@@
-383,9
+409,10
@@
function show_stat()
if (value == 0)
continue;
var name = nodes[i].nodeName;
if (value == 0)
continue;
var name = nodes[i].nodeName;
- body.innerHTML += ' ' + name + '=' + value;
+ append_text(body, ' ' + name + '=' + value);
}
}
- body.innerHTML += ')';
+
+ append_text(body, ')');
if (clients > 0)
stattimer = setTimeout(check_stat, 2000);
}
if (clients > 0)
stattimer = setTimeout(check_stat, 2000);
}
@@
-442,7
+469,7
@@
function start_search()
xsearch.onreadystatechange=search_started;
xsearch.open("GET", url);
xsearch.send(null);
xsearch.onreadystatechange=search_started;
xsearch.open("GET", url);
xsearch.send(null);
- document.getElementById("body").innerHTML = '';
+ clear_cell(document.getElementById("body"));
update_history();
shown = 0;
document.search.startrec.value = 0;
update_history();
shown = 0;
document.search.startrec.value = 0;