2
0

js.htm 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <script type="text/javascript">
  2. //<![CDATA[
  3. function button_action(action) {
  4. var xhr = new XHR(false);
  5. var btn_start = document.getElementById("btn_start");
  6. var btn_action = document.getElementById("btn_action");
  7. var btn_stop = document.getElementById("btn_stop");
  8. var btn_enable = document.getElementById("btn_enable");
  9. var btn_disable = document.getElementById("btn_disable");
  10. var btn_spinner;
  11. switch (action.name) {
  12. case "start":
  13. btn_spinner = document.getElementById("btn_start_spinner");
  14. break;
  15. case "action":
  16. btn_spinner = document.getElementById("btn_action_spinner");
  17. break;
  18. case "stop":
  19. btn_spinner = document.getElementById("btn_stop_spinner");
  20. break;
  21. case "enable":
  22. btn_spinner = document.getElementById("btn_enable_spinner");
  23. break;
  24. case "disable":
  25. btn_spinner = document.getElementById("btn_disable_spinner");
  26. break;
  27. }
  28. btn_start.disabled = true;
  29. btn_action.disabled = true;
  30. btn_stop.disabled = true;
  31. btn_enable.disabled = true;
  32. btn_disable.disabled = true;
  33. spinner(btn_spinner, 1);
  34. xhr.get('<%=luci.dispatcher.build_url("admin", "services", "https-dns-proxy", "action")%>/' + action.name, null,
  35. function (x) {
  36. if (!x) {
  37. return;
  38. }
  39. btn_start.disabled = false;
  40. btn_action.disabled = false;
  41. btn_stop.disabled = false;
  42. btn_enable.disabled = false;
  43. btn_disable.disabled = false;
  44. spinner(btn_spinner, 0);
  45. location.reload();
  46. });
  47. }
  48. function spinner(element, state) {
  49. if (state === 1) {
  50. element.style.width = "16px";
  51. element.innerHTML = '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" width="16" height="16" style="vertical-align:middle" />';
  52. }
  53. else {
  54. element.style.width = "0px";
  55. element.innerHTML = '';
  56. }
  57. }
  58. //]]>
  59. </script>