iris/_examples/file-server/file-server/views/dirlist.html
Gerasimos (Makis) Maropoulos cba6351d62 HandleDir: customize file/dir listing page through registered view engine
Former-commit-id: 98bfd9d5a073c5bc7c2c167e2a72dd7b05bfb24a
2020-07-07 06:11:44 +03:00

121 lines
3.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{.Title}}</title>
<style>
a {
padding: 8px 8px;
text-decoration: none;
cursor: pointer;
color: #10a2ff;
}
table {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
border-collapse: collapse;
border-spacing: 0;
empty-cells: show;
border: 1px solid #cbcbcb;
}
table caption {
color: #000;
font: italic 85%/1 arial, sans-serif;
padding: 1em 0;
text-align: center;
}
table td,
table th {
border-left: 1px solid #cbcbcb;
border-width: 0 0 0 1px;
font-size: inherit;
margin: 0;
overflow: visible;
padding: 0.5em 1em;
}
table thead {
background-color: #10a2ff;
color: #fff;
text-align: left;
vertical-align: bottom;
}
table td {
background-color: transparent;
}
.table-odd td {
background-color: #f2f2f2;
}
.table-bordered td {
border-bottom: 1px solid #cbcbcb;
}
.table-bordered tbody>tr:last-child>td {
border-bottom-width: 0;
}
</style>
</head>
<body>
<table class="table-bordered table-odd">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Size</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{{ range $idx, $file := .Files }}
<tr>
<td>{{ $idx }}</td>
<td><a href="{{ $file.Path }}" title="{{ $file.ModTime }}">{{ $file.Name }}</a></td>
{{ if $file.Info.IsDir }}
<td>Dir</td>
{{ else }}
<td>{{ formatBytes $file.Info.Size }}</td>
{{ end }}
<td><input type="button" style="background-color:transparent;border:0px;cursor:pointer;" value="❌"
onclick="deleteFile({{ $file.RelPath }})" /></td>
</tr>
{{ end }}
</tbody>
</table>
<script type="text/javascript">
function deleteFile(filename) {
if (!confirm("Are you sure you want to delete " + filename + " ?")) {
return;
}
fetch('/files/' + filename,
{
method: "DELETE",
// If you don't want server to prompt for username/password:
// credentials:"include",
headers: {
// "Authorization": "Basic " + btoa("myusername:mypassword")
"X-Requested-With": "XMLHttpRequest",
},
}).
then(data => location.reload()).
catch(e => alert(e));
}
</script>
</body>
</html>