mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 01:58:23 +02:00
Remove jquery dependency code (keep it for bootstrap-select)
This commit is contained in:
@ -20,14 +20,15 @@
|
||||
<link rel="stylesheet" href="{% static 'fontawasome/css/all.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'fontawasome/css/v4-shims.css' %}">
|
||||
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.14.0-beta3/css/bootstrap-select.min.css">
|
||||
<link rel="stylesheet" href="{% static 'bootstrap-select/css/bootstrap-select.min.css' %}">
|
||||
|
||||
{# JQuery and Bootstrap JavaScript #}
|
||||
<script src="{% static 'jquery/jquery.min.js' %}"></script>
|
||||
{# Bootstrap JavaScript #}
|
||||
<script src="{% static 'bootstrap/js/bootstrap.bundle.min.js' %}"></script>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.14.0-beta3/js/bootstrap-select.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.14.0-beta3/js/i18n/defaults-fr_FR.min.js"></script>
|
||||
{# bootstrap-select for beautyful selects and JQuery dependency #}
|
||||
<script src="{% static 'jquery/jquery.min.js' %}"></script>
|
||||
<script src="{% static 'bootstrap-select/js/bootstrap-select.min.js' %}"></script>
|
||||
<script src="{% static 'bootstrap-select/js/defaults-fr_FR.min.js' %}"></script>
|
||||
|
||||
{# Si un formulaire requiert des données supplémentaires (notamment JS), les données sont chargées #}
|
||||
{% if form.media %}
|
||||
@ -249,49 +250,42 @@
|
||||
|
||||
<script>
|
||||
CSRF_TOKEN = "{{ csrf_token }}";
|
||||
$(".invalid-feedback").addClass("d-block");
|
||||
document.querySelectorAll(".invalid-feedback").forEach(elem => elem.classList.add('d-block'))
|
||||
|
||||
$(document).ready(function () {
|
||||
$('a[data-bs-target="#tournamentListModal"]').click(function() {
|
||||
let modalBody = $("#tournamentListModal div.modal-body");
|
||||
if (!modalBody.html().trim())
|
||||
modalBody.load("{% url "participation:tournament_list" %} #form-content")
|
||||
});
|
||||
function initModal(target, url, content_id = 'form-content') {
|
||||
document.querySelector('[data-bs-target="#' + target + 'Modal"]').addEventListener('click', () => {
|
||||
let modalBody = document.querySelector("#" + target + "Modal div.modal-body")
|
||||
|
||||
if (!modalBody.innerHTML.trim()) {
|
||||
if (url instanceof Function) url = url()
|
||||
|
||||
fetch(url)
|
||||
.then(resp => resp.text())
|
||||
.then(resp => new DOMParser().parseFromString(resp, 'text/html'))
|
||||
.then(res => modalBody.innerHTML = res.getElementById(content_id).outerHTML)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initModal("tournamentList", "{% url "participation:tournament_list" %}")
|
||||
|
||||
{% if user.is_authenticated and user.registration.is_admin %}
|
||||
$('a[data-bs-target="#teamsModal"]').click(function() {
|
||||
let modalBody = $("#teamsModal div.modal-body");
|
||||
if (!modalBody.html().trim())
|
||||
modalBody.load("{% url "participation:team_list" %} #form-content")
|
||||
});
|
||||
$('button[data-bs-target="#searchModal"]').click(function() {
|
||||
let modalBody = $("#searchModal div.modal-body");
|
||||
let q = encodeURI($("#search-term").val());
|
||||
modalBody.load("{% url "haystack_search" %}?q=" + q + " #search-results");
|
||||
});
|
||||
initModal("teams", "{% url "participation:team_list" %}")
|
||||
initModal("search",
|
||||
() => "{% url "haystack_search" %}?q=" + encodeURI(document.getElementById("search-term").value),
|
||||
"search-results")
|
||||
{% endif %}
|
||||
|
||||
{% if not user.is_authenticated %}
|
||||
$('a[data-bs-target="#loginModal"]').click(function() {
|
||||
let modalBody = $("#loginModal div.modal-body");
|
||||
if (!modalBody.html().trim())
|
||||
modalBody.load("{% url "login" %} #form-content")
|
||||
});
|
||||
initModal("login", "{% url 'login' %}")
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_authenticated and user.registration.participates and not user.registration.team %}
|
||||
$('a[data-bs-target="#createTeamModal"]').click(function() {
|
||||
let modalBody = $("#createTeamModal div.modal-body");
|
||||
if (!modalBody.html().trim())
|
||||
modalBody.load("{% url "participation:create_team" %} #form-content");
|
||||
});
|
||||
$('a[data-bs-target="#joinTeamModal"]').click(function() {
|
||||
let modalBody = $("#joinTeamModal div.modal-body");
|
||||
if (!modalBody.html().trim())
|
||||
modalBody.load("{% url "participation:join_team" %} #form-content");
|
||||
});
|
||||
initModal("createTeam", "{% url 'participation:create_team' %}")
|
||||
initModal("joinTeam", "{% url 'participation:join_team' %}")
|
||||
{% endif %}
|
||||
});
|
||||
})
|
||||
</script>
|
||||
|
||||
{% block extrajavascript %}{% endblock %}
|
||||
|
Reference in New Issue
Block a user