1 var renderTargetsReqVar;
\r
2 var renderOnRecordTargetsReqVar;
\r
4 function renderTargets(doRefresh)
\r
6 //console.log('rendering ' + renderWhileActiveclients);
\r
7 var sourcecomp = document.getElementById("pz2watch:activeclientsField");
\r
8 jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclients + " pz2watch:errorMessages"});
\r
10 //console.log('Will do another ajax request after a timeout in order to render: pz2watch:activeclientsField');
\r
11 renderTargetsReqVar=setTimeout(
\r
13 //console.log('Making request for pz2watch:activeclientsField');
\r
14 jsf.ajax.request(sourcecomp, null,{render: "pz2watch:activeclientsField"});
\r
18 //console.log("No further updates from server requested");
\r
22 function renderOnRecordTargets(doRefresh)
\r
24 console.log('rendering ' + renderWhileActiveclientsRecord);
\r
25 var sourcecomp = document.getElementById("pz2watch:activeclientsFieldRecord");
\r
26 jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclientsRecord});
\r
28 console.log('Will do another ajax request after a timeout in order to render: pz2watch:activeclientsFieldRecord');
\r
29 renderOnRecordTargetsReqVar=setTimeout(
\r
31 console.log('Making request for pz2watch:activeclientsFieldRecord');
\r
32 jsf.ajax.request(sourcecomp, null,{render: "pz2watch:activeclientsFieldRecord"});
\r
36 //console.log("No further updates from server requested");
\r
41 function windowlocationhashListener () {
\r
43 //console.log("browser hash update detected");
\r
44 var stateKey = document.getElementById("pz2watch:windowlocationhash");
\r
45 if (window.location.hash != stateKey.value) {
\r
46 //console.log("updating stateKey with new browser hash: " + window.location.hash);
\r
47 stateKey.value = window.location.hash;
\r
48 if (! stateKey.value) window.location.hash = '#initial';
\r
49 stateKey.onchange();
\r
51 //console.log("State hash already has the value of the new browser hash - not updating state hash");
\r
56 function fieldUpdateListener (data) {
\r
57 if (data.status === "success") {
\r
58 var updates = data.responseXML.getElementsByTagName("update");
\r
59 for (var i=0, max=updates.length; i<max; i++) {
\r
60 var lsnri = fieldListeners.getListener(updates[i].getAttribute("id"));
\r
62 lsnri.invoke(updates[i]);
\r
68 var Pz2listeners = function () {
\r
70 this.addListener = function (key, lsnr) {
\r
73 this.getListener = function (key) {
\r
78 var fieldListeners = new Pz2listeners();
\r
80 var StateListener = function () {
\r
81 this.invoke = function (field) {
\r
82 var stateKeyDoc = StringtoXML(field.textContent || field.text);
\r
83 var stateKeyValue = stateKeyDoc.childNodes[0].getAttribute("value");
\r
84 //console.log('Application hash update detected. New value: ' + stateKeyValue);
\r
85 if (stateKeyValue !== window.location.hash) {
\r
86 window.location.hash = stateKeyValue;
\r
87 //console.log("Browsers hash updated accordingly.");
\r
89 //console.log("Browsers hash already has the value of the state hash. Not updating browser hash.");
\r
95 var ActiveclientsListener = function () {
\r
96 this.invoke = function (field) {
\r
97 var updateDoc = StringtoXML(field.textContent || field.text);
\r
98 var activeClientsValue = (updateDoc.childNodes[0].textContent || updateDoc.childNodes[0].text);
\r
99 //console.log('Activeclients response detected: ' + activeClientsValue);
\r
100 clearTimeout(renderTargetsReqVar);
\r
101 if (activeClientsValue > '0') {
\r
102 renderTargets(true);
\r
104 renderTargets(false);
\r
109 var ActiveclientsRecordListener = function () {
\r
110 this.invoke = function (field) {
\r
111 var updateDoc = StringtoXML(field.textContent || field.text);
\r
112 var activeClientsRecordValue = (updateDoc.childNodes[0].textContent || updateDoc.childNodes[0].text);
\r
113 console.log('Activeclients response for record detected: ' + activeClientsRecordValue);
\r
114 clearTimeout(renderOnRecordTargetsReqVar);
\r
115 if (activeClientsRecordValue > '0') {
\r
116 renderOnRecordTargets(true);
\r
118 console.log('Active clients is 0, final rendering');
\r
119 renderOnRecordTargets(false);
\r
125 jsf.ajax.addOnEvent(fieldUpdateListener);
\r
127 function StringtoXML(text){
\r
129 if (window.ActiveXObject){
\r
130 doc=new ActiveXObject('Microsoft.XMLDOM');
\r
134 var parser=new DOMParser();
\r
135 doc=parser.parseFromString(text,'text/xml');
\r
140 var setUpListeners = function () {
\r
141 //console.log("Starts tracking activeclientsField");
\r
142 fieldListeners.addListener("pz2watch:activeclientsField", new ActiveclientsListener());
\r
143 fieldListeners.addListener("pz2watch:activeclientsFieldRecord", new ActiveclientsRecordListener());
\r
144 if (trackHistory) {
\r
145 //console.log("Starts tracking windowlocationhash field");
\r
146 fieldListeners.addListener("pz2watch:windowlocationhash", new StateListener());
\r
147 //console.log("Setting listener for browser onhashchange");
\r
148 window.onload = window.onhashchange = windowlocationhashListener;
\r