From: Mike Taylor Date: Mon, 17 Jun 2013 16:23:36 +0000 (+0100) Subject: Rename X-Git-Tag: 0.9.1~603 X-Git-Url: http://jsfdemo.indexdata.com/?a=commitdiff_plain;h=af70c1173abe17201f7e1439176c8b102fec8d9b;p=mkws-moved-to-github.git Rename --- diff --git a/experiments/spclient/example_client.js b/experiments/spclient/example_client.js deleted file mode 100644 index 8fb51fb..0000000 --- a/experiments/spclient/example_client.js +++ /dev/null @@ -1,379 +0,0 @@ -/* A very simple client that shows a basic usage of the pz2.js -*/ - -// 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 -var my_paz = new pz2( { "onshow": my_onshow, - "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way - "pazpar2path": '/service-proxy/', - "oninit": my_oninit, - "onstat": my_onstat, - "onterm": my_onterm, - "termlist": "xtargets,subject,author", - "onbytarget": my_onbytarget, - "usesessions" : false, - "showResponseType": '', // or "json" (for debugging?) - "onrecord": my_onrecord } ); -// some state vars -var curPage = 1; -var recPerPage = 20; -var totalRec = 0; -var curDetRecId = ''; -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: -// -function my_oninit() { - my_paz.stat(); - my_paz.bytarget(); -} - -function my_onshow(data) { - totalRec = data.merged; - // move it out - var pager = document.getElementById("pager"); - pager.innerHTML = ""; - pager.innerHTML +='
Displaying: ' - + (data.start + 1) + ' to ' + (data.start + data.num) + - ' of ' + data.merged + ' (found: ' - + data.total + ')
'; - drawPager(pager); - // navi - var results = document.getElementById("results"); - - var html = []; - for (var i = 0; i < data.hits.length; i++) { - var hit = data.hits[i]; - html.push('
' - +''+ (i + 1 + recPerPage * (curPage - 1)) +'. ' - +'' - + 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) { - 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 + ' -- ' - + 'Retrieved records: ' + data.records - + '/' + data.hits + ' :.'; -} - -function my_onterm(data) { - 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 + ')
'); - } - - termlists.push('
.::Subjects
'); - for (var i = 0; i < data.subject.length && i < SubjectMax; i++ ) { - termlists.push('' + data.subject[i].name + ' (' - + data.subject[i].freq + ')
'); - } - - 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; - curDetRecData = data; - var recordDiv = document.getElementById('recdiv_'+curDetRecData.recid); - var html = renderDetails(curDetRecData); - recordDiv.innerHTML += html; -} - -function my_onbytarget(data) { - var targetDiv = document.getElementById("bytarget"); - var table ='' - +''; - - for (var i = 0; i < data.length; i++ ) { - table += ""; - } - - table += '
Target IDHitsDiagsRecordsState
" + data[i].id + - "" + data[i].hits + - "" + data[i].diagnostic + - "" + data[i].records + - "" + data[i].state + "
'; - targetDiv.innerHTML = table; -} - -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -// wait until the DOM is ready -function domReady () -{ - document.search.onsubmit = onFormSubmitEventHandler; - document.search.query.value = ''; - document.select.sort.onchange = onSelectDdChange; - document.select.perpage.onchange = onSelectDdChange; -} - -// when search button pressed -function onFormSubmitEventHandler() -{ - resetPage(); - loadSelect(); - triggerSearch(); - submitted = true; - return false; -} - -function onSelectDdChange() -{ - if (!submitted) return false; - resetPage(); - loadSelect(); - my_paz.show(0, recPerPage, curSort); - return false; -} - -function resetPage() -{ - curPage = 1; - totalRec = 0; -} - -function triggerSearch () -{ - my_paz.search(document.search.query.value, recPerPage, curSort, curFilter); -} - -function loadSelect () -{ - curSort = document.select.sort.value; - recPerPage = document.select.perpage.value; -} - -// limit the query after clicking the facet -function limitQuery (field, value) -{ - document.search.query.value += ' and ' + field + '="' + value + '"'; - onFormSubmitEventHandler(); -} - -// limit by target functions -function limitTarget (id, name) -{ - var navi = document.getElementById('navi'); - navi.innerHTML = - 'Source: ' - + name + ''; - navi.innerHTML += '
'; - curFilter = 'pz:id=' + id; - resetPage(); - loadSelect(); - triggerSearch(); - return false; -} - -function delimitTarget () -{ - var navi = document.getElementById('navi'); - navi.innerHTML = ''; - curFilter = null; - resetPage(); - loadSelect(); - triggerSearch(); - return false; -} - -function drawPager (pagerDiv) -{ - //client indexes pages from 1 but pz2 from 0 - var onsides = 6; - var pages = Math.ceil(totalRec / recPerPage); - - var firstClkbl = ( curPage - onsides > 0 ) - ? curPage - onsides - : 1; - - var lastClkbl = firstClkbl + 2*onsides < pages - ? firstClkbl + 2*onsides - : pages; - - var prev = '<< Prev | '; - if (curPage > 1) - prev = ' | '; - - var middle = ''; - for(var i = firstClkbl; i <= lastClkbl; i++) { - var numLabel = i; - if(i == curPage) - numLabel = '' + i + ''; - - middle += ' ' - + numLabel + ' '; - } - - var next = ' | Next >>'; - if (pages - curPage > 0) - next = ' | '; - - var predots = ''; - if (firstClkbl > 1) - predots = '...'; - - var postdots = ''; - if (lastClkbl < pages) - postdots = '...'; - - pagerDiv.innerHTML += '
' - + prev + predots + middle + postdots + next + '

