X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;ds=sidebyside;f=www%2Fjsdemo%2Fexample_client.js;h=8342494859d9a2a72b9ef965f1ace4272a5dd87c;hb=540f17b0ff1440f461bb9e99429e6157eb689968;hp=449a362a0b3d0bd4638b25d74aa8fc9fc29fb851;hpb=eb281dd67f2c072801a921e93c726d348a9c85f7;p=pazpar2-moved-to-github.git
diff --git a/www/jsdemo/example_client.js b/www/jsdemo/example_client.js
index 449a362..8342494 100644
--- a/www/jsdemo/example_client.js
+++ b/www/jsdemo/example_client.js
@@ -1,5 +1,4 @@
/* A very simple client that shows a basic usage of the pz2.js
-** $Id: example_client.js,v 1.6 2008-01-15 13:59:18 jakub Exp $
*/
// create a parameters array and pass it to the pz2's constructor
@@ -7,12 +6,14 @@
// autoInit is set to true on default
var usesessions = true;
var pazpar2path = '/pazpar2/search.pz2';
-if (document.location.hash == '#nosessions') {
+var showResponseType = '';
+if (document.location.hash == '#useproxy') {
usesessions = false;
- pazpar2path = '/pazpar2-proxy/';
+ pazpar2path = '/service-proxy/';
+ showResponseType = 'json';
}
-my_paz = new pz2( { "onshow": my_onshow,
+var my_paz = new pz2( { "onshow": my_onshow,
"showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way
"pazpar2path": pazpar2path,
"oninit": my_oninit,
@@ -21,6 +22,7 @@ my_paz = new pz2( { "onshow": my_onshow,
"termlist": "xtargets,subject,author",
"onbytarget": my_onbytarget,
"usesessions" : usesessions,
+ "showResponseType": showResponseType,
"onrecord": my_onrecord } );
// some state vars
var curPage = 1;
@@ -31,6 +33,9 @@ var curDetRecData = null;
var curSort = 'relevance';
var curFilter = null;
var submitted = false;
+var SourceMax = 16;
+var SubjectMax = 10;
+var AuthorMax = 10;
//
// pz2.js event handlers:
@@ -46,37 +51,40 @@ function my_onshow(data) {
var pager = document.getElementById("pager");
pager.innerHTML = "";
pager.innerHTML +='
Displaying: '
- + data.start + ' to ' + (data.start + data.num) +
+ + (data.start + 1) + ' to ' + (data.start + data.num) +
' of ' + data.merged + ' (found: '
+ data.total + ')
';
drawPager(pager);
// navi
var results = document.getElementById("results");
- results.innerHTML = "";
-
+
+ var html = [];
for (var i = 0; i < data.hits.length; i++) {
var hit = data.hits[i];
- var html = ''
+ html.push('
'
+'
'+ (i + 1 + recPerPage * (curPage - 1)) +'. '
+'
'
- + hit["md-title"] +' ';
- if (hit["md-title-remainder"] !== undefined) {
- html += '
' + hit["md-title-remainder"] + ' ';
- }
- if (hit["md-title-responsibility"] !== undefined) {
- html += '
'+ hit["md-title-responsibility"] +'';
- }
- html += '
';
- results.innerHTML += html;
+ + hit["md-title"] +' ');
+ if (hit["md-title-remainder"] !== undefined) {
+ html.push('
' + hit["md-title-remainder"] + ' ');
+ }
+ if (hit["md-title-responsibility"] !== undefined) {
+ html.push('
'+hit["md-title-responsibility"]+'');
+ }
if (hit.recid == curDetRecId) {
- drawCurDetails();
+ html.push(renderDetails(curDetRecData));
}
+ html.push('
');
}
+ replaceHtml(results, html.join(''));
}
function my_onstat(data) {
var stat = document.getElementById("stat");
+ if (stat == null)
+ return;
+
stat.innerHTML = ' .:STATUS INFO -- Active clients: '
+ data.activeclients
+ '/' + data.clients + ' -- '
@@ -85,51 +93,42 @@ function my_onstat(data) {
}
function my_onterm(data) {
- var termlist = document.getElementById("termlist");
- termlist.innerHTML = "
TERMLISTS:
";
-
- termlist.innerHTML += '.::Sources
';
- for (var i = 0; i < data.xtargets.length; i++ ) {
- termlist.innerHTML += ''
- + data.xtargets[i].name
- + ' ('
- + data.xtargets[i].freq
- + ')
';
+ var termlists = [];
+ termlists.push('
TERMLISTS:
.::Sources
');
+ for (var i = 0; i < data.xtargets.length && i < SourceMax; i++ ) {
+ termlists.push('' + data.xtargets[i].name
+ + ' (' + data.xtargets[i].freq + ')
');
}
-
- termlist.innerHTML += "
";
-
- termlist.innerHTML += '.::Subjects
';
- for (var i = 0; i < data.subject.length; i++ ) {
- termlist.innerHTML += ''
- + data.subject[i].name
- + ' ('
- + data.subject[i].freq
- + ')
';
+
+ termlists.push('
.::Subjects
');
+ for (var i = 0; i < data.subject.length && i < SubjectMax; i++ ) {
+ termlists.push('' + data.subject[i].name + ' ('
+ + data.subject[i].freq + ')
');
}
-
- termlist.innerHTML += "
";
-
- termlist.innerHTML += '.::Authors
';
- for (var i = 0; i < data.author.length; i++ ) {
- termlist.innerHTML += ''
+
+ termlists.push('
.::Authors
');
+ for (var i = 0; i < data.author.length && i < AuthorMax; i++ ) {
+ termlists.push(''
+ data.author[i].name
+ ' ('
+ data.author[i].freq
- + ')
';
+ + ')
');
}
-
+ var termlist = document.getElementById("termlist");
+ replaceHtml(termlist, termlists.join(''));
}
function my_onrecord(data) {
+ // FIXME: record is async!!
+ clearTimeout(my_paz.recordTimer);
// in case on_show was faster to redraw element
var detRecordDiv = document.getElementById('det_'+data.recid);
- if ( detRecordDiv )
- return;
+ if (detRecordDiv) return;
curDetRecData = data;
- drawCurDetails();
+ var recordDiv = document.getElementById('recdiv_'+curDetRecData.recid);
+ var html = renderDetails(curDetRecData);
+ recordDiv.innerHTML += html;
}
function my_onbytarget(data) {
@@ -246,7 +245,7 @@ function drawPager (pagerDiv)
var prev = '<< Prev | ';
if (curPage > 1)
- var prev = ''
+ prev = ''
+'<< Prev | ';
var middle = '';
@@ -261,14 +260,14 @@ function drawPager (pagerDiv)
var next = ' | Next >>';
if (pages - curPage > 0)
- var next = ' | '
+ next = ' | '
+'Next >>';
- predots = '';
+ var predots = '';
if (firstClkbl > 1)
predots = '...';
- postdots = '';
+ var postdots = '';
if (lastClkbl < pages)
postdots = '...';
@@ -318,33 +317,55 @@ function switchView(view) {
}
// detailed record drawing
-function showDetails ( prefixRecId ) {
+function showDetails (prefixRecId) {
var recId = prefixRecId.replace('rec_', '');
+ var oldRecId = curDetRecId;
+ curDetRecId = recId;
// remove current detailed view if any
- var detRecordDiv = document.getElementById('det_'+curDetRecId);
+ var detRecordDiv = document.getElementById('det_'+oldRecId);
// lovin DOM!
- if ( detRecordDiv )
- detRecordDiv.parentNode.removeChild(detRecordDiv);
+ if (detRecordDiv)
+ detRecordDiv.parentNode.removeChild(detRecordDiv);
- // if the same clicked do not redraw
- if ( recId == curDetRecId ) {
+ // if the same clicked, just hide
+ if (recId == oldRecId) {
curDetRecId = '';
+ curDetRecData = null;
return;
}
-
- curDetRecId = recId;
// request the record
my_paz.record(recId);
}
-function drawCurDetails ()
+function replaceHtml(el, html) {
+ var oldEl = typeof el === "string" ? document.getElementById(el) : el;
+ /*@cc_on // Pure innerHTML is slightly faster in IE
+ oldEl.innerHTML = html;
+ return oldEl;
+ @*/
+ var newEl = oldEl.cloneNode(false);
+ newEl.innerHTML = html;
+ oldEl.parentNode.replaceChild(newEl, oldEl);
+ /* Since we just removed the old element from the DOM, return a reference
+ to the new element, which can be used to restore variable references. */
+ return newEl;
+};
+
+function renderDetails(data, marker)
{
- var data = curDetRecData;
- var recordDiv = document.getElementById('recdiv_'+data.recid);
- var details = "";
- if (data["md-title"] != undefined)
- details += 'Ttle | : '+data["md-title"] + ' |
';
+ var details = '';
+ if (marker) details += ''+ marker + ' |
';
+ if (data["md-title"] != undefined) {
+ details += 'Title | : '+data["md-title"];
+ if (data["md-title-remainder"] !== undefined) {
+ details += ' : ' + data["md-title-remainder"] + ' ';
+ }
+ if (data["md-title-responsibility"] !== undefined) {
+ details += ' '+ data["md-title-responsibility"] +'';
+ }
+ details += ' |
';
+ }
if (data["md-date"] != undefined)
details += 'Date | : ' + data["md-date"] + ' |
';
if (data["md-author"] != undefined)
@@ -355,6 +376,7 @@ function drawCurDetails ()
details += 'Subject | : ' + data["location"][0]["md-subject"] + ' |
';
if (data["location"][0]["@name"] != undefined)
details += 'Location | : ' + data["location"][0]["@name"] + " (" +data["location"][0]["@id"] + ")" + ' |
';
- recordDiv.innerHTML += '';
+ details += '
';
+ return details;
}
//EOF