Fix closing tag in iphone details. Remove the div navi.
[pazpar2-moved-to-github.git] / www / iphone / example_client.js
index 64843f0..4edf65c 100644 (file)
@@ -7,6 +7,8 @@
 var usesessions = true;
 var pazpar2path = '/pazpar2/search.pz2';
 var showResponseType = '';
+var querys = {'su': '', 'au': '', 'xt': ''};
+
 if (document.location.hash == '#useproxy') {
     usesessions = false;
     pazpar2path = '/service-proxy/';
@@ -57,7 +59,7 @@ function my_onshow(data) {
                      ' of ' + data.merged + ' (found: ' 
                      + data.total + ')</div>';
     drawPager(pager);
-    // navi
+
     var results = document.getElementById("results");
   
     var html = [];
@@ -75,7 +77,7 @@ function my_onshow(data) {
              }
        }
         if (hit.recid == curDetRecId) {
-            html.push(renderDetails(curDetRecData));
+            html.push(renderDetails_iphone(curDetRecData));
         }
        html.push('</div>');
     }
@@ -111,12 +113,14 @@ function showhide(newtab) {
        }
        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 == "authors") {
                document.getElementById("term_authors").style.display = '';
                showtermlist = true;
@@ -134,44 +138,43 @@ function my_onterm(data) {
     var termlists = [];
     
     termlists.push('<div id="term_xtargets" >');
-    termlists.push('<div class="termtitle">.::Sources</div>');
+    termlists.push('<h4 class="termtitle">Sources</h4>');
+    termlists.push('<ul>');
+    termlists.push('<li><a href="#" target_id="reset_xt" onclick="limitOrResetTarget(\'reset_xt\',\'All\');return false;">All</a></li>');
     for (var i = 0; i < data.xtargets.length && i < SourceMax; i++ ) {
-        termlists.push('<a href="#" target_id='+data.xtargets[i].id
-            + ' onclick="limitTarget(this.getAttribute(\'target_id\'), this.firstChild.nodeValue);return false;">' + data.xtargets[i].name 
-        + ' </a><span> (' + data.xtargets[i].freq + ')</span><br/>');
+        termlists.push('<li><a href="#" target_id='+data.xtargets[i].id
+            + ' onclick="limitOrResetTarget(this.getAttribute(\'target_id\'), \'' + data.xtargets[i].name + '\');return false;">' 
+           + data.xtargets[i].name + ' (' + data.xtargets[i].freq + ')</a></li>');
     }
+    termlists.push('</ul>');
     termlists.push('</div>');
      
     termlists.push('<div id="term_subjects" >');
-    termlists.push('<div id="subjects" class="termtitle">.::Subjects</div>');
+    termlists.push('<h4>Subjects</h4>');
+    termlists.push('<ul>');
+    termlists.push('<li><a href="#" target_id="reset_su" onclick="limitOrResetQuery(\'reset_su\',\'All\');return false;">All</a></li>');
     for (var i = 0; i < data.subject.length && i < SubjectMax; i++ ) {
-        termlists.push('<a href="#" onclick="limitQuery(\'su\', this.firstChild.nodeValue);return false;">' + data.subject[i].name + '</a><span>  (' 
-              + data.subject[i].freq + ')</span><br/>');
+        termlists.push('<li><a href="#" onclick="limitOrResetQuery(\'su\', \'' + data.subject[i].name + '\');return false;">' 
+                      + data.subject[i].name + ' (' + data.subject[i].freq + ')</a></li>');
     }
+    termlists.push('</ul>');
     termlists.push('</div>');
             
     termlists.push('<div id="term_authors" >');
-    termlists.push('<div class="termtitle">.::Authors</div>');
+    termlists.push('<h4 class="termtitle">Authors</h4>');
+    termlists.push('<ul>');
+    termlists.push('<li><a href="#" onclick="limitOrResetQuery(\'reset_au\',\'All\');return false;">All<a></li>');
     for (var i = 0; i < data.author.length && i < AuthorMax; i++ ) {
-        termlists.push('<a href="#" onclick="limitQuery(\'au\', this.firstChild.nodeValue);return false;">' 
+        termlists.push('<li><a href="#" onclick="limitQuery(\'au\', \'' + data.author[i].name +'\');return false;">' 
                             + data.author[i].name 
-                            + ' </a><span> (' 
+                            + '  (' 
                             + data.author[i].freq 
-                            + ')</span><br/>');
+                            + ')</a></li>');
     }
+    termlists.push('</ul>');
     termlists.push('</div>');
     var termlist = document.getElementById("termlist");
     replaceHtml(termlist, termlists.join(''));
-    var d;
-/*
-    for (d in ("xtargets", "subjects", "authors")) {
-       alert(d);
-       if (tab == d)
-               document.getElementById("term_" + d).style.display = '';
-       else 
-               document.getElementById("term_" +d ).style.display = 'none';
-    }
-*/
     showhide();
 }
 
@@ -199,19 +202,19 @@ function serialize(array) {
 var termlist = {};
 function my_onterm_iphone(data) {
     my_onterm(data);
-    var targets = "-|All|\n";
+    var targets = "reset_xt|All\n";
     
     for (var i = 0; i < data.xtargets.length; i++ ) {
        
         targets = targets + data.xtargets[i].id + "|" + data.xtargets[i].name + "|" + data.xtargets[i].freq + "\n";
     }
     termlist["xtargets"] = targets;
-    var subjects = "-|All|\n";
+    var subjects = "reset_su|All\n";
     for (var i = 0; i < data.subject.length; i++ ) {
         subjects = subjects + "su" + "|" + data.subject[i].name + "|" + data.subject[i].freq + "\n";
     }
     termlist["subjects"] = subjects;
-    var authors = "-|All|\n";
+    var authors = "reset_au|All\n";
     for (var i = 0; i < data.author.length; i++ ) {
         authors = authors + "au" + "|" + data.author[i].name + "|" + data.author[i].freq + "\n";
     }
@@ -240,7 +243,7 @@ function my_onrecord(data) {
     if (detRecordDiv) return;
     curDetRecData = data;
     var recordDiv = document.getElementById('recdiv_'+curDetRecData.recid);
-    var html = renderDetails(curDetRecData);
+    var html = renderDetails_iphone(curDetRecData);
     recordDiv.innerHTML += html;
 }
 
@@ -288,7 +291,7 @@ function applicationMode(newmode)
                inApp = newmode;
        if (inApp) {
        document.getElementById("heading").style.display="none";
-               searchdiv.style.display = 'none';
+               searchdiv.style.display = 'none';
        }
        else { 
                searchdiv.style.display = '';
@@ -333,21 +336,39 @@ function loadSelect ()
 }
 
 // limit the query after clicking the facet
-function limitQuery (field, value)
+function limitQuery(field, value)
 {
-    document.search.query.value += ' and ' + field + '="' + value + '"';
+       var newQuery = ' and ' + field + '="' + value + '"';
+       querys[field] += newQuery;
+    document.search.query.value += newQuery;
+    onFormSubmitEventHandler();
+    showhide("recordview");
+}
+
+//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
+function limitOrResetQuery (field, value, selected) {
+       if (field == 'reset_su' || field == 'reset_au') {
+               var reset_field = field.substring(6);
+               document.search.query.value = document.search.query.value.replace(querys[reset_field], '');
+               querys[reset_field] = '';
+           onFormSubmitEventHandler();
+           showhide("recordview");
+       }
+       else 
+               limitQuery(field, value);
+       //alert("limitOrResetQuerry: query after: " + document.search.query.value);
+}
+
 // limit by target functions
 function limitTarget (id, name)
 {
-    var navi = document.getElementById('navi');
-    navi.innerHTML = 
-        'Source: <a class="crossout" href="#" onclick="delimitTarget();return false;">'
-        + name + '</a>';
-    navi.innerHTML += '<hr/>';
     curFilter = 'pz:id=' + id;
     resetPage();
     loadSelect();
@@ -358,8 +379,6 @@ function limitTarget (id, name)
 
 function delimitTarget ()
 {
-    var navi = document.getElementById('navi');
-    navi.innerHTML = '';
     curFilter = null; 
     resetPage();
     loadSelect();
@@ -367,6 +386,15 @@ function delimitTarget ()
     return false;
 }
 
+function limitOrResetTarget(id, name) {
+       if (id == 'reset_xt') {
+               delimitTarget();
+       }
+       else {
+               limitTarget(id,name);
+       }
+}
+
 function drawPager (pagerDiv)
 {
     //client indexes pages from 1 but pz2 from 0
@@ -409,7 +437,7 @@ function drawPager (pagerDiv)
     if (lastClkbl < pages)
         postdots = '...';
 
-    pagerDiv.innerHTML += '<div style="float: clear">' 
+    pagerDiv.innerHTML += '<div style="float: none">' 
         + prev + predots + middle + postdots + next + '</div><hr/>';
 }
 
@@ -517,4 +545,61 @@ function renderDetails(data, marker)
     details += '</table></div>';
     return details;
 }
- //EOF
+
+function renderLine(title, value) {
+    if (value != undefined)
+        return '<li><h3>' + title + '</h3> <big>' + value + '</big></li>';
+    return '';
+}
+
+function renderLineURL(title, URL, display) {
+    if (URL != undefined)
+       return '<li><h3>' + title + '</h3> <a href="' + URL + '" target="_blank">' + display + '</a></li>';
+    return '';
+}
+
+function renderLineEmail(dtitle, email, display) {
+    if (email != undefined)
+        return '<li><h3>' + title + '</h3> <a href="mailto:' + email + '" target="_blank">' + display + '</a></li>';
+    return '';
+}
+
+function renderDetails_iphone(data, marker)
+{
+       //return renderDetails(data,marker);
+
+
+    var details = ''
+/*
+    details = '<div id="header" id="det_'+data.recid+'">' 
+       + '<h1>Detailed Info</h1>' 
+       + '<a id="backbutton" href="hidedetail(\'det_' + data.recid + '\')">Back</a>' 
+       + '</div>';
+*/
+    if (marker) 
+       details += '<h4>'+ marker + '</h4>'; 
+    details += '<ul class="field">';
+    if (data["md-title"] != undefined) {
+       details += '<li><h3>Title</h3> <big> ' + data["md-title"];
+        if (data["md-title-remainder"] !== undefined) {
+             details += ' ' + data["md-title-remainder"] + ' ';
+        }
+        if (data["md-title-responsibility"] !== undefined) {
+             details += '<i>'+ data["md-title-responsibility"] +'</i>';
+        }
+        details += '</big>'
+        details += '</li>'
+    }
+    details 
+       +=renderLine('Date',    data["md-date"])
+       + renderLine('Author',  data["md-author"])
+       + renderLineURL('URL',  data["md-electronic-url"], data["md-electronic-url"])
+       + renderLine('Subject', data["location"][0]["md-subject"]);
+    
+    if (data["location"][0]["@name"] != undefined)
+       details += renderLine('Location', data["location"][0]["@name"] + " (" +data["location"][0]["@id"] + ")");
+    details += '</ul>';
+    return details;
+}
+
+//EOF