mirror of
https://github.com/24eme/signaturepdf.git
synced 2023-08-25 09:33:08 +02:00
organization: The first upload field allows you to choose several files
This commit is contained in:
parent
fee27a0311
commit
357bffc55f
@ -556,6 +556,24 @@ var degreesToOrientation = function(degrees) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var uploadAndLoadPDF = async function(input_upload) {
|
||||||
|
const cache = await caches.open('pdf');
|
||||||
|
for (let i = 0; i < input_upload.files.length; i++) {
|
||||||
|
if(input_upload.files[i].size > maxSize) {
|
||||||
|
|
||||||
|
alert("Le PDF ne doit pas dépasser " + Math.round(maxSize/1024/1024) + " Mo");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let filename = input_upload.files[i].name;
|
||||||
|
let response = new Response(input_upload.files[i], { "status" : 200, "statusText" : "OK" });
|
||||||
|
let urlPdf = '/pdf/'+filename;
|
||||||
|
await cache.put(urlPdf, response);
|
||||||
|
let pdfBlob = await getPDFBlobFromCache(urlPdf);
|
||||||
|
nbPDF++;
|
||||||
|
await loadPDF(pdfBlob, filename, nbPDF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var createEventsListener = function() {
|
var createEventsListener = function() {
|
||||||
document.getElementById('save-select_mobile').addEventListener('click', function(event) {
|
document.getElementById('save-select_mobile').addEventListener('click', function(event) {
|
||||||
document.getElementById('save').click();
|
document.getElementById('save').click();
|
||||||
@ -592,21 +610,7 @@ var createEventsListener = function() {
|
|||||||
document.getElementById('save').click();
|
document.getElementById('save').click();
|
||||||
});
|
});
|
||||||
document.getElementById('input_pdf_upload_2').addEventListener('change', async function(event) {
|
document.getElementById('input_pdf_upload_2').addEventListener('change', async function(event) {
|
||||||
for (let i = 0; i < this.files.length; i++) {
|
await uploadAndLoadPDF(this);
|
||||||
if(this.files[i].size > maxSize) {
|
|
||||||
|
|
||||||
alert("Le PDF ne doit pas dépasser " + Math.round(maxSize/1024/1024) + " Mo");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const cache = await caches.open('pdf');
|
|
||||||
let filename = this.files[i].name;
|
|
||||||
let response = new Response(this.files[i], { "status" : 200, "statusText" : "OK" });
|
|
||||||
let urlPdf = '/pdf/'+filename;
|
|
||||||
await cache.put(urlPdf, response);
|
|
||||||
let pdfBlob = await getPDFBlobFromCache(urlPdf);
|
|
||||||
nbPDF++;
|
|
||||||
await loadPDF(pdfBlob, filename, nbPDF);
|
|
||||||
}
|
|
||||||
this.value = '';
|
this.value = '';
|
||||||
});
|
});
|
||||||
document.getElementById('btn-zoom-decrease').addEventListener('click', function(event) {
|
document.getElementById('btn-zoom-decrease').addEventListener('click', function(event) {
|
||||||
@ -749,39 +753,19 @@ var pageUpload = async function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document.getElementById('input_pdf_upload').addEventListener('change', async function(event) {
|
document.getElementById('input_pdf_upload').addEventListener('change', async function(event) {
|
||||||
if(document.getElementById('input_pdf_upload').files[0].size > maxSize) {
|
uploadAndLoadPDF(this);
|
||||||
|
pageOrganization(null);
|
||||||
alert("Le PDF ne doit pas dépasser " + Math.round(maxSize/1024/1024) + " Mo");
|
|
||||||
document.getElementById('input_pdf_upload').value = "";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let filename = document.getElementById('input_pdf_upload').files[0].name;
|
|
||||||
let response = new Response(document.getElementById('input_pdf_upload').files[0], { "status" : 200, "statusText" : "OK" });
|
|
||||||
let urlPdf = '/pdf/'+filename;
|
|
||||||
await cache.put(urlPdf, response);
|
|
||||||
history.pushState({}, '', '/organization#'+filename);
|
|
||||||
pageOrganization(urlPdf)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var pageOrganization = async function(url) {
|
var pageOrganization = async function() {
|
||||||
let filename = url.replace('/pdf/', '');
|
|
||||||
document.title = filename + ' - ' + document.title;
|
|
||||||
document.querySelector('body').classList.add('bg-light');
|
document.querySelector('body').classList.add('bg-light');
|
||||||
document.getElementById('page-upload').classList.add('d-none');
|
document.getElementById('page-upload').classList.add('d-none');
|
||||||
document.getElementById('page-organization').classList.remove('d-none');
|
document.getElementById('page-organization').classList.remove('d-none');
|
||||||
menu = document.getElementById('sidebarTools');
|
menu = document.getElementById('sidebarTools');
|
||||||
menuOffcanvas = new bootstrap.Offcanvas(menu);
|
menuOffcanvas = new bootstrap.Offcanvas(menu);
|
||||||
responsiveDisplay();
|
responsiveDisplay();
|
||||||
|
|
||||||
let pdfBlob = await getPDFBlobFromCache(url);
|
|
||||||
if(!pdfBlob) {
|
|
||||||
document.location = '/organization';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
createEventsListener();
|
createEventsListener();
|
||||||
loadPDF(pdfBlob, filename, nbPDF);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
@ -789,8 +773,6 @@ var pageOrganization = async function(url) {
|
|||||||
let hashUrl = window.location.hash.replace(/^\#/, '');
|
let hashUrl = window.location.hash.replace(/^\#/, '');
|
||||||
pageUpload();
|
pageUpload();
|
||||||
uploadFromUrl(hashUrl);
|
uploadFromUrl(hashUrl);
|
||||||
} else if(window.location.hash) {
|
|
||||||
pageOrganization('/pdf/'+window.location.hash.replace(/^\#/, ''));
|
|
||||||
} else {
|
} else {
|
||||||
pageUpload();
|
pageUpload();
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
<div class="col-md-6 col-lg-5 col-xl-4 col-xxl-3 mx-auto">
|
<div class="col-md-6 col-lg-5 col-xl-4 col-xxl-3 mx-auto">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<label class="form-label mt-3" for="input_pdf_upload">Choisir un PDF <small class="opacity-75" style="cursor: help" title="Le PDF ne doit pas dépasser <?php echo round($maxSize / 1024 / 1024) ?> Mo"><i class="bi bi-info-circle"></i></small></label>
|
<label class="form-label mt-3" for="input_pdf_upload">Choisir un PDF <small class="opacity-75" style="cursor: help" title="Le PDF ne doit pas dépasser <?php echo round($maxSize / 1024 / 1024) ?> Mo"><i class="bi bi-info-circle"></i></small></label>
|
||||||
<input id="input_pdf_upload" placeholder="Choisir un PDF" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf" />
|
<input id="input_pdf_upload" placeholder="Choisir un PDF" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf" multiple="true" />
|
||||||
<p class="mt-2 small fw-light text-dark">Le PDF sera traité par le serveur sans être conservé ni stocké</p>
|
<p class="mt-2 small fw-light text-dark">Le PDF sera traité par le serveur sans être conservé ni stocké</p>
|
||||||
<?php if($PDF_DEMO_LINK): ?>
|
<?php if($PDF_DEMO_LINK): ?>
|
||||||
<a class="btn btn-sm btn-link opacity-75" href="#<?php echo $PDF_DEMO_LINK ?>">Tester avec un PDF de démo</a>
|
<a class="btn btn-sm btn-link opacity-75" href="#<?php echo $PDF_DEMO_LINK ?>">Tester avec un PDF de démo</a>
|
||||||
@ -157,6 +157,6 @@
|
|||||||
<script>
|
<script>
|
||||||
var maxSize = <?php echo $maxSize ?>;
|
var maxSize = <?php echo $maxSize ?>;
|
||||||
</script>
|
</script>
|
||||||
<script src="/js/organization.js?202304030148"></script>
|
<script src="/js/organization.js?202304040034"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user