MonScoDocEssai/app/templates/assiduites/widgets/alert.j2
2023-06-30 14:38:56 +02:00

160 lines
4.0 KiB
Django/Jinja

{% block alertmodal %}
<div id="alertModal" class="alertmodal">
<!-- alertModal content -->
<div class="alertmodal-content">
<div class="alertmodal-header">
<span class="alertmodal-close">&times;</span>
<h2 class="alertmodal-title">alertModal Header</h2>
</div>
<div class="alertmodal-body">
<p>Some text in the alertModal Body</p>
<p>Some other text...</p>
</div>
<div class="alertmodal-footer">
<h3>alertModal Footer</h3>
</div>
</div>
</div>
<style>
/* The alertModal (background) */
.alertmodal {
display: none;
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 850;
/* Sit on top */
padding-top: 100px;
/* Location of the box */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.4);
/* Black w/ opacity */
}
/* alertModal Content */
.alertmodal-content {
border-radius: 8px;
overflow: hidden;
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 45%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}
/* Add Animation */
@-webkit-keyframes animatetop {
from {
top: -300px;
opacity: 0
}
to {
top: 0;
opacity: 1
}
}
@keyframes animatetop {
from {
top: -300px;
opacity: 0
}
to {
top: 0;
opacity: 1
}
}
/* The Close Button */
.alertmodal-close {
color: white;
position: absolute;
right: 10px;
font-size: 28px;
font-weight: bold;
}
.alertmodal-close:hover,
.alertmodal-close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.alertmodal-header {
padding: 2px 16px;
color: white;
display: flex;
justify-content: center;
align-items: center;
}
.alertmodal-body {
padding: 2px 16px;
}
.alertmodal-footer {
padding: 2px 16px;
color: white;
display: flex;
justify-content: center;
align-items: center;
}
.alertmodal.is-active {
display: block;
}
</style>
<script>
const alertmodal = document.getElementById("alertModal");
function openAlertModal(titre, contenu, footer, color = "crimson") {
alertmodal.classList.add('is-active');
alertmodal.querySelector('.alertmodal-title').textContent = titre;
alertmodal.querySelector('.alertmodal-body').innerHTML = ""
alertmodal.querySelector('.alertmodal-body').appendChild(contenu);
alertmodal.querySelector('.alertmodal-footer').textContent = footer;
const banners = Array.from(alertmodal.querySelectorAll('.alertmodal-footer,.alertmodal-header'))
banners.forEach((ban) => {
ban.style.backgroundColor = color;
})
alertmodal.addEventListener('click', (e) => {
if (e.target.id == alertmodal.id) {
alertmodal.classList.remove('is-active');
alertmodal.removeEventListener('click', this)
}
})
}
function closeAlertModal() {
alertmodal.classList.remove("is-active")
}
const alertClose = document.querySelector(".alertmodal-close");
alertClose.onclick = function () {
closeAlertModal()
}
</script>
{% endblock alertmodal %}