191 lines
5.2 KiB
HTML
191 lines
5.2 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">
|
|
<link href="/css/nav.css" rel="stylesheet">
|
|
<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: calc(100vh - 120px); /* Adjust for navbar and margins */
|
|
margin: auto; /* Center horizontally */
|
|
margin-bottom: 20px;
|
|
}
|
|
.center-text {
|
|
text-align: center;
|
|
font-size: larger;
|
|
font-weight: bold;
|
|
margin-bottom: 10;
|
|
}
|
|
input[type="text"] {
|
|
width: 100%;
|
|
box-sizing: border-box;
|
|
}
|
|
.row {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
flex-wrap: nowrap;
|
|
min-width: 400px;
|
|
}
|
|
.row > * {
|
|
margin-bottom: 8px;
|
|
}
|
|
.row label {
|
|
flex: 0 0 auto;
|
|
white-space: nowrap;
|
|
}
|
|
.row div {
|
|
display: flex;
|
|
flex: 1;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
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 10px;
|
|
}
|
|
textarea {
|
|
width: 100%; /* Use full width */
|
|
height: calc(100vh - 200px); /* Use vh unit for height */
|
|
box-sizing: border-box;
|
|
border: 1.5px solid gray;
|
|
resize: vertical; /* Allow vertical resizing */
|
|
word-wrap: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="navbar"></div>
|
|
<h1>Edit file</h2>
|
|
<div class="outer-container">
|
|
<div class="container">
|
|
<form name="edit-file" action="/files/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>
|
|
<div class="row">
|
|
<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>
|
|
// Load navbar
|
|
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;
|
|
document.getElementById('save-path').disabled = true;
|
|
})
|
|
.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> |