From fbc1e690a450845259ad3e39b9e5520597a4dadd Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 20 Jun 2007 14:03:15 +0000 Subject: [PATCH] Example client moved to jsdemo. There are other examples and jsdemo illustrates the use of the pz2.js library. --- www/example/example_client.js | 203 ----------------------------------------- www/example/index.html | 141 ---------------------------- 2 files changed, 344 deletions(-) delete mode 100644 www/example/example_client.js delete mode 100644 www/example/index.html diff --git a/www/example/example_client.js b/www/example/example_client.js deleted file mode 100644 index aad6303..0000000 --- a/www/example/example_client.js +++ /dev/null @@ -1,203 +0,0 @@ -/* A very simple client that shows a basic usage of the pz2.js -** $Id: example_client.js,v 1.4 2007-05-21 08:21:33 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 = 20; -var totalRec = 0; -var curDetRecId = -1; -var curDetRecData = null; - -// wait until the DOM is ready -function domReady () -{ - document.search.onsubmit = onFormSubmitEventHandler; - my_paz.stat(); - my_paz.bytarget(); -} - -// when search button pressed -function onFormSubmitEventHandler() -{ - curPage = 1; - curDetRecId = -1; - totalRec = 0; - 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 - + '/' + data.clients + ' | ' - + 'Retrieved records: ' + data.records - + '/' + data.hits + ''; -} - -function my_onterm(data) { - var termlist = document.getElementById("termlist"); - termlist.innerHTML = "
TERMLISTS:
"; - termlist.innerHTML += '
.::Subjects
'; - for (var i = 0; i < data.subject.length; i++ ) { - termlist.innerHTML += '' - + data.subject[i].name - + ' (' - + data.subject[i].freq - + ')
'; - } - termlist.innerHTML += "
"; - termlist.innerHTML += '
.::Authors
'; - for (var i = 0; i < data.author.length; i++ ) { - termlist.innerHTML += '' - + data.author[i].name - + ' (' - + data.author[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"); - var table = 'Target IDHitsDiags' - +'RecordsState'; - - for (var i = 0; i < data.length; i++ ) { - table += "" + data[i].id + - "" + data[i].hits + - "" + data[i].diagnostic + - "" + data[i].records + - "" + data[i].state + ""; - } - - table += ''; - targetDiv.innerHTML = table; - -} - -// detailed record drawing -function showDetails ( prefixRecId ) { - var recId = Number(prefixRecId.replace('rec_', '')); - - // remove current detailed view if any - var detRecordDiv = document.getElementById('det_'+curDetRecId); - // lovin DOM! - if ( detRecordDiv ) - detRecordDiv.parentNode.removeChild(detRecordDiv); - - // if the same clicked do not redraw - if ( recId == curDetRecId ) { - curDetRecId = -1; - return; - } - - 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--; -} - -// swithing view between targets and records - -function switchView(view) { - - var targets = document.getElementById('targetview'); - var records = document.getElementById('recordview'); - - switch(view) { - case 'targetview': - targets.style.display = "block"; - records.style.display = "none"; - break; - case 'recordview': - targets.style.display = "none"; - records.style.display = "block"; - break; - default: - alert('Unknown view.'); - } -} diff --git a/www/example/index.html b/www/example/index.html deleted file mode 100644 index 66bffb3..0000000 --- a/www/example/index.html +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - Exemplary pazpar2 client [using pz2.js] - - - - - - - - Records Browser - | - Targets Information - -

- - - - - - -
PazPar2 -
- - -
-
- -
- - - - - - -
-
-
-
-
- -
-
- STATUS INFO: -
-
-
- -
- - - - - -- 1.7.10.4