summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-dockerman/luasrc/view/dockerman/container_file.htm
blob: ab5ecdd488ca10b97ca5b8ca17e8389fa89ef467 (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
<div id="upload-container" class="cbi-value cbi-value-last">
	<label class="cbi-value-title" for="archive"><%:Upload%></label>
	<div class="cbi-value-field">
		<input type="file" name="upload_archive" accept="application/x-tar" id="upload_archive" />
	</div>
	<br>
	<label class="cbi-value-title" for="path"><%:Path%></label>
	<div class="cbi-value-field">
		<input type="text" class="cbi-input-text" name="path" value="/tmp/" id="path" />
	</div>
	<br>
	<div class="cbi-value-field">
		<input type="button"" class="btn cbi-button cbi-button-action important" id="upload" name="upload" value="<%:Upload%>" />
		<input type="button"" class="btn cbi-button cbi-button-action important" id="download" name="download" value="<%:Download%>" />
	</div>
</div>

<script type="text/javascript">
	let btnUpload = document.getElementById('upload')
	btnUpload.onclick = function (e) {
		let uploadArchive = document.getElementById('upload_archive')
		let uploadPath = document.getElementById('path').value
		if (!uploadArchive.value || !uploadPath) {
			docker_status_message('warning', "<%:Please input the PATH and select the file !%>")
			document.getElementById('docker_apply_overlay').addEventListener(
				"click",
				(e)=>{
					docker_status_message()
				}
			)
			return
		}
		let fileName = uploadArchive.files[0].name
		let formData = new FormData()
		formData.append('upload-filename', fileName)
		formData.append('upload-path', uploadPath)
		formData.append('upload-archive', uploadArchive.files[0])
		let xhr = new XMLHttpRequest()
		xhr.open("POST", '<%=luci.dispatcher.build_url("admin/docker/container_put_archive")%>/<%=self.container%>', true)
		xhr.onload = function() {
			if (xhr.status == 200) {
				uploadArchive.value = ''
				docker_status_message('notice', "<%:Upload Success%>")
			}
			else {
				docker_status_message('warning', "<%:Upload Error%>:" + xhr.statusText)
			}
			document.getElementById('docker_apply_overlay').addEventListener(
				"click",
				(e)=>{
					docker_status_message()
				}
			)
		}
		xhr.send(formData)
	}

	let btnDownload = document.getElementById('download')
	btnDownload.onclick = function (e) {
		let downloadPath = document.getElementById('path').value
		if (!downloadPath) {
			docker_status_message('warning', "<%:Please input the PATH !%>")
			document.getElementById('docker_apply_overlay').addEventListener(
				"click",
				(e)=>{
					docker_status_message()
				}
			)
			return
		}
		window.open('<%=luci.dispatcher.build_url("admin/docker/container_get_archive")%>?id=<%=self.container%>&path=' + encodeURIComponent(downloadPath))
	}
</script>