1 var renderTargetsReqVar;
\r
3 function renderTargets(doRefresh)
\r
5 //console.log('rendering ' + renderWhileActiveclients);
\r
6 var sourcecomp = document.getElementById("pz2watch:activeclientsField");
\r
7 jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclients + " pz2watch:errorMessages"});
\r
9 //console.log('Will do another ajax request after a timeout in order to render: pz2watch:activeclientsField');
\r
10 renderTargetsReqVar=setTimeout(
\r
12 //console.log('Making request for pz2watch:activeclientsField');
\r
13 jsf.ajax.request(sourcecomp, null,{render: "pz2watch:activeclientsField"});
\r
17 //console.log("No further updates from server requested");
\r
21 function windowlocationhashListener () {
\r
23 //console.log("browser hash update detected");
\r
24 var stateKey = document.getElementById("pz2watch:windowlocationhash");
\r
25 if (window.location.hash != stateKey.value) {
\r
26 //console.log("updating stateKey with new browser hash: " + window.location.hash);
\r
27 stateKey.value = window.location.hash;
\r
28 if (! stateKey.value) window.location.hash = '#initial';
\r
29 stateKey.onchange();
\r
31 //console.log("State hash already has the value of the new browser hash - not updating state hash");
\r
36 function fieldUpdateListener (data) {
\r
37 if (data.status === "success") {
\r
38 var updates = data.responseXML.getElementsByTagName("update");
\r
39 for (var i=0, max=updates.length; i<max; i++) {
\r
40 var lsnri = fieldListeners.getListener(updates[i].getAttribute("id"));
\r
42 lsnri.invoke(updates[i]);
\r
48 var Pz2listeners = function () {
\r
50 this.addListener = function (key, lsnr) {
\r
53 this.getListener = function (key) {
\r
58 var fieldListeners = new Pz2listeners();
\r
60 var StateListener = function () {
\r
61 this.invoke = function (field) {
\r
62 var stateKeyDoc = StringtoXML(field.textContent || field.text);
\r
63 var stateKeyValue = stateKeyDoc.childNodes[0].getAttribute("value");
\r
64 //console.log('Application hash update detected. New value: ' + stateKeyValue);
\r
65 if (stateKeyValue != window.location.hash) {
\r
66 window.location.hash = stateKeyValue;
\r
67 //console.log("Browsers hash updated accordingly.");
\r
69 //console.log("Browsers hash already has the value of the state hash. Not updating browser hash.");
\r
75 var ActiveclientsListener = function () {
\r
76 this.invoke = function (field) {
\r
77 var updateDoc = StringtoXML(field.textContent || field.text);
\r
78 var activeClientsValue = (updateDoc.childNodes[0].textContent || updateDoc.childNodes[0].text);
\r
79 //console.log('Activeclients response detected: ' + activeClientsValue);
\r
80 clearTimeout(renderTargetsReqVar);
\r
81 if (activeClientsValue > '0') {
\r
82 renderTargets(true);
\r
84 renderTargets(false);
\r
89 jsf.ajax.addOnEvent(fieldUpdateListener);
\r
91 function StringtoXML(text){
\r
93 if (window.ActiveXObject){
\r
94 doc=new ActiveXObject('Microsoft.XMLDOM');
\r
98 var parser=new DOMParser();
\r
99 doc=parser.parseFromString(text,'text/xml');
\r
104 var setUpListeners = function () {
\r
105 //console.log("Starts tracking activeclientsField");
\r
106 fieldListeners.addListener("pz2watch:activeclientsField", new ActiveclientsListener());
\r
107 if (trackHistory) {
\r
108 //console.log("Starts tracking windowlocationhash field");
\r
109 fieldListeners.addListener("pz2watch:windowlocationhash", new StateListener());
\r
110 //console.log("Setting listener for browser onhashchange");
\r
111 window.onload = window.onhashchange = windowlocationhashListener;
\r