X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=www%2Fiphone%2Fexample_client.js;h=9761e831996dcb6ebcedc53d1438c9d6941e5e9a;hb=01f19b8c3664fa1c78d1fb9efb8e358d50f85c39;hp=4edf65ca62036d351dcf96ee0c35418b66ab477f;hpb=284eaefa1c5e4bceadc4a0dba031cdf755822144;p=pazpar2-moved-to-github.git diff --git a/www/iphone/example_client.js b/www/iphone/example_client.js index 4edf65c..9761e83 100644 --- a/www/iphone/example_client.js +++ b/www/iphone/example_client.js @@ -9,12 +9,13 @@ var pazpar2path = '/pazpar2/search.pz2'; var showResponseType = ''; var querys = {'su': '', 'au': '', 'xt': ''}; -if (document.location.hash == '#useproxy') { +if (document.location.hash == '#useproxy' || document.location.search.match("useproxy=true")) { 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, @@ -23,7 +24,7 @@ my_paz = new pz2( { "onshow": my_onshow, "onterm": my_onterm_iphone, "termlist": "xtargets,subject,author", "onbytarget": my_onbytarget, - "usesessions" : usesessions, + "usesessions" : usesessions, "showResponseType": showResponseType, "onrecord": my_onrecord } ); // some state vars @@ -33,16 +34,76 @@ var totalRec = 0; var curDetRecId = ''; var curDetRecData = null; var curSort = 'relevance'; -var curFilter = null; +var curFilter = 'ALL'; var submitted = false; var SourceMax = 16; var SubjectMax = 10; var AuthorMax = 10; var tab = "recordview"; +var triedPass = ""; +var triedUser = ""; + +function loginFormSubmit() { + triedUser = document.loginForm.username.value; + triedPass = document.loginForm.password.value; + auth.login( {"username": triedUser, + "password": triedPass}, + authCb, authCb); +} + +function authCb(authData) { + if (!authData.loginFailed) { + triedUser = ""; + triedPass = ""; + } + + if (authData.loggedIn == true) { + showhide("recordview"); + } +} + +function logOutClick() { + auth.logOut(authCb, authCb); +} + +function loggedOut() { + var login = document.getElementById("login"); + login.innerHTML = 'Login'; +} + +function loggingOutFailed() { + alert("Logging out failed"); +} + +function login() { + showhide("login"); +} + +function logout() { + auth.logOut(loggedOut, loggingOutFailed, true); +} + +function logInOrOut() { + var loginElement = document.getElementById("login"); + if (loginElement.innerHTML == 'Login') + login(); + else + logout(); +} +function loggedIn() { + var login = document.getElementById("login"); + login.innerHTML = 'Logout(' + auth.displayName + ')'; + document.getElementById("log").innerHTML = login.innerHTML; +} + +function auth_check() { + auth.check(loggedIn, login, true); + domReady(); +} // -// pz2.js event handlers: +// Pz2.js event handlers: // function my_oninit() { my_paz.stat(); @@ -97,41 +158,49 @@ function my_onstat(data) { } function showhide(newtab) { - var showtermlist = false; - if (newtab != null) - tab = 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 == "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 == "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 == "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 (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 = ''; - if (showtermlist == false) - document.getElementById("termlist").style.display = 'none'; - else - document.getElementById("termlist").style.display = ''; + var tabDiv = document.getElementById("loginDiv"); + if (tab == "login") { + tabDiv.style.display = ''; + } + else { + tabDiv.style.display = 'none'; + } } function my_onterm(data) { @@ -178,27 +247,6 @@ function my_onterm(data) { 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); @@ -219,7 +267,6 @@ function my_onterm_iphone(data) { 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"); } @@ -282,6 +329,8 @@ function domReady () document.select.perpage.onchange = onSelectDdChange; if (document.location.search.match("inApp=true")) applicationMode(true); + else + applicationMode(false); } function applicationMode(newmode) @@ -294,6 +343,7 @@ function applicationMode(newmode) searchdiv.style.display = 'none'; } else { + document.getElementById("nav").style.display=""; searchdiv.style.display = ''; document.search.onsubmit = onFormSubmit; } @@ -303,10 +353,11 @@ function applicationMode(newmode) function onFormSubmitEventHandler() { resetPage(); + document.getElementById("logo").style.display = 'none'; loadSelect(); triggerSearch(); submitted = true; - return false; + return true; } function onSelectDdChange() @@ -379,7 +430,7 @@ function limitTarget (id, name) function delimitTarget () { - curFilter = null; + curFilter = 'ALL'; resetPage(); loadSelect(); triggerSearch(); @@ -490,6 +541,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); @@ -568,8 +620,9 @@ function renderDetails_iphone(data, marker) { //return renderDetails(data,marker); - - var details = '' + if (!data) + return ""; + var details = '
' /* details = ''; return details; }