X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=www%2Fdemo%2Fsearch.js;h=e6917a7e76e2a95d80abf8b194a3acef4029ab86;hb=8ca1269eac32c1ddc19d16dc4f74e9a1e3e0b8f9;hp=6e90aa0de6b9d188438efed1ba342a49b58ff2e1;hpb=b1d1bd7c6dbf7af16d5047d91b39827d9a8c4252;p=pazpar2-moved-to-github.git diff --git a/www/demo/search.js b/www/demo/search.js index 6e90aa0..e6917a7 100644 --- a/www/demo/search.js +++ b/www/demo/search.js @@ -1,4 +1,4 @@ -/* $Id: search.js,v 1.8 2007-01-08 14:51:35 sondberg Exp $ +/* $Id: search.js,v 1.23 2007-01-15 04:34:29 quinn Exp $ * --------------------------------------------------- * Javascript container */ @@ -20,16 +20,19 @@ var stattimer; var session_cells = Array('query', 'startrec', 'action_type'); var old_session = session_read(); var url_surveillence; -var recstoshow = 15; +var recstoshow = 20; var page_window = 5; // Number of pages prior to and after the current page var facet_list; var cur_facet = 0; +var cur_sort = "relevance"; +var searched = 0; function initialize () { facet_list = get_available_facets(); start_session(); session_check(); + set_sort(); } @@ -60,7 +63,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); } @@ -73,8 +76,6 @@ function start_session() xinitSession.onreadystatechange=session_started; xinitSession.open("GET", url); xinitSession.send(null); - - //url_surveillence = setInterval(session_check, 200); } function ping_session() @@ -101,46 +102,6 @@ function session_pinged() setTimeout(ping_session, 50000); } -function targets_loaded() -{ - if (xloadTargets.readyState != 4) - return; - var xml = xloadTargets.responseXML; - var error = xml.getElementsByTagName("error"); - if (error[0]) - { - var msg = error[0].childNodes[0].nodeValue; - alert(msg); - return; - } - document.getElementById("targetstatus").innerHTML = "Targets loaded"; -} - -function load_targets() -{ - var fn = document.getElementById("targetfilename").value; - clearTimeout(termtimer); - clearTimeout(searchtimer); - clearTimeout(stattimer); - clearTimeout(showtimer); - document.getElementById("stat").innerHTML = ""; - if (!fn) - { - alert("Please enter a target definition file name"); - return; - } - var url="search.pz2?" + - "command=load" + - "&session=" + session + - "&name=" + fn; - document.getElementById("targetstatus").innerHTML = "Loading targets..."; - xloadTargets = GetXmlHttpObject(); - xloadTargets.onreadystatechange=targets_loaded; - xloadTargets.open("GET", url); - xloadTargets.send(null); -} - - function update_action (new_action) { document.search.action_type.value = new_action; } @@ -149,30 +110,43 @@ 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'; - for (off = offset - page_window * max; - off < hits && off < (offset + page_window * max); - off += max) { + if (start_offset < 0) { + start_offset = 0; + } - var class = ''; + for (off = start_offset; + off < hits && off < (start_offset + 2 * page_window * max); + off += max) { - if (off < 0) - off = 0; - 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'; + } - if ((offset >= off) && (offset < (off + max))) - class = ' class="select"'; + page_elem.setAttribute('off', off); + page_elem.style.cursor = 'pointer'; + page_elem.onclick = function () { + update_offset(this.getAttribute('off')); + }; - html += '' + p + '\n'; + div_elem.appendChild(page_elem); + div_elem.appendChild(newline_node); } - return html; + return div_elem; } function update_offset (offset) { + clearTimeout(searchtimer); document.search.startrec.value = offset; update_action('page'); check_search(); @@ -181,6 +155,64 @@ function update_offset (offset) { } +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 set_sort_opt(n, opt, str) +{ + var txt = document.createTextNode(str); + if (opt == cur_sort) + n.appendChild(txt); + else + { + var a = document.createElement('a'); + a.appendChild(txt); + a.setAttribute('href', ""); + a.setAttribute('onclick', "set_sort('" + opt + "'); return false"); + n.appendChild(a); + } +} + +function set_sort(sort) +{ + if (sort && sort != cur_sort) + { + cur_sort = sort; + if (searched) + check_search(); + } + + var t = document.getElementById("sortselect"); + clear_cell(t); + t.appendChild(document.createTextNode("Sort results by: ")); + set_sort_opt(t, 'relevance', 'Relevance'); + t.appendChild(document.createTextNode(" or ")); + set_sort_opt(t, 'title:1', 'Title'); +} + function show_records() { if (xshow.readyState != 4) @@ -189,59 +221,56 @@ 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 { - var total = Number(xml.getElementsByTagName('total')[0].childNodes[0].nodeValue); 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 = '