btn_startstop.htm 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <!-- ++ BEGIN ++ Radicale ++ btn_startstop.htm ++ -->
  2. <script type="text/javascript">//<![CDATA[
  3. // show XHR.poll/XHR.get response on button
  4. function _data2elements(x) {
  5. var btn = document.getElementById("cbid.radicale.<%=section%>._startstop");
  6. if ( ! btn ) { return; } // security check
  7. if (x.responseText == "0") {
  8. btn.value = "<%:Start%>";
  9. btn.className = "cbi-button cbi-button-apply";
  10. btn.disabled = false;
  11. } else {
  12. btn.value = "PID: " + x.responseText;
  13. btn.className = "cbi-button cbi-button-reset";
  14. btn.disabled = false;
  15. }
  16. }
  17. // event handler for start/stop button
  18. function onclick_startstop(id) {
  19. // do start/stop
  20. var btnXHR = new XHR();
  21. btnXHR.post('<%=url([[admin/services/radicale/startstop]])%>', { token: '<%=token%>' },
  22. function(x) { _data2elements(x); }
  23. );
  24. }
  25. XHR.poll(5, '<%=url([[admin/services/radicale/status]])%>', null,
  26. function(x, data) { _data2elements(x); }
  27. );
  28. //]]></script>
  29. <%+cbi/valueheader%>
  30. <% if self:cfgvalue(section) ~= false then
  31. -- We need to garantie that function cfgvalue run first to set missing parameters
  32. %>
  33. <!-- style="font-size: 100%;" needed for openwrt theme to fix font size -->
  34. <!-- type="button" onclick="..." enable standard onclick functionalty -->
  35. <input class="cbi-button cbi-input-<%=self.inputstyle or "button" %>" style="font-size: 100%;" type="button" onclick="onclick_startstop(this.id)"
  36. <%=
  37. attr("name", section) .. attr("id", cbid) .. attr("value", self.inputtitle) .. ifattr(self.disabled, "disabled")
  38. %> />
  39. <% end %>
  40. <%+cbi/valuefooter%>
  41. <!-- ++ END ++ Radicale ++ btn_startstop.htm ++ -->