container_file.htm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <div id="upload-container" class="cbi-value cbi-value-last">
  2. <label class="cbi-value-title" for="archive"><%:Upload%></label>
  3. <div class="cbi-value-field">
  4. <input type="file" name="upload_archive" accept="application/x-tar" id="upload_archive" />
  5. </div>
  6. <br>
  7. <label class="cbi-value-title" for="path"><%:Path%></label>
  8. <div class="cbi-value-field">
  9. <input type="text" class="cbi-input-text" name="path" value="/tmp/" id="path" />
  10. </div>
  11. <br>
  12. <div class="cbi-value-field">
  13. <input type="button"" class="cbi-button cbi-button-action important" id="upload" name="upload" value="<%:Upload%>" />
  14. <input type="button"" class="cbi-button cbi-button-action important" id="download" name="download" value="<%:Download%>" />
  15. </div>
  16. </div>
  17. <script type="text/javascript">
  18. let btnUpload = document.getElementById('upload')
  19. btnUpload.onclick = function (e) {
  20. let uploadArchive = document.getElementById('upload_archive')
  21. let uploadPath = document.getElementById('path').value
  22. if (!uploadArchive.value || !uploadPath) {
  23. docker_status_message('warning', "<%:Please input the PATH and select the file !%>")
  24. document.getElementById('docker_apply_overlay').addEventListener("click", (e)=>{
  25. docker_status_message()
  26. })
  27. return
  28. }
  29. let fileName = uploadArchive.files[0].name
  30. let formData = new FormData()
  31. formData.append('upload-filename', fileName)
  32. formData.append('upload-path', uploadPath)
  33. formData.append('upload-archive', uploadArchive.files[0])
  34. let xhr = new XMLHttpRequest()
  35. xhr.open("POST", '<%=luci.dispatcher.build_url("admin/docker/container_put_archive")%>/<%=self.container%>', true)
  36. xhr.onload = function() {
  37. if (xhr.status == 200) {
  38. uploadArchive.value = ''
  39. docker_status_message('notice', "<%:Upload Success%>")
  40. }
  41. else {
  42. docker_status_message('warning', "<%:Upload Error%>:" + xhr.statusText)
  43. }
  44. document.getElementById('docker_apply_overlay').addEventListener("click", (e)=>{
  45. docker_status_message()
  46. })
  47. }
  48. xhr.send(formData)
  49. }
  50. let btnDownload = document.getElementById('download')
  51. btnDownload.onclick = function (e) {
  52. let downloadPath = document.getElementById('path').value
  53. if (!downloadPath) {
  54. docker_status_message('warning', "<%:Please input the PATH !%>")
  55. document.getElementById('docker_apply_overlay').addEventListener("click", (e)=>{
  56. docker_status_message()
  57. })
  58. return
  59. }
  60. window.open('<%=luci.dispatcher.build_url("admin/docker/container_get_archive")%>?id=<%=self.container%>&path=' + encodeURIComponent(downloadPath))
  61. }
  62. </script>