apply_widget.htm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <style>
  2. #docker_apply_overlay {
  3. position: absolute;
  4. top: 0;
  5. left: 0;
  6. bottom: 0;
  7. right: 0;
  8. background: rgba(0, 0, 0, 0.7);
  9. display: none;
  10. z-index: 20000;
  11. }
  12. #docker_apply_overlay .alert-message {
  13. position: relative;
  14. top: 10%;
  15. width: 60%;
  16. margin: auto;
  17. display: flex;
  18. flex-wrap: wrap;
  19. min-height: 32px;
  20. align-items: center;
  21. }
  22. #docker_apply_overlay .alert-message > h4,
  23. #docker_apply_overlay .alert-message > p,
  24. #docker_apply_overlay .alert-message > div {
  25. flex-basis: 100%;
  26. }
  27. #docker_apply_overlay .alert-message > img {
  28. margin-right: 1em;
  29. flex-basis: 32px;
  30. }
  31. body.apply-overlay-active {
  32. overflow: hidden;
  33. height: 100vh;
  34. }
  35. body.apply-overlay-active #docker_apply_overlay {
  36. display: block;
  37. }
  38. </style>
  39. <script>
  40. var xhr = new XHR(),
  41. uci_apply_rollback = <%=math.max(luci.config and luci.config.apply and luci.config.apply.rollback or 90, 90)%>,
  42. uci_apply_holdoff = <%=math.max(luci.config and luci.config.apply and luci.config.apply.holdoff or 4, 1)%>,
  43. uci_apply_timeout = <%=math.max(luci.config and luci.config.apply and luci.config.apply.timeout or 5, 1)%>,
  44. uci_apply_display = <%=math.max(luci.config and luci.config.apply and luci.config.apply.display or 1.5, 1)%>,
  45. was_xhr_poll_running = false;
  46. function docker_status_message(type, content) {
  47. document.getElementById('docker_apply_overlay') || document.body.insertAdjacentHTML("beforeend",'<div id="docker_apply_overlay"><div class="alert-message"></div></div>')
  48. var overlay = document.getElementById('docker_apply_overlay')
  49. message = overlay.querySelector('.alert-message');
  50. if (message && type) {
  51. if (!message.classList.contains(type)) {
  52. message.classList.remove('notice');
  53. message.classList.remove('warning');
  54. message.classList.add(type);
  55. }
  56. if (content)
  57. message.innerHTML = content;
  58. document.body.classList.add('apply-overlay-active');
  59. document.body.scrollTop = document.documentElement.scrollTop = 0;
  60. if (!was_xhr_poll_running) {
  61. was_xhr_poll_running = XHR.running();
  62. XHR.halt();
  63. }
  64. }
  65. else {
  66. document.body.classList.remove('apply-overlay-active');
  67. if (was_xhr_poll_running)
  68. XHR.run();
  69. }
  70. }
  71. var loading_msg="Loading.."
  72. function uci_confirm_docker() {
  73. var tt;
  74. docker_status_message('notice');
  75. var call = function(r, resjson, duration) {
  76. if (r && r.status === 200 ) {
  77. var indicator = document.querySelector('.uci_change_indicator');
  78. if (indicator)
  79. indicator.style.display = 'none';
  80. docker_status_message('notice', '<%:Docker actions done.%>');
  81. document.body.classList.remove('apply-overlay-active');
  82. window.clearTimeout(tt);
  83. return;
  84. }
  85. loading_msg = resjson?resjson.info:loading_msg
  86. // var delay = isNaN(duration) ? 0 : Math.max(1000 - duration, 0);
  87. var delay =1000
  88. window.setTimeout(function() {
  89. xhr.get('<%=url("admin/docker/confirm")%>', null, call, uci_apply_timeout * 1000);
  90. },delay);
  91. };
  92. var tick = function() {
  93. var now = Date.now();
  94. docker_status_message(
  95. 'notice',
  96. '<img src="<%=resource%>/icons/loading.gif" alt="" style="vertical-align:middle" /> <span style="white-space:pre-line; word-break:break-all; font-family: \'Courier New\', Courier, monospace;">' + loading_msg + '</span>'
  97. );
  98. tt = window.setTimeout(tick, 200);
  99. ts = now;
  100. };
  101. tick();
  102. /* wait a few seconds for the settings to become effective */
  103. window.setTimeout(call, Math.max(uci_apply_holdoff * 1000 , 1));
  104. }
  105. // document.getElementsByTagName("form")[0].addEventListener("submit", (e)=>{
  106. // uci_confirm_docker()
  107. // })
  108. function fnSubmitForm(el){
  109. if (el.id != "cbid.table.1._new") {
  110. uci_confirm_docker()
  111. }
  112. }
  113. <% if self.err then -%>
  114. docker_status_message('warning', '<span style="white-space:pre-line; word-break:break-all; font-family: \'Courier New\', Courier, monospace;">'+`<%=self.err%>`+'</span>');
  115. document.getElementById('docker_apply_overlay').addEventListener(
  116. "click",
  117. (e)=>{
  118. docker_status_message()
  119. }
  120. )
  121. <%- end %>
  122. window.onload= function (){
  123. var buttons = document.querySelectorAll('input[type="submit"]');
  124. [].slice.call(buttons).forEach(function (el) {
  125. el.onclick = fnSubmitForm.bind(this, el);
  126. });
  127. }
  128. </script>