forked from ScoDoc/ScoDoc
Update opolka/ScoDoc from ScoDoc/ScoDoc #2
@ -185,7 +185,7 @@ def sidebar(etudid: int = None):
|
||||
formsemestre.date_fin.strftime("%d/%m/%Y")
|
||||
}">({
|
||||
sco_preferences.get_preference("assi_metrique", None)})
|
||||
<br>{nbabsjust:1.0f} J., {nbabsnj:1.0f} N.J.</span>"""
|
||||
<br>{nbabsjust:1g} J., {nbabsnj:1g} N.J.</span>"""
|
||||
)
|
||||
H.append("<ul>")
|
||||
if current_user.has_permission(Permission.AbsChange):
|
||||
|
@ -154,50 +154,25 @@ div.submit > input {
|
||||
{% include "sco_timepicker.j2" %}
|
||||
<script>
|
||||
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'
|
||||
var deleteButtons = document.querySelectorAll('.suppr_fichier_just');
|
||||
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
|
||||
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();
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -58,7 +58,7 @@
|
||||
{% if sco.etud_cur_sem %}
|
||||
<span title="absences du {{ sco.etud_cur_sem['date_debut'].strftime('%d/%m/%Y') }}
|
||||
au {{ sco.etud_cur_sem['date_fin'].strftime('%d/%m/%Y') }}">({{sco.prefs["assi_metrique"]}})
|
||||
<br />{{'%1.0f'|format(sco.nbabsjust)}} J., {{'%1.0f'|format(sco.nbabsnj)}} N.J.</span>
|
||||
<br />{{'%1g'|format(sco.nbabsjust)}} J., {{'%1g'|format(sco.nbabsnj)}} N.J.</span>
|
||||
{% endif %}
|
||||
<ul>
|
||||
{% if current_user.has_permission(sco.Permission.AbsChange) %}
|
||||
@ -94,4 +94,4 @@
|
||||
{{ scu.icontag("scologo_img", no_size=True) | safe}}</a>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end of sidebar -->
|
||||
<!-- end of sidebar -->
|
@ -658,6 +658,8 @@ def edit_justificatif_etud(justif_id: int):
|
||||
etudid=justif.etudiant.id,
|
||||
)
|
||||
if form.validate_on_submit():
|
||||
if form.cancel.data: # cancel button
|
||||
return redirect(redirect_url)
|
||||
if _record_justificatif_etud(justif.etudiant, form, justif):
|
||||
return redirect(redirect_url)
|
||||
|
||||
@ -757,7 +759,6 @@ def _record_justificatif_etud(
|
||||
dt_fin_tz_server,
|
||||
dt_entry_date_tz_server,
|
||||
) = _get_dates_from_assi_form(form, all_day=True)
|
||||
|
||||
if not ok:
|
||||
log("_record_justificatif_etud: dates invalides")
|
||||
form.set_error("Erreur: dates invalides")
|
||||
@ -793,6 +794,14 @@ def _record_justificatif_etud(
|
||||
)
|
||||
else:
|
||||
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:
|
||||
justif = Justificatif.create_justificatif(
|
||||
etud,
|
||||
|
Loading…
Reference in New Issue
Block a user