'; -} - -function showPage (pageNum) -{ - curPage = pageNum; - my_paz.showPage( curPage - 1 ); -} - -// 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.'); - } -} - -// detailed record drawing -function showDetails (prefixRecId) { - var recId = prefixRecId.replace('rec_', ''); - var oldRecId = curDetRecId; - curDetRecId = recId; - - // remove current detailed view if any - var detRecordDiv = document.getElementById('det_'+oldRecId); - // lovin DOM! - if (detRecordDiv) - detRecordDiv.parentNode.removeChild(detRecordDiv); - - // if the same clicked, just hide - if (recId == oldRecId) { - curDetRecId = ''; - curDetRecData = null; - return; - } - // request the record - my_paz.record(recId); -} - -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 details = '
'; - if (marker) details += ''; - if (data["md-title"] != undefined) { - details += ''; - } - if (data["md-date"] != undefined) - details += ''; - if (data["md-author"] != undefined) - details += ''; - if (data["md-electronic-url"] != undefined) - details += ''; - if (data["location"][0]["md-subject"] != undefined) - details += ''; - if (data["location"][0]["@name"] != undefined) - details += ''; - details += '
'+ marker + '
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 += '
Date: ' + data["md-date"] + '
Author: ' + data["md-author"] + '
URL: ' + data["md-electronic-url"] + '' + '
Subject: ' + data["location"][0]["md-subject"] + '
Location: ' + data["location"][0]["@name"] + " (" +data["location"][0]["@id"] + ")" + '
'; - return details; -} - - -$(document).ready(function() { - domReady(); - var jqxhr = jQuery.get("/service-proxy-auth") - .fail(function() { alert("service proxy authentifiction failed"); }); -}); diff --git a/experiments/spclient/mkws.js b/experiments/spclient/mkws.js new file mode 100644 index 0000000..8fb51fb --- /dev/null +++ b/experiments/spclient/mkws.js @@ -0,0 +1,379 @@ +/* A very simple client that shows a basic usage of the pz2.js +*/ + +// 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 +var my_paz = new pz2( { "onshow": my_onshow, + "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way + "pazpar2path": '/service-proxy/', + "oninit": my_oninit, + "onstat": my_onstat, + "onterm": my_onterm, + "termlist": "xtargets,subject,author", + "onbytarget": my_onbytarget, + "usesessions" : false, + "showResponseType": '', // or "json" (for debugging?) + "onrecord": my_onrecord } ); +// some state vars +var curPage = 1; +var recPerPage = 20; +var totalRec = 0; +var curDetRecId = ''; +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: +// +function my_oninit() { + my_paz.stat(); + my_paz.bytarget(); +} + +function my_onshow(data) { + totalRec = data.merged; + // move it out + var pager = document.getElementById("pager"); + pager.innerHTML = ""; + pager.innerHTML +='
Displaying: ' + + (data.start + 1) + ' to ' + (data.start + data.num) + + ' of ' + data.merged + ' (found: ' + + data.total + ')
'; + drawPager(pager); + // navi + var results = document.getElementById("results"); + + var html = []; + for (var i = 0; i < data.hits.length; i++) { + var hit = data.hits[i]; + html.push('
' + +''+ (i + 1 + recPerPage * (curPage - 1)) +'. ' + +'' + + 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) { + 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 + ' -- ' + + 'Retrieved records: ' + data.records + + '/' + data.hits + ' :.'; +} + +function my_onterm(data) { + 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 + ')
'); + } + + termlists.push('
.::Subjects
'); + for (var i = 0; i < data.subject.length && i < SubjectMax; i++ ) { + termlists.push('' + data.subject[i].name + ' (' + + data.subject[i].freq + ')
'); + } + + 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; + curDetRecData = data; + var recordDiv = document.getElementById('recdiv_'+curDetRecData.recid); + var html = renderDetails(curDetRecData); + recordDiv.innerHTML += html; +} + +function my_onbytarget(data) { + var targetDiv = document.getElementById("bytarget"); + var table ='' + +''; + + for (var i = 0; i < data.length; i++ ) { + table += ""; + } + + table += '
Target IDHitsDiagsRecordsState
" + data[i].id + + "" + data[i].hits + + "" + data[i].diagnostic + + "" + data[i].records + + "" + data[i].state + "
'; + targetDiv.innerHTML = table; +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +// wait until the DOM is ready +function domReady () +{ + document.search.onsubmit = onFormSubmitEventHandler; + document.search.query.value = ''; + document.select.sort.onchange = onSelectDdChange; + document.select.perpage.onchange = onSelectDdChange; +} + +// when search button pressed +function onFormSubmitEventHandler() +{ + resetPage(); + loadSelect(); + triggerSearch(); + submitted = true; + return false; +} + +function onSelectDdChange() +{ + if (!submitted) return false; + resetPage(); + loadSelect(); + my_paz.show(0, recPerPage, curSort); + return false; +} + +function resetPage() +{ + curPage = 1; + totalRec = 0; +} + +function triggerSearch () +{ + my_paz.search(document.search.query.value, recPerPage, curSort, curFilter); +} + +function loadSelect () +{ + curSort = document.select.sort.value; + recPerPage = document.select.perpage.value; +} + +// limit the query after clicking the facet +function limitQuery (field, value) +{ + document.search.query.value += ' and ' + field + '="' + value + '"'; + onFormSubmitEventHandler(); +} + +// limit by target functions +function limitTarget (id, name) +{ + var navi = document.getElementById('navi'); + navi.innerHTML = + 'Source: ' + + name + ''; + navi.innerHTML += '
'; + curFilter = 'pz:id=' + id; + resetPage(); + loadSelect(); + triggerSearch(); + return false; +} + +function delimitTarget () +{ + var navi = document.getElementById('navi'); + navi.innerHTML = ''; + curFilter = null; + resetPage(); + loadSelect(); + triggerSearch(); + return false; +} + +function drawPager (pagerDiv) +{ + //client indexes pages from 1 but pz2 from 0 + var onsides = 6; + var pages = Math.ceil(totalRec / recPerPage); + + var firstClkbl = ( curPage - onsides > 0 ) + ? curPage - onsides + : 1; + + var lastClkbl = firstClkbl + 2*onsides < pages + ? firstClkbl + 2*onsides + : pages; + + var prev = '<< Prev | '; + if (curPage > 1) + prev = ' | '; + + var middle = ''; + for(var i = firstClkbl; i <= lastClkbl; i++) { + var numLabel = i; + if(i == curPage) + numLabel = '' + i + ''; + + middle += ' ' + + numLabel + ' '; + } + + var next = ' | Next >>'; + if (pages - curPage > 0) + next = ' | '; + + var predots = ''; + if (firstClkbl > 1) + predots = '...'; + + var postdots = ''; + if (lastClkbl < pages) + postdots = '...'; + + pagerDiv.innerHTML += '
' + + prev + predots + middle + postdots + next + '

