From 12b951baa959d50bbf0b81671c8c4a5a6f2852ee Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Fri, 29 Mar 2013 23:59:00 -0700 Subject: [PATCH] Adds polling for record command (WiP) --- src/META-INF/resources/pz2utils/fieldlisteners.js | 38 ++++++++++++++++++++ src/META-INF/resources/pz2utils/pz2watch.xhtml | 4 +++ .../indexdata/pz2utils4jsf/pazpar2/Pz2Session.java | 7 +++- .../pz2utils4jsf/pazpar2/data/RecordResponse.java | 4 +++ .../pz2utils4jsf/pz2utils/ListenerFieldIds.java | 4 +++ 5 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/META-INF/resources/pz2utils/fieldlisteners.js b/src/META-INF/resources/pz2utils/fieldlisteners.js index 5f521f0..300d223 100644 --- a/src/META-INF/resources/pz2utils/fieldlisteners.js +++ b/src/META-INF/resources/pz2utils/fieldlisteners.js @@ -1,4 +1,5 @@ var renderTargetsReqVar; + var renderOnRecordTargetsReqVar; function renderTargets(doRefresh) { @@ -17,6 +18,26 @@ //console.log("No further updates from server requested"); } } + + function renderOnRecordTargets(doRefresh) + { + console.log('rendering ' + renderWhileActiveclientsRecord); + var sourcecomp = document.getElementById("pz2watch:activeclientsFieldRecord"); + jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclientsRecord}); + if (doRefresh) { + console.log('Will do another ajax request after a timeout in order to render: pz2watch:activeclientsFieldRecord'); + renderOnRecordTargetsReqVar=setTimeout( + function() { + console.log('Making request for pz2watch:activeclientsFieldRecord'); + jsf.ajax.request(sourcecomp, null,{render: "pz2watch:activeclientsFieldRecord"}); + } + ,2000); + } else { + console.log("No further updates from server requested"); + jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclientsRecord}); + } + } + function windowlocationhashListener () { if (trackHistory) { @@ -85,6 +106,22 @@ } }; }; + + var ActiveclientsRecordListener = function () { + this.invoke = function (field) { + var updateDoc = StringtoXML(field.textContent || field.text); + var activeClientsRecordValue = (updateDoc.childNodes[0].textContent || updateDoc.childNodes[0].text); + console.log('Activeclients response for record detected: ' + activeClientsRecordValue); + clearTimeout(renderOnRecordTargetsReqVar); + if (activeClientsRecordValue > '0') { + renderOnRecordTargets(true); + } else { + console.log('Active clients is 0, final rendering'); + renderOnRecordTargets(false); + } + }; + }; + jsf.ajax.addOnEvent(fieldUpdateListener); @@ -104,6 +141,7 @@ var setUpListeners = function () { //console.log("Starts tracking activeclientsField"); fieldListeners.addListener("pz2watch:activeclientsField", new ActiveclientsListener()); + fieldListeners.addListener("pz2watch:activeclientsFieldRecord", new ActiveclientsRecordListener()); if (trackHistory) { //console.log("Starts tracking windowlocationhash field"); fieldListeners.addListener("pz2watch:windowlocationhash", new StateListener()); diff --git a/src/META-INF/resources/pz2utils/pz2watch.xhtml b/src/META-INF/resources/pz2utils/pz2watch.xhtml index 9cbdda2..39706dd 100644 --- a/src/META-INF/resources/pz2utils/pz2watch.xhtml +++ b/src/META-INF/resources/pz2utils/pz2watch.xhtml @@ -13,6 +13,7 @@ + @@ -26,6 +27,7 @@