forked from ScoDoc/ScoDoc
Merge pull request 'Assiduité : fix bug suppression fichier justif' (#930) from iziram/ScoDoc:hotfix into master
Reviewed-on: ScoDoc/ScoDoc#930
This commit is contained in:
commit
1808e7f5a4
@ -130,7 +130,7 @@ div.submit > input {
|
||||
</div>
|
||||
<ul>
|
||||
{% for filename in filenames %}
|
||||
<li><span data-justif_id="{{justif.id}}" class="suppr_fichier_just"
|
||||
<li><span data-justif_id="{{justif.id}}" data-filename="{{filename}}" class="suppr_fichier_just"
|
||||
>{{scu.icontag("delete_img", alt="supprimer", title="Supprimer")|safe}}</span>
|
||||
<a href="{{url_for('apiweb.justif_export',justif_id=justif.justif_id,
|
||||
filename=filename, scodoc_dept=g.scodoc_dept)}}">{{filename}}</a>
|
||||
@ -194,27 +194,28 @@ div.submit > input {
|
||||
{% include "sco_timepicker.j2" %}
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
// Add event listeners to all elements with class 'suppr_fichier_just'
|
||||
var deleteButtons = document.querySelectorAll('.suppr_fichier_just');
|
||||
// On récupère les boutons de suppression de fichiers
|
||||
const deleteButtons = document.querySelectorAll('.suppr_fichier_just');
|
||||
// On récupère le formulaire
|
||||
const form = document.getElementById('ajout-justificatif-etud');
|
||||
deleteButtons.forEach(function(button) {
|
||||
button.addEventListener('click', function() {
|
||||
// Get the text content of the next sibling node
|
||||
var justif_id = this.dataset.justif_id;
|
||||
var fileName = this.nextSibling.nodeValue.trim();
|
||||
var liElement = this.parentNode; // Get the parent <li> element
|
||||
// Pour chaque bouton, on ajoute une fonction de suppression
|
||||
deleteButtons.forEach((btn)=>{
|
||||
// Quand le bouton est cliqué, on récupère les infos
|
||||
// et on ajoute un input hidden au formulaire
|
||||
// et enfin on supprime l'élement <li> du DOM.
|
||||
btn.addEventListener("click",()=>{
|
||||
const filename = btn.getAttribute('data-filename');
|
||||
const justif_id = btn.getAttribute('data-justif_id');
|
||||
|
||||
// Create a hidden input element to store the file name
|
||||
var input = document.createElement('input');
|
||||
const input = document.createElement('input');
|
||||
input.type = 'hidden';
|
||||
input.name = 'suppr_fichier_just';
|
||||
input.value = fileName;
|
||||
input.value = filename;
|
||||
form.appendChild(input);
|
||||
|
||||
liElement.remove();
|
||||
|
||||
});
|
||||
});
|
||||
btn.parentNode.remove();
|
||||
})
|
||||
})
|
||||
});
|
||||
</script>
|
||||
{% endblock scripts %}
|
||||
|
Loading…
Reference in New Issue
Block a user