images_load.htm 1.0 KB

123456789101112131415161718192021222324252627282930
  1. <div style="display: inline-block;">
  2. <input type="button"" class="btn cbi-button cbi-button-add" id="btnload" name="load" value="<%:Load%>" />
  3. <input type="file" id="file_load" style="visibility:hidden; position: absolute;top: 0px; left: 0px;" accept="application/x-tar" />
  4. </div>
  5. <script>
  6. let btnLoad = document.getElementById('btnload')
  7. btnLoad.onclick = function (e) {
  8. document.getElementById("file_load").click()
  9. e.preventDefault()
  10. }
  11. let fileLoad = document.getElementById('file_load')
  12. fileLoad.onchange = function(e){
  13. let fileLoad = document.getElementById('file_load')
  14. if (!fileLoad.value) {
  15. return
  16. }
  17. let fileName = fileLoad.files[0].name
  18. let formData = new FormData()
  19. formData.append('upload-filename', fileName)
  20. formData.append('upload-archive', fileLoad.files[0])
  21. let xhr = new XMLHttpRequest()
  22. uci_confirm_docker()
  23. xhr.open("POST", '<%=luci.dispatcher.build_url("admin/docker/images_load")%>', true)
  24. xhr.onload = function() {
  25. location.reload()
  26. }
  27. xhr.send(formData)
  28. }
  29. </script>