X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=www%2Fiphone%2Fexample_client.js;h=a131b8ab55b3b5c32dad4fb86e7836eb8fe92631;hb=838ce61b876f3a575182ab6048a8e2686f093738;hp=fd9c37ee8eded2de4dadbbff82324efe729656ad;hpb=d7f1c93a49111cc48e2c78c1796472509b8397fe;p=pazpar2-moved-to-github.git
diff --git a/www/iphone/example_client.js b/www/iphone/example_client.js
index fd9c37e..a131b8a 100644
--- a/www/iphone/example_client.js
+++ b/www/iphone/example_client.js
@@ -7,10 +7,12 @@
var usesessions = true;
var pazpar2path = '/pazpar2/search.pz2';
var showResponseType = '';
-if (document.location.hash == '#useproxy') {
+var querys = {'su': '', 'au': '', 'xt': ''};
+
+if (document.location.hash == '#useproxy' || document.location.search.match("useproxy=true")) {
usesessions = false;
pazpar2path = '/service-proxy/';
- showResponseType = 'json';
+ showResponseType = 'xml';
}
my_paz = new pz2( { "onshow": my_onshow,
@@ -18,10 +20,10 @@ my_paz = new pz2( { "onshow": my_onshow,
"pazpar2path": pazpar2path,
"oninit": my_oninit,
"onstat": my_onstat,
- "onterm": my_onterm,
+ "onterm": my_onterm_iphone,
"termlist": "xtargets,subject,author",
"onbytarget": my_onbytarget,
- "usesessions" : usesessions,
+ "usesessions" : usesessions,
"showResponseType": showResponseType,
"onrecord": my_onrecord } );
// some state vars
@@ -36,6 +38,8 @@ var submitted = false;
var SourceMax = 16;
var SubjectMax = 10;
var AuthorMax = 10;
+var tab = "recordview";
+
//
// pz2.js event handlers:
@@ -55,25 +59,25 @@ function my_onshow(data) {
' 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)) +'. '
+ html.push('
'
+ /* +''+ (i + 1 + recPerPage * (curPage - 1)) +'. ' */
+''
- + hit["md-title"] +' ');
- if (hit["md-title-remainder"] !== undefined) {
- html.push('' + hit["md-title-remainder"] + ' ');
- }
+ +'" onclick="showDetails(this.id);return false;">'
+ + hit["md-title"] +' ');
if (hit["md-title-responsibility"] !== undefined) {
- html.push(''+hit["md-title-responsibility"]+'');
+ html.push(''+hit["md-title-responsibility"]+' ');
+ if (hit["md-title-remainder"] !== undefined) {
+ html.push('' + hit["md-title-remainder"] + ' ');
+ }
}
if (hit.recid == curDetRecId) {
- html.push(renderDetails(curDetRecData));
+ html.push(renderDetails_iphone(curDetRecData));
}
html.push(' ');
}
@@ -92,31 +96,143 @@ function my_onstat(data) {
+ '/' + data.hits + ' :.';
}
+function showhide(newtab) {
+ var showtermlist = false;
+ if (newtab != null)
+ tab = newtab;
+
+ if (tab == "recordview") {
+ document.getElementById("recordview").style.display = '';
+ }
+ else
+ document.getElementById("recordview").style.display = 'none';
+
+ if (tab == "xtargets") {
+ document.getElementById("term_xtargets").style.display = '';
+ showtermlist = true;
+ }
+ else
+ document.getElementById("term_xtargets").style.display = 'none';
+
+ if (tab == "subjects") {
+ document.getElementById("term_subjects").style.display = '';
+ showtermlist = true;
+ }
+ else
+ document.getElementById("term_subjects").style.display = 'none';
+
+ if (tab == "authors") {
+ document.getElementById("term_authors").style.display = '';
+ showtermlist = true;
+ }
+ else
+ document.getElementById("term_authors").style.display = 'none';
+
+ if (showtermlist == false)
+ document.getElementById("termlist").style.display = 'none';
+ else
+ document.getElementById("termlist").style.display = '';
+}
+
function my_onterm(data) {
var termlists = [];
- termlists.push('
TERMLISTS:
.::Sources
');
+
+ termlists.push('');
+ termlists.push('
Sources
');
+ termlists.push('
');
+ termlists.push('
');
- termlists.push('
.::Subjects
');
+ termlists.push('');
+ termlists.push('
Subjects
');
+ termlists.push('
');
+ termlists.push('
');
+
+ termlists.push('');
+ termlists.push('
Authors
');
+ termlists.push('
');
+ termlists.push('
');
var termlist = document.getElementById("termlist");
replaceHtml(termlist, termlists.join(''));
+ showhide();
+}
+
+function serialize(array) {
+ var t = typeof (obj);
+ if (t != "object" || obj === null) {
+ // simple data type
+ return String(obj);
+ } else {
+ // recurse array or object
+ var n, v, json = [], arr = (obj && obj.constructor == Array);
+ for (n in obj) {
+ v = obj[n];
+ t = typeof (v);
+ if (t == "string")
+ v = '"' + v + '"';
+ else if (t == "object" && v !== null)
+ v = JSON.stringify(v);
+ json.push((arr ? "" : '"' + n + '":') + String(v));
+ }
+ return (arr ? "" : "") + String(json) + (arr ? "]" : "}");
+ }
+}
+
+var termlist = {};
+function my_onterm_iphone(data) {
+ my_onterm(data);
+ var targets = "reset_xt|All\n";
+
+ for (var i = 0; i < data.xtargets.length; i++ ) {
+
+ targets = targets + data.xtargets[i].id + "|" + data.xtargets[i].name + "|" + data.xtargets[i].freq + "\n";
+ }
+ termlist["xtargets"] = targets;
+ var subjects = "reset_su|All\n";
+ for (var i = 0; i < data.subject.length; i++ ) {
+ subjects = subjects + "su" + "|" + data.subject[i].name + "|" + data.subject[i].freq + "\n";
+ }
+ termlist["subjects"] = subjects;
+ var authors = "reset_au|All\n";
+ for (var i = 0; i < data.author.length; i++ ) {
+ authors = authors + "au" + "|" + data.author[i].name + "|" + data.author[i].freq + "\n";
+ }
+ termlist["authors"] = authors;
+ //document.getElementById("log").innerHTML = targets + "\n" + subjects + "\n" + authors;
+ callback.send("termlist", "refresh");
+}
+
+function getTargets() {
+ return termlist['xtargets'];
+}
+
+function getSubjects() {
+ return termlist['subjects'];
+}
+
+function getAuthors() {
+ return termlist['authors'];
}
function my_onrecord(data) {
@@ -127,10 +243,16 @@ function my_onrecord(data) {
if (detRecordDiv) return;
curDetRecData = data;
var recordDiv = document.getElementById('recdiv_'+curDetRecData.recid);
- var html = renderDetails(curDetRecData);
+ var html = renderDetails_iphone(curDetRecData);
recordDiv.innerHTML += html;
}
+function my_onrecord_iphone(data) {
+ my_onrecord(data);
+ callback.send("record", data.recid, data, data.xtargets[i].freq);
+}
+
+
function my_onbytarget(data) {
var targetDiv = document.getElementById("bytarget");
var table ='Target ID | Hits | Diags | '
@@ -158,12 +280,32 @@ function domReady ()
document.search.query.value = '';
document.select.sort.onchange = onSelectDdChange;
document.select.perpage.onchange = onSelectDdChange;
+ if (document.location.search.match("inApp=true"))
+ applicationMode(true);
+ else
+ applicationMode(false);
+}
+
+function applicationMode(newmode)
+{
+ var searchdiv = document.getElementById("searchForm");
+ if (newmode)
+ inApp = newmode;
+ if (inApp) {
+ document.getElementById("heading").style.display="none";
+ searchdiv.style.display = 'none';
+ }
+ else {
+ searchdiv.style.display = '';
+ document.search.onsubmit = onFormSubmit;
+ }
+ callback.init();
}
-
// when search button pressed
function onFormSubmitEventHandler()
{
resetPage();
+ document.getElementById("logo").style.display = 'none';
loadSelect();
triggerSearch();
submitted = true;
@@ -197,31 +339,49 @@ function loadSelect ()
}
// limit the query after clicking the facet
-function limitQuery (field, value)
+function limitQuery(field, value)
{
- document.search.query.value += ' and ' + field + '="' + value + '"';
+ var newQuery = ' and ' + field + '="' + value + '"';
+ querys[field] += newQuery;
+ document.search.query.value += newQuery;
onFormSubmitEventHandler();
+ showhide("recordview");
+}
+
+//limit the query after clicking the facet
+function removeQuery (field, value) {
+ document.search.query.value.replace(' and ' + field + '="' + value + '"', '');
+ onFormSubmitEventHandler();
+ showhide("recordview");
+}
+
+//limit the query after clicking the facet
+function limitOrResetQuery (field, value, selected) {
+ if (field == 'reset_su' || field == 'reset_au') {
+ var reset_field = field.substring(6);
+ document.search.query.value = document.search.query.value.replace(querys[reset_field], '');
+ querys[reset_field] = '';
+ onFormSubmitEventHandler();
+ showhide("recordview");
+ }
+ else
+ limitQuery(field, value);
+ //alert("limitOrResetQuerry: query after: " + document.search.query.value);
}
// 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();
+ showhide("recordview");
return false;
}
function delimitTarget ()
{
- var navi = document.getElementById('navi');
- navi.innerHTML = '';
curFilter = null;
resetPage();
loadSelect();
@@ -229,6 +389,15 @@ function delimitTarget ()
return false;
}
+function limitOrResetTarget(id, name) {
+ if (id == 'reset_xt') {
+ delimitTarget();
+ }
+ else {
+ limitTarget(id,name);
+ }
+}
+
function drawPager (pagerDiv)
{
//client indexes pages from 1 but pz2 from 0
@@ -271,7 +440,7 @@ function drawPager (pagerDiv)
if (lastClkbl < pages)
postdots = '...';
- pagerDiv.innerHTML += ''
+ pagerDiv.innerHTML += '
'
+ prev + predots + middle + postdots + next + '
';
}
@@ -324,6 +493,7 @@ function showDetails (prefixRecId) {
// remove current detailed view if any
var detRecordDiv = document.getElementById('det_'+oldRecId);
+ //alert("oldRecId: " + oldRecId + " " + detRecordDiv != null);
// lovin DOM!
if (detRecordDiv)
detRecordDiv.parentNode.removeChild(detRecordDiv);
@@ -379,4 +549,61 @@ function renderDetails(data, marker)
details += '
';
return details;
}
- //EOF
+
+function renderLine(title, value) {
+ if (value != undefined)
+ return '' + title + '
' + value + '';
+ return '';
+}
+
+function renderLineURL(title, URL, display) {
+ if (URL != undefined)
+ return '' + title + '
' + display + '';
+ return '';
+}
+
+function renderLineEmail(dtitle, email, display) {
+ if (email != undefined)
+ return '' + title + '
' + display + '';
+ return '';
+}
+
+function renderDetails_iphone(data, marker)
+{
+ //return renderDetails(data,marker);
+
+
+ var details = ''
+/*
+ details = '';
+*/
+ if (marker)
+ details += '
'+ marker + '
';
+ details += '
';
+ 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 += ''
+ details += ' '
+ }
+ details
+ +=renderLine('Date', data["md-date"])
+ + renderLine('Author', data["md-author"])
+ + renderLineURL('URL', data["md-electronic-url"], data["md-electronic-url"])
+ + renderLine('Subject', data["location"][0]["md-subject"]);
+
+ if (data["location"][0]["@name"] != undefined)
+ details += renderLine('Location', data["location"][0]["@name"] + " (" +data["location"][0]["@id"] + ")");
+ details += '
';
+ return details;
+}
+
+//EOF