151 lines
4.0 KiB
HTML
151 lines
4.0 KiB
HTML
<!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>
|
|
body {
|
|
font-family: Tahoma, Arial, sans-serif;
|
|
font-size: small;
|
|
margin: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: flex-start;
|
|
}
|
|
h1 {
|
|
margin-top: 0;
|
|
}
|
|
#submit {
|
|
width:100px;
|
|
}
|
|
button{
|
|
width: 100px;
|
|
}
|
|
#spacer-50 {
|
|
height: 20px;
|
|
}
|
|
#spacer-20 {
|
|
height: 10px;
|
|
}
|
|
fieldset {
|
|
width:700px;
|
|
border-radius: 10px;
|
|
background-color: lightgray;
|
|
}
|
|
td, th {
|
|
text-align: center;
|
|
padding: 1px;
|
|
}
|
|
legend{
|
|
background-color:white;
|
|
background-blend-mode: darken;
|
|
border-radius: 5px;
|
|
padding: 1px 6px 2px 6px;
|
|
border-style:solid;
|
|
border-width: 1.0;
|
|
}
|
|
textarea {
|
|
width: 700px;
|
|
height: 500px;
|
|
box-sizing: border-box;
|
|
border: 1.5px solid #000000;
|
|
border-radius: 8px;
|
|
resize: none;
|
|
word-wrap: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="navbar"></div>
|
|
<h2>Edit file</h2>
|
|
<fieldset>
|
|
<legend>Editing file: {{SAVE_PATH_INPUT}}</legend>
|
|
<div id="spacer-20"></div>
|
|
<table><tr><td colspan="2">
|
|
<form name="edit-file" action="/save" onsubmit="return validateForm()">
|
|
<textarea name="edit-textarea" id="edit-textarea" wrap="off" ></textarea>
|
|
<div id="spacer-20"></div>
|
|
</td></tr><tr><td>
|
|
{{SAVE_PATH_INPUT}}
|
|
<button type="submit" id="submit-edit" >Save</button>
|
|
</form>
|
|
</td><td>
|
|
<button id="submit" onclick="window.location.href='/files';">Cancel</button>
|
|
</td></tr></table>
|
|
<div id="spacer-50"></div>
|
|
</fieldset>
|
|
|
|
<iframe style="display:none" name="self-page"></iframe>
|
|
|
|
<script>
|
|
|
|
fetch('/www/navbar.html')
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
document.getElementById('navbar').innerHTML = data;
|
|
});
|
|
|
|
|
|
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> |