Stirling-PDF/src/main/resources/templates/merge-pdfs.html

106 lines
3.3 KiB
HTML
Raw Normal View History

2023-01-27 19:23:40 +01:00
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:insert="~{common :: head}"></th:block>
<title>S-PDF MergePDFs</title>
2023-01-28 11:00:32 +01:00
2023-01-27 19:23:40 +01:00
</head>
<body>
<div th:insert="~{navbar.html :: navbar}"></div>
<br>
<br>
2023-01-28 11:00:32 +01:00
<div class="container" id="dropContainer">
2023-01-27 19:23:40 +01:00
<div class="row justify-content-center">
2023-01-28 11:00:32 +01:00
<div class="col-md-6" >
2023-01-27 19:23:40 +01:00
<h2>Merge multiple PDFs (2+)</h2>
<form action="/merge-pdfs" method="post"
enctype="multipart/form-data">
<div class="form-group">
<label>Select (or drag & drop) all PDFs to merge</label>
<div class="custom-file">
<input type="file" class="custom-file-input" id="fileInput"
name="fileInput" multiple> <label
class="custom-file-label">Choose PDFs</label>
</div>
</div>
2023-01-30 21:50:47 +01:00
<div class="form-group">
<ul id="selectedFiles" class="list-group"></ul>
</div>
2023-01-27 19:23:40 +01:00
<div class="form-group text-center">
<button type="submit" class="btn btn-primary">Merge</button>
</div>
</form>
2023-01-30 21:50:47 +01:00
2023-01-27 19:23:40 +01:00
2023-01-30 21:50:47 +01:00
<script>
document.getElementById("fileInput").addEventListener("change", function() {
var files = this.files;
var list = document.getElementById("selectedFiles");
list.innerHTML = "";
for (var i = 0; i < files.length; i++) {
var item = document.createElement("li");
item.className = "list-group-item d-flex justify-content-between align-items-center";
item.textContent = files[i].name;
item.innerHTML += '<div><button class="btn btn-secondary move-up">Move Up</button> <button class="btn btn-secondary move-down">Move Down</button></div>';
list.appendChild(item);
}
var moveUpButtons = document.querySelectorAll(".move-up");
for (var i = 0; i < moveUpButtons.length; i++) {
moveUpButtons[i].addEventListener("click", function(event) {
event.preventDefault();
var parent = this.parentNode.parentNode;
var grandParent = parent.parentNode;
if (parent.previousElementSibling) {
grandParent.insertBefore(parent, parent.previousElementSibling);
updateFiles();
}
});
}
var moveDownButtons = document.querySelectorAll(".move-down");
for (var i = 0; i < moveDownButtons.length; i++) {
moveDownButtons[i].addEventListener("click", function(event) {
event.preventDefault();
var parent = this.parentNode.parentNode;
var grandParent = parent.parentNode;
if (parent.nextElementSibling) {
grandParent.insertBefore(parent.nextElementSibling, parent);
updateFiles();
}
});
}
2023-01-27 19:23:40 +01:00
2023-01-30 21:50:47 +01:00
function updateFiles() {
var dataTransfer = new DataTransfer();
var liElements = document.querySelectorAll("#selectedFiles li");
for (var i = 0; i < liElements.length; i++) {
var fileNameFromList = liElements[i].innerText.replace("\nMove Up Move Down","");
var fileFromFiles
for (var j = 0; j < files.length; j++) {
var file = files[j];
if(file.name === fileNameFromList){
dataTransfer.items.add(file);
break;
}
}
}
document.getElementById("fileInput").files = dataTransfer.files;
}
});
</script>
2023-01-27 19:23:40 +01:00
</div>
</div>
</div>
<div th:insert="~{footer.html :: footer}"></div>
</body>
</html>