Use md-author if present instead of md-title-responsibility. Swap title-remainder...
[pazpar2-moved-to-github.git] / www / iphone / example_client.js
index b24561f..ea74e67 100644 (file)
@@ -5,18 +5,16 @@
 // 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/';
-    showResponseType = 'json';
+    pazpar2path = '/pazpar2/search.pz2';
+    showResponseType = 'xml';
 }
 
-if (this.JSON )
-       alert("Native JSON support");
 
 my_paz = new pz2( { "onshow": my_onshow,
                     "showtime": 500,            //each timer (show, stat, term, bytarget) can be specified this way
@@ -54,6 +52,26 @@ function loginFormSubmit() {
        authCb, authCb);
 }
 
+function handleKeyPress(e, formId, focusId)  
+{  
+  var key;  
+  if(window.event)  
+    key = window.event.keyCode;  
+  else  
+    key = e.which;  
+
+  if(key == 13 || key == 10)  
+  {  
+    document.getElementById(formId).submit();  
+    focusElement = document.getElementById(focusId);
+    if (focusElement)
+      focusElement.focus();  
+    return false;  
+  }  
+  else  
+    return true;  
+}  
+
 function authCb(authData) {
     if (!authData.loginFailed) {
        triedUser = "";
@@ -95,11 +113,12 @@ function logInOrOut() {
 }
 function loggedIn() {
     var login = document.getElementById("login");
-    login.innerHTML = 'Logout';
+    login.innerHTML = 'Logout(' + auth.displayName + ')';
+    document.getElementById("log").innerHTML = login.innerHTML;
 }
 
 function auth_check() {
-    auth.check(loggedIn, login, true);
+    auth.check(loggedIn, login);
     domReady();
 }
 
@@ -125,6 +144,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+'" >'
@@ -132,10 +153,13 @@ function my_onshow(data) {
             +'<a href="#" id="rec_'+hit.recid
             +'" onclick="showDetails(this.id);return false;">' 
             + hit["md-title"] +'</a> '); 
-             if (hit["md-title-responsibility"] !== undefined) {
-           html.push('<a href="#">'+hit["md-title-responsibility"]+'</a> ');
              if (hit["md-title-remainder"] !== undefined) {
-               html.push('<a href="#">' + hit["md-title-remainder"] + ' </a> ');
+                 html.push('<a href="#">' + hit["md-title-remainder"] + ' </a> ');
+             if (hit["md-author"] != undefined) {
+                 html.push('<a href="#">'+hit["md-author"]+'</a> ');
+             }
+             else if (hit["md-title-responsibility"] !== undefined) {
+                 html.push('<a href="#">'+hit["md-title-responsibility"]+'</a> ');
              }
        }
         if (hit.recid == curDetRecId) {
@@ -268,7 +292,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");
 }
 
@@ -337,19 +360,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 { 
-           document.getElementById("nav").style.display="";
-               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() 
@@ -380,6 +406,13 @@ function resetPage()
 function triggerSearch ()
 {
     my_paz.search(document.search.query.value, recPerPage, curSort, curFilter);
+/*
+    , startWith,
+       {
+          "limit" : getFacets() 
+       }
+       );
+*/
 }
 
 function loadSelect ()
@@ -391,21 +424,21 @@ function loadSelect ()
 // limit the query after clicking the facet
 function limitQuery(field, value)
 {
-       var newQuery = ' and ' + field + '="' + value + '"';
-       querys[field] += newQuery;
-    document.search.query.value += newQuery;
-    onFormSubmitEventHandler();
-    showhide("recordview");
+  var newQuery = ' and ' + field + '="' + value + '"';
+  querys[field] += newQuery;
+  document.search.query.value += newQuery;
+  onFormSubmitEventHandler();
+  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);
@@ -581,8 +614,8 @@ function renderDetails(data, marker)
        if (data["md-title-remainder"] !== undefined) {
              details += ' : <span>' + data["md-title-remainder"] + ' </span>';
        }
-       if (data["md-title-responsibility"] !== undefined) {
-             details += ' <span><i>'+ data["md-title-responsibility"] +'</i></span>';
+       if (data["md-author"] !== undefined) {
+             details += ' <span><i>'+ data["md-auhtor"] +'</i></span>';
        }
          details += '</td></tr>';
     }
@@ -622,7 +655,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+'">' 
@@ -638,7 +672,9 @@ function renderDetails_iphone(data, marker)
         if (data["md-title-remainder"] !== undefined) {
              details += ' ' + data["md-title-remainder"] + ' ';
         }
-        if (data["md-title-responsibility"] !== undefined) {
+        if (data["md-author"] !== undefined) {
+             details += '<i>'+ data["md-author"] +'</i>';
+        } else if (data["md-title-responsibility"] !== undefined) {
              details += '<i>'+ data["md-title-responsibility"] +'</i>';
         }
         details += '</big>'