X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=www%2Fdemo%2Fsearch.js;h=81be27de1f2bac982980f53798500f41d4c3b291;hb=9028635288ffc5ba9706923bc79ac3bddfdf5e68;hp=633b10bd0fcc7c6dd65fdc350d2a32789d3e7af5;hpb=7268be709f8b7ecc6e2abb3bff746d1bd2c9a8e3;p=pazpar2-moved-to-github.git
diff --git a/www/demo/search.js b/www/demo/search.js
index 633b10b..81be27d 100644
--- a/www/demo/search.js
+++ b/www/demo/search.js
@@ -1,4 +1,4 @@
-/* $Id: search.js,v 1.4 2007-01-05 13:45:35 sondberg Exp $
+/* $Id: search.js,v 1.14 2007-01-10 12:15:46 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;
@@ -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()
@@ -145,6 +144,59 @@ 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('\n');
+
+ if ((offset >= off) && (offset < (off + max))) {
+ page_elem.className = 'select';
+ }
+
+ page_elem.setAttribute('href', '#');
+ page_elem.setAttribute('onclick', 'update_offset(' + off + ')');
+
+ div_elem.appendChild(page_elem);
+ div_elem.appendChild(newline_node);
+ }
+
+ return div_elem;
+}
+
+
+function update_offset (offset) {
+ 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 show_records()
{
if (xshow.readyState != 4)
@@ -153,6 +205,9 @@ function show_records()
var xml = xshow.responseXML;
var body = document.getElementById("body");
var hits = xml.getElementsByTagName("hit");
+
+ body.innerHTML = '';
+
if (!hits[0]) // We should never get here with blocking operations
{
body.innerHTML = "No records yet";
@@ -166,32 +221,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) { @@ -264,9 +327,11 @@ function show_termlist() { var namen = hits[i].getElementsByTagName("name"); if (namen[0]) - body.innerHTML += '' + - namen[0].childNodes[0].nodeValue + - ''; + var refine_cell = create_element('a', + namen[0].childNodes[0].nodeValue); + refine_cell.setAttribute('href', '#'); + refine_cell.setAttribute('onclick', 'refine_query(this)'); + body.appendChild(refine_cell); } if (clients > 0) @@ -371,7 +436,6 @@ function start_search() xsearch.onreadystatechange=search_started; xsearch.open("GET", url); xsearch.send(null); -// document.getElementById("termlist").innerHTML = ''; document.getElementById("body").innerHTML = ''; update_history(); shown = 0; @@ -488,7 +552,7 @@ function toggle_facet (obj) { if (obj.className == 'selected') { obj.className = 'unselected'; - container.style.display = 'block'; + container.style.display = 'inline'; } else { obj.className = 'selected'; container.style.display = 'none';