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
37 jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclientsRecord});
\r
42 function windowlocationhashListener () {
\r
44 //console.log("browser hash update detected");
\r
45 var stateKey = document.getElementById("pz2watch:windowlocationhash");
\r
46 if (window.location.hash != stateKey.value) {
\r
47 //console.log("updating stateKey with new browser hash: " + window.location.hash);
\r
48 stateKey.value = window.location.hash;
\r
49 if (! stateKey.value) window.location.hash = '#initial';
\r
50 stateKey.onchange();
\r
52 //console.log("State hash already has the value of the new browser hash - not updating state hash");
\r
57 function fieldUpdateListener (data) {
\r
58 if (data.status === "success") {
\r
59 var updates = data.responseXML.getElementsByTagName("update");
\r
60 for (var i=0, max=updates.length; i<max; i++) {
\r
61 var lsnri = fieldListeners.getListener(updates[i].getAttribute("id"));
\r
63 lsnri.invoke(updates[i]);
\r
69 var Pz2listeners = function () {
\r
71 this.addListener = function (key, lsnr) {
\r
74 this.getListener = function (key) {
\r
79 var fieldListeners = new Pz2listeners();
\r
81 var StateListener = function () {
\r
82 this.invoke = function (field) {
\r
83 var stateKeyDoc = StringtoXML(field.textContent || field.text);
\r
84 var stateKeyValue = stateKeyDoc.childNodes[0].getAttribute("value");
\r
85 //console.log('Application hash update detected. New value: ' + stateKeyValue);
\r
86 if (stateKeyValue != window.location.hash) {
\r
87 window.location.hash = stateKeyValue;
\r
88 //console.log("Browsers hash updated accordingly.");
\r
90 //console.log("Browsers hash already has the value of the state hash. Not updating browser hash.");
\r
96 var ActiveclientsListener = function () {
\r
97 this.invoke = function (field) {
\r
98 var updateDoc = StringtoXML(field.textContent || field.text);
\r
99 var activeClientsValue = (updateDoc.childNodes[0].textContent || updateDoc.childNodes[0].text);
\r
100 //console.log('Activeclients response detected: ' + activeClientsValue);
\r
101 clearTimeout(renderTargetsReqVar);
\r
102 if (activeClientsValue > '0') {
\r
103 renderTargets(true);
\r
105 renderTargets(false);
\r
110 var ActiveclientsRecordListener = function () {
\r
111 this.invoke = function (field) {
\r
112 var updateDoc = StringtoXML(field.textContent || field.text);
\r
113 var activeClientsRecordValue = (updateDoc.childNodes[0].textContent || updateDoc.childNodes[0].text);
\r
114 console.log('Activeclients response for record detected: ' + activeClientsRecordValue);
\r
115 clearTimeout(renderOnRecordTargetsReqVar);
\r
116 if (activeClientsRecordValue > '0') {
\r
117 renderOnRecordTargets(true);
\r
119 console.log('Active clients is 0, final rendering');
\r
120 renderOnRecordTargets(false);
\r
126 jsf.ajax.addOnEvent(fieldUpdateListener);
\r
128 function StringtoXML(text){
\r
130 if (window.ActiveXObject){
\r
131 doc=new ActiveXObject('Microsoft.XMLDOM');
\r
135 var parser=new DOMParser();
\r
136 doc=parser.parseFromString(text,'text/xml');
\r
141 var setUpListeners = function () {
\r
142 //console.log("Starts tracking activeclientsField");
\r
143 fieldListeners.addListener("pz2watch:activeclientsField", new ActiveclientsListener());
\r
144 fieldListeners.addListener("pz2watch:activeclientsFieldRecord", new ActiveclientsRecordListener());
\r
145 if (trackHistory) {
\r
146 //console.log("Starts tracking windowlocationhash field");
\r
147 fieldListeners.addListener("pz2watch:windowlocationhash", new StateListener());
\r
148 //console.log("Setting listener for browser onhashchange");
\r
149 window.onload = window.onhashchange = windowlocationhashListener;
\r