Merge branch 'bytarget_block' of ssh://git.indexdata.com/home/git/pub/pazpar2 into...
[pazpar2-moved-to-github.git] / www / iphone / example_client.js
index 336739b..e6af70c 100644 (file)
@@ -5,16 +5,17 @@
 // 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 pazpar2path = '/service-proxy/';
 var showResponseType = '';
 var querys = {'su': '', 'au': '', 'xt': ''};
-
-if (document.location.hash == '#useproxy' || document.location.search.match("useproxy=true")) {
+var showResponseType = 'json';
+if (document.location.hash == '#pazpar2' || document.location.search.match("useproxy=false")) {
     usesessions = false;
-    pazpar2path = '/service-proxy/';
+    pazpar2path = '/pazpar2/search.pz2';
     showResponseType = 'xml';
 }
 
+
 my_paz = new pz2( { "onshow": my_onshow,
                     "showtime": 500,            //each timer (show, stat, term, bytarget) can be specified this way
                     "pazpar2path": pazpar2path,
@@ -80,25 +81,25 @@ function login() {
 }
 
 function logout() {
-    auth.logOut(loggedOut, loggingOutFailed, false);
+    auth.logOut(loggedOut, loggingOutFailed, true);
 }
 
 function logInOrOut() {
     var loginElement = document.getElementById("login");
     if (loginElement.innerHTML == 'Login')
-       login();
+       login();
     else
-       logout();
+       logout();
 }
 function loggedIn() {
     var login = document.getElementById("login");
-    login.innerHTML = 'Logout';
-    //    login.onclick = 'logout();';
-    domReady();
+    login.innerHTML = 'Logout(' + auth.displayName + ')';
+    document.getElementById("log").innerHTML = login.innerHTML;
 }
 
 function auth_check() {
-    auth.check(loggedIn, login, false);
+    auth.check(loggedIn, login);
+    domReady();
 }
 
 //
@@ -123,6 +124,8 @@ function my_onshow(data) {
     var results = document.getElementById("results");
   
     var html = [];
+    if (data.hits == undefined) 
+       return ; 
     for (var i = 0; i < data.hits.length; i++) {
         var hit = data.hits[i];
              html.push('<li id="recdiv_'+hit.recid+'" >'
@@ -246,27 +249,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);
@@ -287,7 +269,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");
 }
 
@@ -356,18 +337,22 @@ function domReady ()
  
 function applicationMode(newmode) 
 {
-       var searchdiv = document.getElementById("searchForm");
-       if (newmode)
-               inApp = newmode;
-       if (inApp) {
+    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();
+    }
+    else { 
+       
+       document.getElementById("nav").style.display="";
+       document.getElementById("normal").style.display="inline";
+       document.getElementById("normal").style.visibility="";
+       searchdiv.style.display = '';
+       document.search.onsubmit = onFormSubmit;
+    }
+    callback.init();
 }
 // when search button pressed
 function onFormSubmitEventHandler() 
@@ -416,14 +401,14 @@ function limitQuery(field, value)
     showhide("recordview");
 }
 
-//limit the query after clicking the facet
+// 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
+// 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);
@@ -640,7 +625,8 @@ function renderDetails_iphone(data, marker)
 {
        //return renderDetails(data,marker);
 
-
+    if (!data) 
+       return ""; 
     var details = '<div class="details" id="det_'+data.recid+'" >'
 /*
     details = '<div id="header" id="det_'+data.recid+'">'