From: Jakub Skoczen Date: Fri, 18 May 2007 11:36:39 +0000 (+0000) Subject: Added simple example of the pz2.js usage. X-Git-Tag: PAZPAR2.1.0.0~128 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=84a66a0ff48346b0d3477934e95a30135e79be8e;p=pazpar2-moved-to-github.git Added simple example of the pz2.js usage. --- diff --git a/www/README b/www/README new file mode 100644 index 0000000..90baef1 --- /dev/null +++ b/www/README @@ -0,0 +1,4 @@ +For the time being example/ (and masterkey/js/ as well, but this will be removed from the repo anyway) requires the pz2.js +to be symlinked to work. Solutions on its way, (need to talk to Adam). + +www$ ln -s ../js/pz2.js example/pz2.js diff --git a/www/example/example_client.js b/www/example/example_client.js new file mode 100644 index 0000000..5629656 --- /dev/null +++ b/www/example/example_client.js @@ -0,0 +1,157 @@ +/* A very simple client that shows a basic usage of the pz2.js +** $Id: example_client.js,v 1.1 2007-05-18 11:36:39 jakub Exp $ +*/ + +// create a parameters array and pass it to the pz2's constructor +// then register the form submit event with the pz2.search function +// autoInit is set to true on default + +my_paz = new pz2( { "onshow": my_onshow, + "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way + "onstat": my_onstat, + "onterm": my_onterm, + "termlist": "subject,author", + "onbytarget": my_onbytarget, + "onrecord": my_onrecord } ); +// some state vars +var curPage = 1; +var recPerPage = 15; +var totalRec = 0; +var curDetRecId = -1; +var curDetRecData = null; + +// wait until the DOM is ready +function domReady () +{ + document.search.onsubmit = onFormSubmitEventHandler; +} + +// when search button pressed +function onFormSubmitEventHandler() +{ + my_paz.search(document.search.query.value, recPerPage, 'relevance'); + return false; +} + +// +// pz2.js event handlers: +// + +function my_onshow(data) { + totalRec = data.merged; + + var body = document.getElementById("body"); + body.innerHTML = ""; + + body.innerHTML +='
Displaying: ' + data.start + ' to ' + (data.start + data.num) + + ' of ' + data.merged + ' (total not merged hits: ' + data.total + ')

'; + + body.innerHTML += 'Prev | ' + + 'Next
'; + + for (var i = 0; i < data.hits.length; i++) { + var hit = data.hits[i]; + body.innerHTML += '
' + +'' + (i + 1 + recPerPage * ( curPage - 1)) + '. ' + +'' + hit["md-title"] + + ' by ' + hit["md-author"] + '
'; + + if ( hit.recid == curDetRecId ) { + drawCurDetails(); + } + } + +} + +function my_onstat(data) { + var stat = document.getElementById("stat"); + stat.innerHTML = 'active clients: ' + data.activeclients + ' ' + + 'hits: ' + data.hits + ' ' + + 'records: ' + data.records + ' ' + + 'clients: ' + data.clients + ' ' + + 'searching: ' + data.searching + ''; +} + +function my_onterm(data) { + var termlist = document.getElementById("termlist"); + termlist.innerHTML = ""; + termlist.innerHTML += "
--Author
"; + for (var i = 0; i < data.author.length; i++ ) { + termlist.innerHTML += '
' + data.author[i].name + ' (' + data.author[i].freq + ')
'; + } + termlist.innerHTML += "
"; + termlist.innerHTML += "
--Subject
"; + for (var i = 0; i < data.subject.length; i++ ) { + termlist.innerHTML += '
' + data.subject[i].name + ' (' + data.subject[i].freq + ')
'; + } +} + +function my_onrecord(data) { + // in case on_show was faster to redraw element + var detRecordDiv = document.getElementById('det_'+data.recid); + if ( detRecordDiv ) + return; + + curDetRecData = data; + drawCurDetails(); +} + +function my_onbytarget(data) { + var targetDiv = document.getElementById("bytarget"); + targetDiv.innerHTML = 'IDHitsDiagRecState'; + + for (var i = 0; i < data.length; i++ ) { + targetDiv.innerHTML += "" + data[i].id + + "" + data[i].hits + + "" + data[i].diagnostic + + "" + data[i].records + + "" + data[i].state + ""; + } +} + +// detailed record drawing +function showDetails ( prefixRecId ) { + var recId = Number(prefixRecId.replace('rec_', '')); + + // if the same clicked ignore + if ( recId == curDetRecId ) + return; + + // if different remove the old one + var detRecordDiv = document.getElementById('det_'+curDetRecId); + // lovin DOM! + if ( detRecordDiv ) + detRecordDiv.parentNode.removeChild(detRecordDiv); + + curDetRecId = recId; + + // request the record + my_paz.record(recId); +} + +function drawCurDetails () +{ + var data = curDetRecData; + var recordDiv = document.getElementById('rec_'+data.recid); + recordDiv.innerHTML += '
Ttle: ' + data["md-title"] + + "
Date: " + data["md-date"] + + "
Author: " + data["md-author"] + + "
Subject: " + data["md-subject"] + + "
Location: " + data["location"][0].name + + "
"; +} + + +// simple paging functions + +function pagerNext() { + if ( totalRec - recPerPage*curPage > 0) { + my_paz.showNext(); + curPage++; + } +} + +function pagerPrev() { + if ( my_paz.showPrev() != false ) + curPage--; +} diff --git a/www/example/index.html b/www/example/index.html new file mode 100644 index 0000000..58eb769 --- /dev/null +++ b/www/example/index.html @@ -0,0 +1,57 @@ + + + + + Exemplary pazpar2 client [using pz2.js] + + + + + + + + + + + + + + + + + +
Exemplary pazpar2 client [using pz2.js] +
+ Search: + + +
+
+
+ TERMLISTS: +

+
+
+ RESULTS: +

+
+
+
+ +
+ + STATUS INFO: +
+
+
+ +
+
+ + TARGET IFO: +
+
+
+ + +