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 // data[0] ignored here
20 for( i = 1; i < data.length; i++ )
22 var section = data[i].section // Section to handle
23 var cbx = document.getElementById("cbid.ddns." + section + ".enabled"); // Enabled
24 var btn = document.getElementById("cbid.ddns." + section + "._startstop"); // Start/Stop button
25 var rip = document.getElementById("cbid.ddns." + section + "._domainIP.two"); // Registered IP
26 var lup = document.getElementById("cbid.ddns." + section + "._update.one"); // Last Update
27 var nup = document.getElementById("cbid.ddns." + section + "._update.two"); // Next Update
28 if ( !(cbx && btn && rip && lup && nup) ) { return; } // security check
31 if (data[i].pid > 0) {
32 // stop always possible if process running
33 btn.value = "PID: " + data[i].pid;
34 btn.className = "cbi-button cbi-input-reset";
36 // default Start / enabled
37 btn.value = "<%:Start%>";
38 btn.className = "cbi-button cbi-input-apply";
40 btn.disabled = false; // button enabled
43 switch (data[i].datelast) {
45 lup.innerHTML = '<em><%:Unknown error%></em>' ;
48 lup.innerHTML = '<em><%:Never%></em>' ;
51 lup.innerHTML = data[i].datelast;
56 switch (data[i].datenext) {
58 nup.innerHTML = '<em><%:Unknown error%></em>' ;
61 nup.innerHTML = '<em><%:Verify%></em>';
66 if (cbx.checked && data[i].datenext == "_runonce_") {
67 nup.innerHTML = '<em><%:Run once%></em>';
68 } else if (cbx.checked) {
69 nup.innerHTML = '<em><%:Stopped%></em>';
71 nup.innerHTML = '<em><%:Disabled%></em>';
72 btn.value = '----------';
73 btn.className = "cbi-button cbi-input-button"; // no image
74 btn.disabled = true; // disabled
78 nup.innerHTML = data[i].datenext;
83 // (data[i].domain ignored here
86 // rip.innerHTML = "Registered IP";
87 if (data[i].domain == "_nodomain_")
89 else if (data[i].reg_ip == "_nodata_")
90 rip.innerHTML = '<em><%:No data%></em>';
92 rip.innerHTML = data[i].reg_ip;
94 // monitored interfacce
95 // data[i].iface ignored here
99 // event handler for enabled checkbox
100 function onchange_enabled(id) {
101 // run original function in cbi.js
102 // whatever is done there
105 var section = _id2section(id);
106 var cbx = document.getElementById("cbid.ddns." + section + ".enabled");
107 var btn = document.getElementById("cbid.ddns." + section + "._startstop");
108 if ( !(cbx && btn) ) { return; } // security check
110 var pid_txt = btn.value;
111 var pid_found = ( pid_txt.search("PID") >= 0 ) ? true : false;
114 // btn.value = "PID: 0000";
115 btn.className = "cbi-button cbi-button-reset";
116 btn.disabled = false;
117 } else if (cbx.checked) {
118 btn.value = "<%:Start%>";
119 btn.className = "cbi-button cbi-button-apply";
120 btn.disabled = false;
122 btn.value = '----------';
123 btn.className = "cbi-button cbi-input-button"; // no image
124 btn.disabled = true; // disabled
128 // event handler for start/stop button
129 function onclick_startstop(id) {
131 var section = _id2section(id);
133 var cbx = document.getElementById("cbid.ddns." + section + ".enabled"); // Enabled
134 var obj = document.getElementById("cbi-ddns-overview-status-legend"); // objext defined below to make in-/visible
135 if ( !(obj && cbx) ) { return; } // security check
138 obj.parentNode.style.display = "block";
141 var btnXHR = new XHR();
142 btnXHR.get('<%=luci.dispatcher.build_url("admin", "services", "ddns", "startstop")%>/' + section + '/' + cbx.checked, null,
144 if (x.responseText == "_uncommited_") {
145 // we need a trick to display Ampersand "&" in stead of "&" or "&"
147 txt="<%:Please [Save & Apply] your changes first%>";
148 alert( txt.replace(new RegExp("<%:&%>", "g"), "&") );
150 // should have data because status changed
153 _data2elements(data);
156 obj.parentNode.style.display = "none";
161 // define only ONE XHR.poll in a page because if one is running it blocks the other one
162 // optimum is to define on Map or Section Level from here you can reach all elements
163 // we need update every 30 seconds only
164 XHR.poll(30, '<%=luci.dispatcher.build_url("admin", "services", "ddns", "status")%>', null,
167 _data2elements(data);
173 <fieldset class="cbi-section" style="display:none">
174 <legend id="cbi-ddns-overview-status-legend"><%:Applying changes%></legend>
175 <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
176 <span id="cbi-ddns-overview-status-text"><%:Waiting for changes to be applied...%></span>
178 <!-- ++ END ++ Dynamic DNS ++ overview_status.htm ++ -->