From: Dennis Schafroth Date: Tue, 22 Nov 2011 17:19:16 +0000 (+0100) Subject: Add error handler. Reworked detail view. Added Pager. X-Git-Tag: v1.6.6~26 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=b13f0a61bf7ba99531087dad4ba048cd0d8d4751;p=pazpar2-moved-to-github.git Add error handler. Reworked detail view. Added Pager. --- diff --git a/www/iphone/example_client.js b/www/iphone/example_client.js index e447c9e..e713b06 100644 --- a/www/iphone/example_client.js +++ b/www/iphone/example_client.js @@ -33,10 +33,12 @@ my_paz = new pz2( { "onshow": my_onshow, "onbytarget": null, "usesessions" : usesessions, "showResponseType": showResponseType, - "onrecord": my_onrecord } ); + "onrecord": my_onrecord, + "errorhandler" : my_onerror} +); // some state vars var curPage = 1; -var recPerPage = 100; +var recPerPage = 10; var recToShowPageSize = 20; var recToShow = recToShowPageSize; var recIDs = {}; @@ -54,6 +56,28 @@ var tab = "recordview"; var triedPass = ""; var triedUser = ""; +// +// pz2.js event handlers: +// +function my_onerror(error) { + switch(error.code) { + // No targets! + case "8": alert("No resources were selected for the search"); break; + // target not configured, this is a pazpar2 bug + // but for now simply research + case "9": + triggerSearch(); + break; + // authentication + case "100" : + auth.check(loggedIn, login); + //window.location = "login.html"; break; + default: + alert("Unhandled error: " + error.code); + throw error; // display error in JavaScript console + } +} + function loginFormSubmit() { triedUser = document.loginForm.username.value; triedPass = document.loginForm.password.value; @@ -123,7 +147,7 @@ function logInOrOut() { } function loggedIn() { var login = document.getElementById("login"); - login.innerHTML = 'Logout(' + auth.displayName + ')'; + login.innerHTML = 'Logout'; document.getElementById("log").innerHTML = login.innerHTML; } @@ -189,11 +213,11 @@ function my_onshow(data) { // move it out var pager = document.getElementById("pager"); pager.innerHTML = ""; - pager.innerHTML +='
Displaying: ' + drawPager(pager); + pager.innerHTML +='
Displaying: ' + (data.start + 1) + ' to ' + (data.start + data.num) + ' of ' + data.merged + ' (found: ' + data.total + ')
'; - drawPager(pager); var results = document.getElementById("results"); @@ -262,14 +286,16 @@ function my_onshow(data) { */ html.push(''); } - document.getElementById("loading").style.display = 'none'; + if (data.activeclients == 0) + document.getElementById("loading").style.display = 'none'; +/* // set up "More..." if needed. style = 'display:none'; if (recToShow < recPerPage) { style = 'display:block'; } html.push('
  • More...
  • '); - +*/ replaceHtml(results, html.join('')); } @@ -372,7 +398,7 @@ function my_onterm(data) { termlists.push('
    '); termlists.push('

    Authors

    '); termlists.push('
    '; return details; }