37c54be25fa059599c37fcda7586d73e0abcbd24
[project/luci.git] / applications / luci-app-ddns / luasrc / view / ddns / overview_status.htm
1
2 <!-- ++ BEGIN ++ Dynamic DNS ++ overview_status.htm ++ -->
3 <script type="text/javascript">//<![CDATA[
4
5         // variables to store version information
6         var luci_version
7         var luci_build
8         var ddns_version
9         var ddns_required
10
11         // helper to extract section from objects id
12         // cbi.ddns.SECTION._xyz
13         function _id2section(id) {
14                 var x = id.split(".");
15                 return x[2];
16         }
17
18         // helper to move status data to the relevant
19         // screen objects
20         // called by XHR.poll and onclick_startstop
21         function _data2elements(data) {
22                 // DDNS Service
23                 // fill Version informations
24                 luci_version  = data[0].luci_ver
25                 luci_build    = data[0].luci_build
26                 ddns_version  = data[0].script_ver
27                 ddns_required = data[0].script_min
28
29                 // Service sections
30                 for( i = 1; i < data.length; i++ )
31                 {
32                         var section = data[i].section   // Section to handle
33                         var cbx = document.getElementById("cbid.ddns." + section + ".enabled");         // Enabled
34                         var btn = document.getElementById("cbid.ddns." + section + "._startstop");      // Start/Stop button
35                         var rip = document.getElementById("cbid.ddns." + section + "._domainIP.two");   // Registered IP
36                         var lup = document.getElementById("cbid.ddns." + section + "._update.one");     // Last Update
37                         var nup = document.getElementById("cbid.ddns." + section + "._update.two");     // Next Update
38                         if ( !(cbx && btn && rip && lup && nup) ) { return; }   // security check
39
40                         // process id
41                         if (data[i].pid > 0) {
42                                 // stop always possible if process running
43                                 btn.value = "PID: " + data[i].pid;
44                                 btn.className = "cbi-button cbi-input-reset";
45                         } else {
46                                 // default Start / enabled
47                                 btn.value = "<%:Start%>";
48                                 btn.className = "cbi-button cbi-input-apply";
49                         }
50                         btn.disabled = false;   // button enabled
51
52                         // last update
53                         switch (data[i].datelast) {
54                                 case "_empty_":
55                                         lup.innerHTML = '<em><%:Unknown error%></em>' ;
56                                         break;
57                                 case "_never_":
58                                         lup.innerHTML = '<em><%:Never%></em>' ;
59                                         break;
60                                 default:
61                                         lup.innerHTML = data[i].datelast;
62                                         break;
63                         }
64
65                         // next update
66                         switch (data[i].datenext) {
67                                 case "_empty_":
68                                         nup.innerHTML = '<em><%:Unknown error%></em>' ;
69                                         break;
70                                 case "_verify_":
71                                         nup.innerHTML = '<em><%:Verify%></em>';
72                                         break;
73                                 case "_runonce_":
74                                 case "_stopped_":
75                                 case "_disabled_":
76                                         if (cbx.checked && data[i].datenext == "_runonce_") {
77                                                 nup.innerHTML = '<em><%:Run once%></em>';
78                                         } else if (cbx.checked) {
79                                                 nup.innerHTML = '<em><%:Stopped%></em>';
80                                         } else {
81                                                 nup.innerHTML = '<em><%:Disabled%></em>';
82                                                 btn.value = '----------';
83                                                 btn.className = "cbi-button cbi-input-button";  // no image
84                                                 btn.disabled = true;    // disabled
85                                         }
86                                         break;
87                                 default:
88                                         nup.innerHTML = data[i].datenext;
89                                         break;
90                         }
91
92                         // domain
93                         // (data[i].domain ignored here
94
95                         // registered IP
96                         // rip.innerHTML = "Registered IP";
97                         if (data[i].domain == "_nodomain_")
98                                 rip.innerHTML = '';
99                         else if (data[i].reg_ip == "_nodata_")
100                                 rip.innerHTML = '<em><%:No data%></em>';
101                         else
102                                 rip.innerHTML = data[i].reg_ip;
103
104                         // monitored interfacce
105                         // data[i].iface ignored here
106                 }
107         }
108
109         // event handler for enabled checkbox
110         function onchange_enabled(id) {
111                 // run original function in cbi.js
112                 // whatever is done there
113                 cbi_d_update(id);
114
115                 var section = _id2section(id);
116                 var cbx = document.getElementById("cbid.ddns." + section + ".enabled");
117                 var btn = document.getElementById("cbid.ddns." + section + "._startstop");
118                 if ( !(cbx && btn) ) { return; }        // security check
119
120                 var pid_txt = btn.value;
121                 var pid_found = ( pid_txt.search("PID") >= 0 ) ? true : false;
122
123                 if (pid_found) {
124                         // btn.value = "PID: 0000";
125                         btn.className = "cbi-button cbi-button-reset";
126                         btn.disabled = false;
127                 } else if (cbx.checked) {
128                         btn.value = "<%:Start%>";
129                         btn.className = "cbi-button cbi-button-apply";
130                         btn.disabled = false;
131                 } else {
132                         btn.value = '----------';
133                         btn.className = "cbi-button cbi-input-button";  // no image
134                         btn.disabled = true;            // disabled
135                 }
136         }
137
138         // event handler for map.title link
139         function onclick_maptitle() {
140                 var str = "<%:Version Information%>";
141                 str += "\n\nluci-app-ddns:";
142                 str += "\n\t<%:Version%>:\t" + luci_version;
143                 str += "\n\t<%:Build%>:\t" + luci_build;
144                 str += "\n\nddns-scripts <%:required%>:";
145                 str += "\n\t<%:Version%>:\t" + ddns_required + " <%:or greater%>";
146                 str += "\n\nddns-scripts <%:installed%>:";
147                 str += "\n\t<%:Version%>:\t" + ddns_version;
148                 str += "\n\n"
149                 alert(str);
150         }
151
152         // event handler for start/stop button
153         function onclick_startstop(id) {
154                 // extract section
155                 var section = _id2section(id);
156                 // get elements
157                 var cbx = document.getElementById("cbid.ddns." + section + ".enabled");         // Enabled
158                 var obj = document.getElementById("cbi-ddns-overview-status-legend");           // objext defined below to make in-/visible
159                 if ( !(obj && cbx) ) { return; }        // security check
160
161                 // make me visible
162                 obj.parentNode.style.display = "block";
163
164                 // do start/stop
165                 var btnXHR = new XHR();
166                 btnXHR.get('<%=luci.dispatcher.build_url("admin", "services", "ddns", "startstop")%>/' + section + '/' + cbx.checked, null,
167                         function(x, data) {
168                                 if (x.responseText == "_uncommited_") {
169                                         // we need a trick to display Ampersand "&" in stead of "&#38;" or "&amp;"
170                                         // after translation
171                                         txt="<%:Please [Save & Apply] your changes first%>";
172                                         alert( txt.replace(new RegExp("<%:&%>", "g"), "&") );
173                                 } else {
174                                         // should have data because status changed
175                                         // so update screen
176                                         if (data)
177                                                 _data2elements(data);
178                                 }
179                                 // make me invisible
180                                 obj.parentNode.style.display = "none";
181                         }
182                 );
183         }
184
185         // force to immediate show status on page load (not waiting for XHR.poll)
186         XHR.get('<%=luci.dispatcher.build_url("admin", "services", "ddns", "status")%>', null,
187                 function(x, data) {
188                         _data2elements(data);
189                 }
190         );
191
192         // define only ONE XHR.poll in a page because if one is running it blocks the other one
193         // optimum is to define on Map or Section Level from here you can reach all elements
194         // we need update every 15 seconds only
195         XHR.poll(15, '<%=luci.dispatcher.build_url("admin", "services", "ddns", "status")%>', null,
196                 function(x, data) {
197                         _data2elements(data);
198                 }
199         );
200
201 //]]></script>
202
203 <fieldset class="cbi-section" style="display:none">
204         <legend id="cbi-ddns-overview-status-legend"><%:Applying changes%></legend>
205         <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
206         <span id="cbi-ddns-overview-status-text"><%:Waiting for changes to be applied...%></span>
207 </fieldset>
208 <!-- ++ END ++ Dynamic DNS ++ overview_status.htm ++ -->