From 68b7620cc5510380ffbccda64ef28c985cde2fa9 Mon Sep 17 00:00:00 2001 From: Dennis Schafroth Date: Thu, 10 Nov 2011 18:51:23 +0100 Subject: [PATCH] Created a simple paging/More records --- www/iphone/example_client.js | 56 +++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/www/iphone/example_client.js b/www/iphone/example_client.js index 18feaa9..a336f8e 100644 --- a/www/iphone/example_client.js +++ b/www/iphone/example_client.js @@ -34,7 +34,10 @@ my_paz = new pz2( { "onshow": my_onshow, "onrecord": my_onrecord } ); // some state vars var curPage = 1; -var recPerPage = 20; +var recPerPage = 100; +var recToShowPageSize = 20; +var recToShow = recToShowPageSize; +var recIDs = {}; var totalRec = 0; var curDetRecId = ''; var curDetRecData = null; @@ -135,6 +138,21 @@ function my_oninit() { my_paz.bytarget(); } +function showMoreRecords() { + var i = recToShow; + recToShow += recToShowPageSize; + for ( ; i < recToShow && i < recPerPage; i++) { + var element = document.getElementById(recIDs[i]); + if (element) + element.style.display = ''; + } + if (i == recPerPage) { + var element = document.getElementById('recdiv_END'); + if (element) + element.style.display = 'none'; + } +} + function my_onshow(data) { totalRec = data.merged; // move it out @@ -147,28 +165,40 @@ function my_onshow(data) { drawPager(pager); var results = document.getElementById("results"); - + var html = []; if (data.hits == undefined) - return ; + return ; + var style = ''; 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-responsibility"] !== undefined) { + var recID = "recdiv_" + hit.recid; + //var recID = "recdiv_" + i; + recIDs[i] = recID; + if (i == recToShow) + style = ' style="display:none" '; + html.push('
  • ' + +'' + + hit["md-title"] +' '); + if (hit["md-title-responsibility"] !== undefined) { html.push(''+hit["md-title-responsibility"]+' '); - if (hit["md-title-remainder"] !== undefined) { + if (hit["md-title-remainder"] !== undefined) { html.push('' + hit["md-title-remainder"] + ' '); - } + } } if (hit.recid == curDetRecId) { html.push(renderDetails_iphone(curDetRecData)); } - html.push(''); + html.push('
  • '); } + // set up "More..." if needed. + style = 'display:none'; + if (recToShow < recPerPage) { + style = 'display:block'; + } + html.push('
  • More...
  • '); + replaceHtml(results, html.join('')); } @@ -417,6 +447,8 @@ function getFacets() { function triggerSearch () { + // Restore to initial page size + recToShow = recToShowPageSize; my_paz.search(document.search.query.value, recPerPage, curSort, curFilter, undefined, { "limit" : getFacets() -- 1.7.10.4