newcontainer_resolve.htm 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <style type="text/css">
  2. #dialog_reslov {
  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. #dialog_reslov .dialog_box {
  13. position: relative;
  14. background: rgba(255, 255, 255);
  15. top: 10%;
  16. width: 50%;
  17. margin: auto;
  18. display: flex;
  19. flex-wrap: wrap;
  20. height:auto;
  21. align-items: center;
  22. }
  23. #dialog_reslov .dialog_line {
  24. margin-top: .5em;
  25. margin-bottom: .5em;
  26. margin-left: 2em;
  27. margin-right: 2em;
  28. }
  29. #dialog_reslov .dialog_box>h4,
  30. #dialog_reslov .dialog_box>p,
  31. #dialog_reslov .dialog_box>div {
  32. flex-basis: 100%;
  33. }
  34. #dialog_reslov .dialog_box>img {
  35. margin-right: 1em;
  36. flex-basis: 32px;
  37. }
  38. body.dialog-reslov-active {
  39. overflow: hidden;
  40. height: 100vh;
  41. }
  42. body.dialog-reslov-active #dialog_reslov {
  43. display: block;
  44. }
  45. </style>
  46. <script type="text/javascript">
  47. function close_reslov_dialog() {
  48. document.body.classList.remove('dialog-reslov-active')
  49. document.documentElement.style.overflowY = 'scroll'
  50. }
  51. function reslov_container() {
  52. let s = document.getElementById('cmd-line-status')
  53. if (!s) return
  54. let cmd_line = document.getElementById("dialog_reslov_text").value;
  55. if (cmd_line == null || cmd_line == "") {
  56. return
  57. }
  58. cmd_line = cmd_line.replace(/(^\s*)/g,"")
  59. if (!cmd_line.match(/^docker\s+(run|create)/)) {
  60. s.innerHTML = "<font color='red'><%:Command line Error%></font>"
  61. return
  62. }
  63. let reg_space = /\s+/g
  64. let reg_muti_line= /\\\s*\n/g
  65. // reg_rem =/(?<!\\)`#.+(?<!\\)`/g // the command has `# `
  66. let reg_rem =/`#.+`/g// the command has `# `
  67. cmd_line = cmd_line.replace(/^docker\s+(run|create)/,"DOCKERCLI").replace(reg_rem, " ").replace(reg_muti_line, " ").replace(reg_space, " ")
  68. console.log(cmd_line)
  69. window.location.href = '<%=luci.dispatcher.build_url("admin/docker/newcontainer")%>/' + encodeURI(cmd_line)
  70. }
  71. function clear_text(){
  72. let s = document.getElementById('cmd-line-status')
  73. s.innerHTML = ""
  74. }
  75. function show_reslov_dialog() {
  76. document.getElementById('dialog_reslov') || document.body.insertAdjacentHTML("beforeend", '<div id="dialog_reslov"><div class="dialog_box"><div class="dialog_line"></div><div class="dialog_line"><span><%:Plese input <docker create/run> command line:%></span><br><span id="cmd-line-status"></span></div><div class="dialog_line"><textarea class="cbi-input-textarea" id="dialog_reslov_text" style="width: 100%; height:100%;" rows="15" onkeyup="clear_text()"></textarea></div><div class="dialog_line" style="text-align: right;"><input type="button" class="cbi-button cbi-button-apply" type="submit" value="<%:Submit%>" onclick="reslov_container()" /> <input type="button" class="cbi-button cbi-button-reset" type="reset" value="<%:Cancel%>" onclick="close_reslov_dialog()" /></div><div class="dialog_line"></div></div></div>')
  77. document.body.classList.add('dialog-reslov-active')
  78. let s = document.getElementById('cmd-line-status')
  79. s.innerHTML = ""
  80. document.documentElement.style.overflowY = 'hidden'
  81. }
  82. </script>
  83. <%+cbi/valueheader%>
  84. <input type="button" class="cbi-button cbi-button-apply" value="<%:Command line%>" onclick="show_reslov_dialog()" />
  85. <%+cbi/valuefooter%>