'; +} + +function showPage (pageNum) +{ + curPage = pageNum; + my_paz.showPage( curPage - 1 ); +} + +// 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.'); + } +} + +// detailed record drawing +function showDetails (prefixRecId) { + var recId = prefixRecId.replace('rec_', ''); + var oldRecId = curDetRecId; + curDetRecId = recId; + + // remove current detailed view if any + var detRecordDiv = document.getElementById('det_'+oldRecId); + // lovin DOM! + if (detRecordDiv) + detRecordDiv.parentNode.removeChild(detRecordDiv); + + // if the same clicked, just hide + if (recId == oldRecId) { + curDetRecId = ''; + curDetRecData = null; + return; + } + // request the record + my_paz.record(recId); +} + +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 details = '
'; + if (marker) details += ''; + if (data["md-title"] != undefined) { + details += ''; + } + if (data["md-date"] != undefined) + details += ''; + if (data["md-author"] != undefined) + details += ''; + if (data["md-electronic-url"] != undefined) + details += ''; + if (data["location"][0]["md-subject"] != undefined) + details += ''; + if (data["location"][0]["@name"] != undefined) + details += ''; + details += '
'+ marker + '
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 += '
Date: ' + data["md-date"] + '
Author: ' + data["md-author"] + '
URL: ' + data["md-electronic-url"] + '' + '
Subject: ' + data["location"][0]["md-subject"] + '
Location: ' + data["location"][0]["@name"] + " (" +data["location"][0]["@id"] + ")" + '
'; + return details; +} + + +$(document).ready(function() { + domReady(); + var jqxhr = jQuery.get("/service-proxy-auth") + .fail(function() { alert("service proxy authentifiction failed"); }); +});