From 986c292739b7f0a7d1b5939dbbddea4bb3d5efa8 Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Wed, 27 Feb 2013 21:12:45 -0500 Subject: [PATCH 1/1] Adds pazpar2 listeners --- .gitignore | 5 + pom.xml | 58 +++++++++++ src/META-INF/MANIFEST.MF | 3 + src/META-INF/resources/pz2utils/fieldlisteners.js | 113 +++++++++++++++++++++ src/META-INF/resources/pz2utils/pz2watch.xhtml | 48 +++++++++ 5 files changed, 227 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/META-INF/MANIFEST.MF create mode 100644 src/META-INF/resources/pz2utils/fieldlisteners.js create mode 100644 src/META-INF/resources/pz2utils/pz2watch.xhtml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf98bbd --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.classpath +.project +.settings/ +build/ +target/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7d6dd9c --- /dev/null +++ b/pom.xml @@ -0,0 +1,58 @@ + + 4.0.0 + com.indexdata + pz2utils4jsf + 0.0.1-SNAPSHOT + pz2utils4jsf + jar + Components for building Pazpar2 application using JSF + + + javax + javaee-api + 6.0 + provided + + + + + org.glassfish + javax.faces + 2.1.16 + compile + + + javax.servlet.jsp.jstl + javax.servlet.jsp.jstl-api + 1.2.1 + compile + + + com.indexdata + masterkey-common + 0.1.9-SNAPSHOT + + + + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + + \ No newline at end of file diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5e94951 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/src/META-INF/resources/pz2utils/fieldlisteners.js b/src/META-INF/resources/pz2utils/fieldlisteners.js new file mode 100644 index 0000000..c5cf63a --- /dev/null +++ b/src/META-INF/resources/pz2utils/fieldlisteners.js @@ -0,0 +1,113 @@ + var renderTargetsReqVar; + + function renderTargets(doRefresh) + { + //console.log('rendering ' + renderWhileActiveclients); + var sourcecomp = document.getElementById("pz2watch:activeclientsField"); + jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclients}); + if (doRefresh) { + //console.log('Will do another ajax request after a timeout in order to render: pz2watch:activeclientsField'); + renderTargetsReqVar=setTimeout( + function() { + //console.log('Making request for pz2watch:activeclientsField'); + jsf.ajax.request(sourcecomp, null,{render: "pz2watch:activeclientsField"}); + } + ,500); + } else { + //console.log("No further updates from server requested"); + } + } + + function windowlocationhashListener () { + if (trackHistory) { + //console.log("browser hash update detected"); + var stateKey = document.getElementById("pz2watch:windowlocationhash"); + if (window.location.hash != stateKey.value) { + //console.log("updating stateKey with new browser hash: " + window.location.hash); + stateKey.value = window.location.hash; + if (! stateKey.value) window.location.hash = '#initial'; + stateKey.onchange(); + } else { + //console.log("State hash already has the value of the new browser hash - not updating state hash"); + } + } + } + + function fieldUpdateListener (data) { + if (data.status === "success") { + var updates = data.responseXML.getElementsByTagName("update"); + for (var i=0, max=updates.length; i '0') { + renderTargets(true); + } else { + renderTargets(false); + } + }; + }; + + jsf.ajax.addOnEvent(fieldUpdateListener); + + function StringtoXML(text){ + var doc; + if (window.ActiveXObject){ + doc=new ActiveXObject('Microsoft.XMLDOM'); + doc.async=false; + doc.loadXML(text); + } else { + var parser=new DOMParser(); + doc=parser.parseFromString(text,'text/xml'); + } + return doc; + } + + var setUpListeners = function () { + //console.log("Starts tracking activeclientsField"); + fieldListeners.addListener("pz2watch:activeclientsField", new ActiveclientsListener()); + if (trackHistory) { + //console.log("Starts tracking windowlocationhash field"); + fieldListeners.addListener("pz2watch:windowlocationhash", new StateListener()); + //console.log("Setting listener for browser onhashchange"); + window.onload = window.onhashchange = windowlocationhashListener; + } + }; \ No newline at end of file diff --git a/src/META-INF/resources/pz2utils/pz2watch.xhtml b/src/META-INF/resources/pz2utils/pz2watch.xhtml new file mode 100644 index 0000000..511aae1 --- /dev/null +++ b/src/META-INF/resources/pz2utils/pz2watch.xhtml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + Active clients: + + + + State: + + + + + + + + \ No newline at end of file -- 1.7.10.4