b0cc2fac357b0d106b9a3627b2e7e330a13a9c54
[project/luci.git] / applications / luci-ddns / luasrc / view / ddns / overview_status.htm
1
2 <!-- ++ BEGIN ++ Dynamic DNS ++ overview_status.htm ++ -->
3 <script type="text/javascript">//<![CDATA[
4
5         // helper to extract section from objects id
6         // cbi.ddns.SECTION._xyz
7         function _id2section(id) {
8                 var x = id.split(".");
9                 return x[2];
10         }
11
12         // helper to move status data to the relevant
13         // screen objects
14         // called by XHR.poll and onclick_startstop
15         function _data2elements(data) {
16                 // DDNS Service
17                 // data[0] ignored here
18
19                 // Service sections
20                 for( i = 1; i < data.length; i++ )
21                 {
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
29
30                         // process id
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";
35                         } else {
36                                 // default Start / enabled
37                                 btn.value = "<%:Start%>";
38                                 btn.className = "cbi-button cbi-input-apply";
39                         }
40                         btn.disabled = false;   // button enabled
41                         
42                         // last update
43                         switch (data[i].datelast) {
44                                 case "_empty_":
45                                         lup.innerHTML = '<em><%:Unknown error%></em>' ;
46                                         break;
47                                 case "_never_":
48                                         lup.innerHTML = '<em><%:Never%></em>' ;
49                                         break;
50                                 default:
51                                         lup.innerHTML = data[i].datelast;
52                                         break;
53                         }
54
55                         // next update
56                         switch (data[i].datenext) {
57                                 case "_empty_":
58                                         nup.innerHTML = '<em><%:Unknown error%></em>' ;
59                                         break;
60                                 case "_verify_":
61                                         nup.innerHTML = '<em><%:Verify%></em>';
62                                         break;
63                                 case "_runonce_":
64                                 case "_stopped_":
65                                 case "_disabled_":
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>';
70                                         } else {
71                                                 nup.innerHTML = '<em><%:Disabled%></em>';
72                                                 btn.value = '----------';
73                                                 btn.className = "cbi-button cbi-input-button";  // no image
74                                                 btn.disabled = true;    // disabled 
75                                         }
76                                         break;
77                                 default:
78                                         nup.innerHTML = data[i].datenext;
79                                         break;
80                         }
81
82                         // domain
83                         // (data[i].domain ignored here
84
85                         // registered IP
86                         // rip.innerHTML = "Registered IP";
87                         if (data[i].domain == "_nodomain_") 
88                                 rip.innerHTML = '';
89                         else if (data[i].reg_ip == "_nodata_")
90                                 rip.innerHTML = '<em><%:No data%></em>';
91                         else
92                                 rip.innerHTML = data[i].reg_ip;
93                 
94                         // monitored interfacce
95                         // data[i].iface ignored here
96                 }
97         }
98
99         // event handler for enabled checkbox
100         function onchange_enabled(id) {
101                 // run original function in cbi.js
102                 // whatever is done there
103                 cbi_d_update(id);
104
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
109
110                 var pid_txt = btn.value;
111                 var pid_found = ( pid_txt.search("PID") >= 0 ) ? true : false;
112
113                 if (pid_found) {
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;
121                 } else {
122                         btn.value = '----------';
123                         btn.className = "cbi-button cbi-input-button";  // no image
124                         btn.disabled = true;            // disabled 
125                 }               
126         }
127
128         // event handler for start/stop button
129         function onclick_startstop(id) {
130                 // extract section              
131                 var section = _id2section(id);
132                 // get elements
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
136
137                 // make me visible
138                 obj.parentNode.style.display = "block";
139
140                 // do start/stop
141                 var btnXHR = new XHR();
142                 btnXHR.get('<%=luci.dispatcher.build_url("admin", "services", "ddns", "startstop")%>/' + section + '/' + cbx.checked, null,
143                         function(x, data) {
144                                 if (x.responseText == "_uncommited_") {
145                                         // we need a trick to display Ampersand "&" in stead of "&#38;" or "&amp;"
146                                         // after translation
147                                         txt="<%:Please [Save & Apply] your changes first%>";
148                                         alert( txt.replace(new RegExp("<%:&%>", "g"), "&") );
149                                 } else {
150                                         // should have data because status changed
151                                         // so update screen
152                                         if (data)
153                                                 _data2elements(data);
154                                 }
155                                 // make me invisible
156                                 obj.parentNode.style.display = "none";
157                         }
158                 );
159         }
160
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,
165                 function(x, data)
166                 {
167                         _data2elements(data);
168                 }                       
169         );
170
171 //]]></script>
172
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>
177 </fieldset>
178 <!-- ++ END ++ Dynamic DNS ++ overview_status.htm ++ -->