From: Niels Erik G. Nielsen Date: Sat, 30 Mar 2013 06:59:00 +0000 (-0700) Subject: Adds polling for record command (WiP) X-Git-Tag: v0.0.7~194 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=12b951baa959d50bbf0b81671c8c4a5a6f2852ee;p=mkjsf-moved-to-github.git Adds polling for record command (WiP) --- 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 @@