diff --git a/static/builder.js b/static/builder.js index 5d392b6..908c4b9 100644 --- a/static/builder.js +++ b/static/builder.js @@ -290,30 +290,52 @@ document - const response = - await fetch( - "/edt.pdf", - { + const submitButton = document.getElementById("submit-button"); + + const loader = + document.querySelector(".loader"); + + const iframe = + document.getElementById("pdf_iframe"); + + + submitButton.disabled = true; + loader.style.display = "block"; + + try { + + const response = + await fetch("/edt.pdf", { method: "POST", headers: { - "Content-Type": - "application/json" + "Content-Type": "application/json" }, - body: - JSON.stringify({ - cours - }) - } - ); + body: JSON.stringify({ cours }) + }); + if (!response.ok) + throw new Error("Erreur lors de la génération du PDF."); - const blob = - await response.blob(); + const blob = + await response.blob(); + const url = + URL.createObjectURL(blob); - window.open( - URL.createObjectURL(blob) - ); + iframe.src = url; + iframe.style.display = "block"; + + } catch (err) { + + console.error(err); + alert(err.message); + + } finally { + + loader.style.display = "none"; + submitButton.disabled = false; + + } } ); diff --git a/static/style.css b/static/style.css index 61d03e1..d464e98 100644 --- a/static/style.css +++ b/static/style.css @@ -105,6 +105,14 @@ color: #111; } + button:disabled { + background: #bdbdbd; + border-color: #bdbdbd; + color: #666; + cursor: not-allowed; + opacity: 1; + } + .remove { background: #333 !important; @@ -136,4 +144,35 @@ overflow-x: auto; white-space: nowrap; } - } \ No newline at end of file + } + + +.loader { + border: 16px solid #f3f3f3; + border-radius: 50%; + border-top: 16px solid #3498db; + width: 120px; + height: 120px; + -webkit-animation: spin 2s linear infinite; /* Safari */ + animation: spin 2s linear infinite; +} + +/* Safari */ +@-webkit-keyframes spin { + 0% { -webkit-transform: rotate(0deg); } + 100% { -webkit-transform: rotate(360deg); } +} + +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} + + +#pdf_iframe { + width: 100%; + height: calc(100vh - 220px); + min-height: 500px; + border: 1px solid #ccc; + margin-top: 1rem; +} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index db26745..34510ba 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,6 +4,7 @@