From: Dennis Schafroth Date: Mon, 31 May 2010 07:11:41 +0000 (+0200) Subject: iPhone UI and client demo X-Git-Tag: v1.4.2~7^2~39 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=d7f1c93a49111cc48e2c78c1796472509b8397fe;p=pazpar2-moved-to-github.git iPhone UI and client demo Some test for embedding a HTML page in an iPhone. - Example of calling javascript from objective-c - Example of calling objective-c from javascript --- diff --git a/www/iphone/example_client.js b/www/iphone/example_client.js new file mode 100644 index 0000000..fd9c37e --- /dev/null +++ b/www/iphone/example_client.js @@ -0,0 +1,382 @@ +/* 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 usesessions = true; +var pazpar2path = '/pazpar2/search.pz2'; +var showResponseType = ''; +if (document.location.hash == '#useproxy') { + usesessions = false; + pazpar2path = '/service-proxy/'; + showResponseType = 'json'; +} + +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, + "onstat": my_onstat, + "onterm": my_onterm, + "termlist": "xtargets,subject,author", + "onbytarget": my_onbytarget, + "usesessions" : usesessions, + "showResponseType": showResponseType, + "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) + var 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) + var next = ' | '; + + predots = ''; + if (firstClkbl > 1) + predots = '...'; + + 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; +} + //EOF diff --git a/www/iphone/index.html b/www/iphone/index.html new file mode 100644 index 0000000..01a13d8 --- /dev/null +++ b/www/iphone/index.html @@ -0,0 +1,100 @@ + + + + + + + Pazpar2 demo client + + + + + + + +
+ +
+ + + +
+ + + + + + +
+
+ + +
+
+
+ +
+ + + + + +
+ +
+ +
+
+
+ + + + + + + diff --git a/www/iphone/index2.html b/www/iphone/index2.html new file mode 100644 index 0000000..3bbc190 --- /dev/null +++ b/www/iphone/index2.html @@ -0,0 +1,60 @@ + + + + + + + Pazpar2 demo client + + + + + + + +
+
+
+ callback +
+ + + diff --git a/www/iphone/indexdata_logo.png b/www/iphone/indexdata_logo.png new file mode 100644 index 0000000..171c039 Binary files /dev/null and b/www/iphone/indexdata_logo.png differ diff --git a/www/iphone/styles.css b/www/iphone/styles.css new file mode 100644 index 0000000..e6cd2b0 --- /dev/null +++ b/www/iphone/styles.css @@ -0,0 +1,110 @@ +html { + overflow-y: scroll; + font-size: 12px; +} + +body { + font-family: tahoma, arial, sans-serif; + color: #156a16; +} + +hr { + border: 0; + color: #156a16; + background-color: #156a16; + height: 1px; +} + +thead { + font-weight: bold; +} + +a { + color: #005701; + text-decoration: none; +} + +a.extern { + color: #CC6600; +} + +a:hover { + text-decoration: underline; +} + +a.crossout:hover { + text-decoration: line-through; + font-weight: bold; +} + + +#heading { + background-color: #87c9af; + border-top: 1px solid #156a16; + color: #ffffff; + font-size: large; +} + +input#button { + border: 3px outset #132194; + background-color: #132194; + padding: 2px; + width: 6em; + color: #FFFFFF; + font-weight: bold; + text-transform: uppercase; + font-size: 10px; + margin-left: 8px; + cursor: pointer; +} + +input#query { + border: 2px inset #34cc67; + padding: 3px; + font-size: 12px; +} + +div.termtitle { + margin: 4px; + font-weight: bold; +} + +div.record { + padding: 5px; +} + +div.details { + border: 3px dashed gray; + color: gray; + padding: 5px; + margin: 4px; +} + +#switchmenu { + padding-bottom: 3px; + text-align: right; +} + +#recordview { + background-color: #fafafa; + border-bottom: 1px solid #156a16; +} + +#targetview { + background-color: #fafafa; + border-bottom: 1px solid #156a16; +} + +#bytarget { + padding: 7px; +} + +#footer { + padding-top: 4px; + color: #74c775; + text-align: center; +} + +#stat { + font-weight: bold; +}