resources/icons: Use gifsicle to save a few bytes.
[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         // 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                 // Service sections
17                 for( i = 1; i < data.length; i++ )
18                 {
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
26
27                         // process id
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";
32                         } else {
33                                 // default Start / enabled
34                                 btn.value = "<%:Start%>";
35                                 btn.className = "cbi-button cbi-input-apply";
36                         }
37                         btn.disabled = false;   // button enabled
38
39                         // last update
40                         switch (data[i].datelast) {
41                                 case "_empty_":
42                                         lup.innerHTML = '<em><%:Unknown error%></em>' ;
43                                         break;
44                                 case "_never_":
45                                         lup.innerHTML = '<em><%:Never%></em>' ;
46                                         break;
47                                 default:
48                                         lup.innerHTML = data[i].datelast;
49                                         break;
50                         }
51
52                         // next update
53                         switch (data[i].datenext) {
54                                 case "_empty_":
55                                         nup.innerHTML = '<em><%:Unknown error%></em>' ;
56                                         break;
57                                 case "_verify_":
58                                         nup.innerHTML = '<em><%:Verify%></em>';
59                                         break;
60                                 case "_runonce_":
61                                 case "_stopped_":
62                                 case "_disabled_":
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>';
67                                         } else {
68                                                 nup.innerHTML = '<em><%:Disabled%></em>';
69                                                 btn.value = '----------';
70                                                 btn.className = "cbi-button cbi-input-button";  // no image
71                                                 btn.disabled = true;    // disabled
72                                         }
73                                         break;
74                                 default:
75                                         nup.innerHTML = data[i].datenext;
76                                         break;
77                         }
78
79                         // domain
80                         // (data[i].domain ignored here
81
82                         // registered IP
83                         // rip.innerHTML = "Registered IP";
84                         if (data[i].domain == "_nodomain_")
85                                 rip.innerHTML = '';
86                         else if (data[i].reg_ip == "_nodata_")
87                                 rip.innerHTML = '<em><%:No data%></em>';
88                         else
89                                 rip.innerHTML = data[i].reg_ip;
90
91                         // monitored interfacce
92                         // data[i].iface ignored here
93                 }
94         }
95
96         // event handler for enabled checkbox
97         function onchange_enabled(id) {
98                 // run original function in cbi.js
99                 // whatever is done there
100                 cbi_d_update(id);
101
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
106
107                 var pid_txt = btn.value;
108                 var pid_found = ( pid_txt.search("PID") >= 0 ) ? true : false;
109
110                 if (pid_found) {
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;
118                 } else {
119                         btn.value = '----------';
120                         btn.className = "cbi-button cbi-input-button";  // no image
121                         btn.disabled = true;            // disabled
122                 }
123         }
124
125         // event handler for start/stop button
126         function onclick_startstop(id) {
127                 // extract section
128                 var section = _id2section(id);
129                 // get elements
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
133
134                 // make me visible
135                 obj.parentNode.style.display = "block";
136
137                 // do start/stop
138                 var btnXHR = new XHR();
139                 btnXHR.get('<%=url('admin/services/ddns/startstop')%>/' + section + '/' + cbx.checked, null,
140                         function(x, data) {
141                                 if (x.responseText == "_uncommitted_") {
142                                         // we need a trick to display Ampersand "&" in stead of "&#38;" or "&amp;"
143                                         // after translation
144                                         txt="<%:Please [Save & Apply] your changes first%>";
145                                         alert( txt.replace(new RegExp("<%:&%>", "g"), "&") );
146                                 } else {
147                                         // should have data because status changed
148                                         // so update screen
149                                         if (data) { _data2elements(data); }
150                                 }
151                                 // make me invisible
152                                 obj.parentNode.style.display = "none";
153                         }
154                 );
155         }
156
157         // force to immediate show status on page load (not waiting for XHR.poll)
158         XHR.get('<%=url('admin/services/ddns/status')%>', null,
159                 function(x, data) {
160                         if (data) { _data2elements(data); }
161                 }
162         );
163
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,
168                 function(x, data) {
169                         if (data) { _data2elements(data); }
170                 }
171         );
172
173 //]]></script>
174
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>
179 </fieldset>
180 <!-- ++ END ++ Dynamic DNS ++ overview_status.htm ++ -->