2 <!-- ++ BEGIN ++ Dynamic DNS ++ overview_status.htm ++ -->
3 <script type="text/javascript">//<![CDATA[
5 // helper to extract section from objects id
6 // cbi.ddns.SECTION._xyz
7 function _id2section(id) {
12 // helper to move status data to the relevant
14 // called by XHR.poll and onclick_startstop
15 function _data2elements(data) {
17 for( i = 1; i < data.length; i++ )
19 var section = data[i].section // Section to handle
20 var cbx = document.getElementById("cbid.ddns." + section + ".enabled"); // Enabled
21 var btn = document.getElementById("cbid.ddns." + section + "._startstop"); // Start/Stop button
22 var rip = document.getElementById("cbid.ddns." + section + "._domainIP.two"); // Registered IP
23 var lup = document.getElementById("cbid.ddns." + section + "._update.one"); // Last Update
24 var nup = document.getElementById("cbid.ddns." + section + "._update.two"); // Next Update
25 if ( !(cbx && btn && rip && lup && nup) ) { return; } // security check
28 if (data[i].pid > 0) {
29 // stop always possible if process running
30 btn.value = "PID: " + data[i].pid;
31 btn.className = "cbi-button cbi-input-reset";
33 // default Start / enabled
34 btn.value = "<%:Start%>";
35 btn.className = "cbi-button cbi-input-apply";
37 btn.disabled = false; // button enabled
40 switch (data[i].datelast) {
42 lup.innerHTML = '<em><%:Unknown error%></em>' ;
45 lup.innerHTML = '<em><%:Never%></em>' ;
48 lup.innerHTML = data[i].datelast;
53 switch (data[i].datenext) {
55 nup.innerHTML = '<em><%:Unknown error%></em>' ;
58 nup.innerHTML = '<em><%:Verify%></em>';
63 if (cbx.checked && data[i].datenext == "_runonce_") {
64 nup.innerHTML = '<em><%:Run once%></em>';
65 } else if (cbx.checked) {
66 nup.innerHTML = '<em><%:Stopped%></em>';
68 nup.innerHTML = '<em><%:Disabled%></em>';
69 btn.value = '----------';
70 btn.className = "cbi-button cbi-input-button"; // no image
71 btn.disabled = true; // disabled
75 nup.innerHTML = data[i].datenext;
80 // (data[i].domain ignored here
83 // rip.innerHTML = "Registered IP";
84 if (data[i].domain == "_nodomain_")
86 else if (data[i].reg_ip == "_nodata_")
87 rip.innerHTML = '<em><%:No data%></em>';
89 rip.innerHTML = data[i].reg_ip;
91 // monitored interfacce
92 // data[i].iface ignored here
96 // event handler for enabled checkbox
97 function onchange_enabled(id) {
98 // run original function in cbi.js
99 // whatever is done there
102 var section = _id2section(id);
103 var cbx = document.getElementById("cbid.ddns." + section + ".enabled");
104 var btn = document.getElementById("cbid.ddns." + section + "._startstop");
105 if ( !(cbx && btn) ) { return; } // security check
107 var pid_txt = btn.value;
108 var pid_found = ( pid_txt.search("PID") >= 0 ) ? true : false;
111 // btn.value = "PID: 0000";
112 btn.className = "cbi-button cbi-button-reset";
113 btn.disabled = false;
114 } else if (cbx.checked) {
115 btn.value = "<%:Start%>";
116 btn.className = "cbi-button cbi-button-apply";
117 btn.disabled = false;
119 btn.value = '----------';
120 btn.className = "cbi-button cbi-input-button"; // no image
121 btn.disabled = true; // disabled
125 // event handler for start/stop button
126 function onclick_startstop(id) {
128 var section = _id2section(id);
130 var cbx = document.getElementById("cbid.ddns." + section + ".enabled"); // Enabled
131 var obj = document.getElementById("cbi-ddns-overview-status-legend"); // object defined below to make in-/visible
132 if ( !(obj && cbx) ) { return; } // security check
135 obj.parentNode.style.display = "block";
138 var btnXHR = new XHR();
139 btnXHR.post('<%=url('admin/services/ddns/startstop')%>/' + section + '/' + cbx.checked, { token: '<%=token%>' },
141 if (x.responseText == "_uncommitted_") {
142 // we need a trick to display Ampersand "&" in stead of "&" or "&"
144 txt="<%:Please [Save & Apply] your changes first%>";
145 alert( txt.replace(new RegExp("<%:&%>", "g"), "&") );
147 // should have data because status changed
149 if (data) { _data2elements(data); }
152 obj.parentNode.style.display = "none";
157 // force to immediate show status on page load (not waiting for XHR.poll)
158 XHR.get('<%=url('admin/services/ddns/status')%>', null,
160 if (data) { _data2elements(data); }
164 // define only ONE XHR.poll in a page because if one is running it blocks the other one
165 // optimum is to define on Map or Section Level from here you can reach all elements
166 // we need update every 15 seconds only
167 XHR.poll(15, '<%=url('admin/services/ddns/status')%>', null,
169 if (data) { _data2elements(data); }
175 <fieldset class="cbi-section" style="display:none">
176 <legend id="cbi-ddns-overview-status-legend"><%:Applying changes%></legend>
177 <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
178 <span id="cbi-ddns-overview-status-text"><%:Waiting for changes to be applied...%></span>
180 <!-- ++ END ++ Dynamic DNS ++ overview_status.htm ++ -->