forked from ScoDoc/ScoDoc
Assiduité : annulation / suppression fichier justif
This commit is contained in:
parent
1b037d6c7c
commit
71f90f5261
@ -154,50 +154,25 @@ div.submit > input {
|
|||||||
{% include "sco_timepicker.j2" %}
|
{% include "sco_timepicker.j2" %}
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
// Suppression d'un fichier justificatif
|
|
||||||
function delete_file(justif_id, fileName, liElement) {
|
|
||||||
// Construct the URL
|
|
||||||
var url = "{{url_for('apiweb.justif_remove', justif_id=-1, scodoc_dept=g.scodoc_dept)}}".replace('-1', justif_id);
|
|
||||||
|
|
||||||
payload = {
|
|
||||||
"remove": "list",
|
|
||||||
"filenames" : [ fileName ],
|
|
||||||
}
|
|
||||||
// Send API request
|
|
||||||
fetch(url, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(payload)
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.ok) {
|
|
||||||
// Hide the <li> element on successful deletion
|
|
||||||
liElement.style.display = 'none';
|
|
||||||
sco_message("fichier supprimé");
|
|
||||||
} else {
|
|
||||||
// Handle non-successful responses here
|
|
||||||
console.error('Deletion failed:', response.statusText);
|
|
||||||
sco_error_message("erreur lors de la suppression du fichier");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
sco_error_message("erreur lors de la suppression du fichier (2)");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add event listeners to all elements with class 'suppr_fichier_just'
|
// Add event listeners to all elements with class 'suppr_fichier_just'
|
||||||
var deleteButtons = document.querySelectorAll('.suppr_fichier_just');
|
var deleteButtons = document.querySelectorAll('.suppr_fichier_just');
|
||||||
|
const form = document.getElementById('ajout-justificatif-etud');
|
||||||
deleteButtons.forEach(function(button) {
|
deleteButtons.forEach(function(button) {
|
||||||
button.addEventListener('click', function() {
|
button.addEventListener('click', function() {
|
||||||
// Get the text content of the next sibling node
|
// Get the text content of the next sibling node
|
||||||
var justif_id = this.dataset.justif_id;
|
var justif_id = this.dataset.justif_id;
|
||||||
var fileName = this.nextSibling.nodeValue.trim();
|
var fileName = this.nextSibling.nodeValue.trim();
|
||||||
var liElement = this.parentNode; // Get the parent <li> element
|
var liElement = this.parentNode; // Get the parent <li> element
|
||||||
delete_file(justif_id, fileName, liElement);
|
|
||||||
|
// Create a hidden input element to store the file name
|
||||||
|
var input = document.createElement('input');
|
||||||
|
input.type = 'hidden';
|
||||||
|
input.name = 'suppr_fichier_just';
|
||||||
|
input.value = fileName;
|
||||||
|
form.appendChild(input);
|
||||||
|
|
||||||
|
liElement.remove();
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -658,6 +658,8 @@ def edit_justificatif_etud(justif_id: int):
|
|||||||
etudid=justif.etudiant.id,
|
etudid=justif.etudiant.id,
|
||||||
)
|
)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
|
if form.cancel.data: # cancel button
|
||||||
|
return redirect(redirect_url)
|
||||||
if _record_justificatif_etud(justif.etudiant, form, justif):
|
if _record_justificatif_etud(justif.etudiant, form, justif):
|
||||||
return redirect(redirect_url)
|
return redirect(redirect_url)
|
||||||
|
|
||||||
@ -757,7 +759,6 @@ def _record_justificatif_etud(
|
|||||||
dt_fin_tz_server,
|
dt_fin_tz_server,
|
||||||
dt_entry_date_tz_server,
|
dt_entry_date_tz_server,
|
||||||
) = _get_dates_from_assi_form(form, all_day=True)
|
) = _get_dates_from_assi_form(form, all_day=True)
|
||||||
|
|
||||||
if not ok:
|
if not ok:
|
||||||
log("_record_justificatif_etud: dates invalides")
|
log("_record_justificatif_etud: dates invalides")
|
||||||
form.set_error("Erreur: dates invalides")
|
form.set_error("Erreur: dates invalides")
|
||||||
@ -793,6 +794,14 @@ def _record_justificatif_etud(
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
message = "Pas de modification"
|
message = "Pas de modification"
|
||||||
|
fichier_suppr: list[str] = request.form.getlist("suppr_fichier_just")
|
||||||
|
|
||||||
|
if len(fichier_suppr) > 0 and justif.fichier is not None:
|
||||||
|
archiver: JustificatifArchiver = JustificatifArchiver()
|
||||||
|
for fichier in fichier_suppr:
|
||||||
|
archiver.delete_justificatif(etud, justif.fichier, fichier)
|
||||||
|
flash(f"Fichier {fichier} supprimé")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
justif = Justificatif.create_justificatif(
|
justif = Justificatif.create_justificatif(
|
||||||
etud,
|
etud,
|
||||||
|
Loading…
Reference in New Issue
Block a user