170 lines
4.6 KiB
HTML

{{NAVBAR}}
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Edit file</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
h1{
text-align: center;
margin: 0;
margin-bottom: 10px;
}
body {
font-family: Arial, sans-serif;
padding: 0;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
width: 100%;
max-width: auto;
min-width: 400px;
margin: 0 auto;
}
.outer-container {
justify-content: center;
align-items: center;
padding: 20px;
padding-top: 0;
}
.container {
border: 1px solid #ccc;
padding: 10px; /* Adjust padding */
background-color: #fff;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
width: 90%;
min-width: 400px;
height: 85vh; /* Use vh unit for height */
margin: auto; /* Center horizontally */
margin-bottom: 20px;
}
.center-text {
text-align: center;
font-size: larger;
font-weight: bold;
margin-bottom: 10;
}
.row {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 10px;
align-items: flex-end;
}
.row > * {
flex: 1;
width: calc(50% - 20px);
margin-bottom: 8px;
}
input[type="number"], select {
border: 1px solid #ccc;
border-radius: 4px;
width: 50%;
}
button {
background-color: #007bff;
color: #fff;
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
margin: 20px 5px 0 10px;
}
textarea {
width: 100%; /* Use full width */
height: 80vh; /* Use vh unit for height */
box-sizing: border-box;
border: 1.5px solid #000000;
border-radius: 8px;
resize: vertical; /* Allow vertical resizing */
word-wrap: none;
}
</style>
</head>
<body>
<h1>Edit file</h2>
<div class="outer-container">
<div class="container">
<form name="edit-file" action="/save" onsubmit="return validateForm()">
<div>
<textarea name="edit-textarea" id="edit-textarea" wrap="off" ></textarea>
</div>
<div class="row">
<div>
<label>File Name:</label>
<input type="text" id="save-path" value="{{SAVE_PATH_INPUT}}">
</div>
<div>
<button type="submit" id="submit-edit" >Save</button>
<button id="cancel" onclick="window.location.href='/files';">Cancel</button>
</div>
</div>
</form>
</div>
</div>
<script>
window.onload=loadEditFile();
function loadEditFile(){
var savePath = document.getElementById('save-path').value;
if( savePath != "/new.txt"){ // skip if new.txt
fetch(savePath)
.then(response => {
if (!response.ok) {
throw new Error('Failed to fetch file');
}
return response.text();
})
.then(fileContents => {
// Put the file contents into a textarea element
document.getElementById('edit-textarea').value = fileContents;
})
.catch(error => {
console.error(error);
});
}
}
function validateForm()
{
var allowedExtensions = "{{ALLOWED_EXTENSIONS_EDIT}}";
var inputMessage = document.getElementById('save-path').value;
var dotIndex = inputMessage.lastIndexOf(".")+1;
var inputMessageExtension = inputMessage.substring(dotIndex);
var extIndex = allowedExtensions.indexOf(inputMessageExtension);
var isSlash = inputMessage.substring(0,1);
if(inputMessage == "")
{
alert("Enter the file name! \ne.g.: /new.txt");
return false;
}
if(isSlash != "/")
{
alert("The slash at the beginning of the file is missing!");
return false;
}
if(dotIndex == 0)
{
alert("The extension is missing at the end of the file!");
return false;
}
if(inputMessageExtension == "")
{
alert("The extension is missing at the end of the file!");
return false;
}
if(extIndex == -1)
{
alert("Extension not supported!");
return false;
}
}
</script>
</body>
</html>