summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-dockerman/luasrc/view/dockerman/images_import.htm
blob: b87759d00ff223ec258f9f95496233e4acb46ff8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<input type="text" class="cbi-input-text" name="isrc" placeholder="http://host/image.tar" id="isrc" />
<input type="text" class="cbi-input-text" name="itag" placeholder="repository:tag" id="itag" />
<div style="display: inline-block;">
	<input type="button"" class="btn cbi-button cbi-button-add" id="btnimport" name="import" value="<%:Import%>" />
	<input type="file" id="file_import" style="visibility:hidden; position: absolute;top: 0px; left: 0px;" />
</div>

<script type="text/javascript">
	let btnImport = document.getElementById('btnimport')
	let valISrc = document.getElementById('isrc')
	let valITag = document.getElementById('itag')
	btnImport.onclick = function (e) {
		if (valISrc.value == "") {
			document.getElementById("file_import").click()
			return
		}
		else {
			let formData = new FormData()
			formData.append('src', valISrc.value)
			formData.append('tag', valITag.value)
			let xhr = new XMLHttpRequest()
			uci_confirm_docker()
			xhr.open("POST", "<%=luci.dispatcher.build_url('admin/docker/images_import')%>", true)
			xhr.onload = function () {
				location.reload()
			}
			xhr.send(formData)
		}
	}

	let fileimport = document.getElementById('file_import')
	fileimport.onchange = function (e) {
		let fileimport = document.getElementById('file_import')
		if (!fileimport.value) {
			return
		}
		let valITag = document.getElementById('itag')
		let fileName = fileimport.files[0].name
		let formData = new FormData()
		formData.append('upload-filename', fileName)
		formData.append('tag', valITag.value)
		formData.append('upload-archive', fileimport.files[0])
		let xhr = new XMLHttpRequest()
		uci_confirm_docker()
		xhr.open("POST", "<%=luci.dispatcher.build_url('admin/docker/images_import')%>", true)
		xhr.onload = function () {
			fileimport.value = ''
			location.reload()
		}
		xhr.send(formData)
	}

	let new_tag = function (image_id) {
		let new_tag = prompt("<%:New tag%>\n<%:Image%>" + "ID: " + image_id + "\n<%:Please input new tag%>:", "")
		if (new_tag) {
			(new XHR()).post("<%=luci.dispatcher.build_url('admin/docker/images_tag')%>",
				{
					id: image_id,
					tag: new_tag
				},
				function (r) {
					if (r.status == 201) {
						location.reload()
					}
					else {
						docker_status_message('warning', 'Image: untagging ' + tag + '...fail code:' + r.status + r.statusText);
						document.getElementById('docker_apply_overlay').addEventListener(
							"click",
							(e)=>{
								docker_status_message()
							}
						)
					}
				}
			)
		}
	}

	let un_tag = function (tag) {
		if (tag.match("<none>"))
			return
		if (confirm("<%:Remove tag%>: " + tag + " ?")) {
			(new XHR()).post("<%=luci.dispatcher.build_url('admin/docker/images_untag')%>",
				{
					tag: tag
				},
				function (r) {
					if (r.status == 200) {
						location.reload()
					}
					else {
						docker_status_message('warning', 'Image: untagging ' + tag + '...fail code:' + r.status + r.statusText);
						document.getElementById('docker_apply_overlay').addEventListener(
							"click",
							(e)=>{
								docker_status_message()
							}
						)
					}
				}
			)
		}
	}
</script>