X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=www%2Fdemo%2Fsearch.js;h=e4f6dab0be2ef582dc7da8b6749835e467108e3d;hb=b9d0a5d83e92790ae3acf181d172dad1188e5fb7;hp=d8713811cb732a2664237e24b4ea419a633f49fc;hpb=04ff15226a5bc356bbee08160c1b49dcae519b5c;p=pazpar2-moved-to-github.git
diff --git a/www/demo/search.js b/www/demo/search.js
index d871381..e4f6dab 100644
--- a/www/demo/search.js
+++ b/www/demo/search.js
@@ -1,4 +1,4 @@
-/* $Id: search.js,v 1.5 2007-01-05 13:53:33 sondberg Exp $
+/* $Id: search.js,v 1.20 2007-01-11 12:47:19 sondberg Exp $
* ---------------------------------------------------
* Javascript container
*/
@@ -21,6 +21,7 @@ var session_cells = Array('query', 'startrec', 'action_type');
var old_session = session_read();
var url_surveillence;
var recstoshow = 15;
+var page_window = 5; // Number of pages prior to and after the current page
var facet_list;
var cur_facet = 0;
@@ -59,7 +60,7 @@ function session_started()
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);
}
@@ -72,8 +73,6 @@ function start_session()
xinitSession.onreadystatechange=session_started;
xinitSession.open("GET", url);
xinitSession.send(null);
-
- //url_surveillence = setInterval(session_check, 200);
}
function ping_session()
@@ -112,7 +111,8 @@ function targets_loaded()
alert(msg);
return;
}
- document.getElementById("targetstatus").innerHTML = "Targets loaded";
+
+ assign_text(document.getElementById("targetstatus"), 'Targets loaded');
}
function load_targets()
@@ -122,7 +122,7 @@ function load_targets()
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");
@@ -132,7 +132,7 @@ function load_targets()
"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);
@@ -145,6 +145,81 @@ function update_action (new_action) {
}
+function make_pager (hits, offset, max) {
+ var html = '';
+ var off;
+ var start_offset = offset - page_window * max;
+ var div_elem = document.createElement('div');
+
+ div_elem.className = 'pages';
+
+ if (start_offset < 0) {
+ start_offset = 0;
+ }
+
+ for (off = start_offset;
+ off < hits && off < (start_offset + 2 * page_window * max);
+ off += max) {
+
+ var p = off / max + 1;
+ var page_elem = create_element('a', p);
+ var newline_node = document.createTextNode(' ');
+
+ if ((offset >= off) && (offset < (off + max))) {
+ page_elem.className = 'select';
+ }
+
+ page_elem.setAttribute('href', '#');
+ page_elem.setAttribute('off', off);
+ page_elem.onclick = function () {
+ update_offset(this.getAttribute('off'));
+ };
+
+ div_elem.appendChild(page_elem);
+ div_elem.appendChild(newline_node);
+ }
+
+ return div_elem;
+}
+
+
+function update_offset (offset) {
+ clearTimeout(searchtimer);
+ document.search.startrec.value = offset;
+ update_action('page');
+ check_search();
+ update_history();
+ return false;
+}
+
+
+function create_element (name, cdata) {
+ var elem_node = document.createElement(name);
+ var text_node = document.createTextNode(cdata);
+ elem_node.appendChild(text_node);
+
+ return elem_node;
+}
+
+
+function clear_cell (cell) {
+ while (cell.hasChildNodes())
+ cell.removeChild(cell.firstChild);
+}
+
+
+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)
@@ -153,9 +228,12 @@ function show_records()
var xml = xshow.responseXML;
var body = document.getElementById("body");
var hits = xml.getElementsByTagName("hit");
+
+ clear_cell(body);
+
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
@@ -166,32 +244,40 @@ function show_records()
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 = 'Records : ';
- body.innerHTML += (start + 1) + ' to ' + (start + num) +
- ' of ' + merged + ' (total hits: ' + total + ')';
-
- if (start + num < merged)
- body.innerHTML += ' Next';
-
- if (start > 0)
- body.innerHTML += ' Previous';
-
- body.innerHTML += '
';
+ var pager = make_pager(merged, start,recstoshow);
+ var break_node1 = document.createElement('br');
+ var break_node2 = document.createElement('br');
+ var record_container = document.createElement('div');
+ var interval = create_element('div', 'Records : ' + (start + 1) +
+ ' to ' + (start + num) + ' of ' +
+ merged + ' (total hits: ' +
+ total + ')');
+ interval.className = 'results';
+ record_container.className = 'records';
+
+ body.appendChild(pager);
+ body.appendChild(interval);
+ body.appendChild(break_node1);
+ body.appendChild(break_node2);
+ body.appendChild(record_container);
+
for (i = 0; i < hits.length; i++)
{
- body.innerHTML += '
'; - body.innerHTML += (i + start + 1) + ': '; - var mk = hits[i].getElementsByTagName("title"); - if (mk[0]) - body.innerHTML += mk[0].childNodes[0].nodeValue; - body.innerHTML += '
'; + var mk = hits[i].getElementsByTagName("md-title"); + var field = ''; + + if (mk[0]) { + field = mk[0].childNodes[0].nodeValue; + } else { + field = 'N/A'; + } + + var record_cell = create_element('a', field); + record_cell.setAttribute('href', '#'); + record_cell.className = 'record'; + record_container.appendChild(record_cell); } + shown++; if (clients > 0) { @@ -222,14 +308,17 @@ function check_search() function refine_query (obj) { + var term = obj.getAttribute('term'); + var cur_termlist = obj.getAttribute('facet'); var query_cell = document.getElementById('query'); - var term = obj.innerHTML; 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 + ')'; + start_search(); } @@ -243,6 +332,7 @@ function show_termlist() 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); @@ -258,15 +348,22 @@ function show_termlist() } else { - body.innerHTML = ''; + clear_cell(body); for (i = 0; i < hits.length; i++) { var namen = hits[i].getElementsByTagName("name"); if (namen[0]) - body.innerHTML += '' + - 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('term', term); + refine_cell.setAttribute('facet', facet_name); + refine_cell.onclick = function () { + refine_query(this); + return false; + }; + body.appendChild(refine_cell); } if (clients > 0) @@ -303,7 +400,7 @@ function show_stat() } else { - body.innerHTML = "("; + assign_text(body, '('); for (i = 0; i < nodes.length; i++) { if (nodes[i].nodeType != 1) @@ -312,9 +409,10 @@ function show_stat() 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); } @@ -371,8 +469,7 @@ function start_search() xsearch.onreadystatechange=search_started; xsearch.open("GET", url); xsearch.send(null); -// document.getElementById("termlist").innerHTML = ''; - document.getElementById("body").innerHTML = ''; + clear_cell(document.getElementById("body")); update_history(); shown = 0; document.search.startrec.value = 0;