apply_widget.htm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <style type="text/css">
  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 type="text/javascript">//<![CDATA[
  40. var xhr = new XHR(),
  41. uci_apply_rollback = <%=math.max(luci.config and luci.config.apply and luci.config.apply.rollback or 30, 30)%>,
  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) indicator.style.display = 'none';
  79. docker_status_message('notice', '<%:Docker actions done.%>');
  80. document.body.classList.remove('apply-overlay-active');
  81. window.clearTimeout(tt);
  82. return;
  83. }
  84. loading_msg = resjson?resjson.info:loading_msg
  85. // var delay = isNaN(duration) ? 0 : Math.max(1000 - duration, 0);
  86. var delay =1000
  87. window.setTimeout(function() {
  88. xhr.get('<%=url("admin/docker/confirm")%>', null, call, uci_apply_timeout * 1000);
  89. }, delay);
  90. };
  91. var tick = function() {
  92. var now = Date.now();
  93. docker_status_message('notice',
  94. '<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;">' +
  95. loading_msg + '</span>');
  96. tt = window.setTimeout(tick, 200);
  97. ts = now;
  98. };
  99. tick();
  100. /* wait a few seconds for the settings to become effective */
  101. window.setTimeout(call, Math.max(uci_apply_holdoff * 1000 , 1));
  102. }
  103. // document.getElementsByTagName("form")[0].addEventListener("submit", (e)=>{
  104. // uci_confirm_docker()
  105. // })
  106. function fnSubmitForm(el){
  107. if (el.id != "cbid.table.1._new") {
  108. uci_confirm_docker()
  109. }
  110. }
  111. <% if self.err then -%>
  112. docker_status_message('warning', '<span style="white-space:pre-line; word-break:break-all; font-family: \'Courier New\', Courier, monospace;">'+`<%=self.err%>`+'</span>');
  113. document.getElementById('docker_apply_overlay').addEventListener("click", (e)=>{
  114. docker_status_message()
  115. })
  116. <%- end %>
  117. window.onload= function (){
  118. var buttons = document.querySelectorAll('input[type="submit"]');
  119. [].slice.call(buttons).forEach(function (el) {
  120. el.onclick = fnSubmitForm.bind(this, el);
  121. });
  122. }
  123. //]]></script>