images_import.htm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <input type="text" class="cbi-input-text" name="isrc" placeholder="http://host/image.tar" id="isrc" />
  2. <input type="text" class="cbi-input-text" name="itag" placeholder="repository:tag" id="itag" />
  3. <div style="display: inline-block;">
  4. <input type="button"" class="btn cbi-button cbi-button-add" id="btnimport" name="import" value="<%:Import%>" />
  5. <input type="file" id="file_import" style="visibility:hidden; position: absolute;top: 0px; left: 0px;" />
  6. </div>
  7. <script>
  8. let btnImport = document.getElementById('btnimport')
  9. let valISrc = document.getElementById('isrc')
  10. let valITag = document.getElementById('itag')
  11. btnImport.onclick = function (e) {
  12. if (valISrc.value == "") {
  13. document.getElementById("file_import").click()
  14. return
  15. }
  16. else {
  17. let formData = new FormData()
  18. formData.append('src', valISrc.value)
  19. formData.append('tag', valITag.value)
  20. let xhr = new XMLHttpRequest()
  21. uci_confirm_docker()
  22. xhr.open("POST", "<%=luci.dispatcher.build_url('admin/docker/images_import')%>", true)
  23. xhr.onload = function () {
  24. location.reload()
  25. }
  26. xhr.send(formData)
  27. }
  28. }
  29. let fileimport = document.getElementById('file_import')
  30. fileimport.onchange = function (e) {
  31. let fileimport = document.getElementById('file_import')
  32. if (!fileimport.value) {
  33. return
  34. }
  35. let valITag = document.getElementById('itag')
  36. let fileName = fileimport.files[0].name
  37. let formData = new FormData()
  38. formData.append('upload-filename', fileName)
  39. formData.append('tag', valITag.value)
  40. formData.append('upload-archive', fileimport.files[0])
  41. let xhr = new XMLHttpRequest()
  42. uci_confirm_docker()
  43. xhr.open("POST", "<%=luci.dispatcher.build_url('admin/docker/images_import')%>", true)
  44. xhr.onload = function () {
  45. fileimport.value = ''
  46. location.reload()
  47. }
  48. xhr.send(formData)
  49. }
  50. let new_tag = function (image_id) {
  51. let new_tag = prompt("<%:New tag%>\n<%:Image%>" + "ID: " + image_id + "\n<%:Please input new tag%>:", "")
  52. if (new_tag) {
  53. (new XHR()).post("<%=luci.dispatcher.build_url('admin/docker/images_tag')%>",
  54. {
  55. id: image_id,
  56. tag: new_tag
  57. },
  58. function (r) {
  59. if (r.status == 201) {
  60. location.reload()
  61. }
  62. else {
  63. docker_status_message('warning', 'Image: untagging ' + tag + '...fail code:' + r.status + r.statusText);
  64. document.getElementById('docker_apply_overlay').addEventListener(
  65. "click",
  66. (e)=>{
  67. docker_status_message()
  68. }
  69. )
  70. }
  71. }
  72. )
  73. }
  74. }
  75. let un_tag = function (tag) {
  76. if (tag.match("<none>"))
  77. return
  78. if (confirm("<%:Remove tag%>: " + tag + " ?")) {
  79. (new XHR()).post("<%=luci.dispatcher.build_url('admin/docker/images_untag')%>",
  80. {
  81. tag: tag
  82. },
  83. function (r) {
  84. if (r.status == 200) {
  85. location.reload()
  86. }
  87. else {
  88. docker_status_message('warning', 'Image: untagging ' + tag + '...fail code:' + r.status + r.statusText);
  89. document.getElementById('docker_apply_overlay').addEventListener(
  90. "click",
  91. (e)=>{
  92. docker_status_message()
  93. }
  94. )
  95. }
  96. }
  97. )
  98. }
  99. }
  100. </script>