Table recap: efface données client cachées si erreur.

This commit is contained in:
Emmanuel Viennet 2023-01-30 18:38:34 -03:00
parent cb21043f31
commit a42a3708fb

View File

@ -14,6 +14,8 @@ $(function () {
const url = new URL(document.URL); const url = new URL(document.URL);
const formsemestre_id = url.searchParams.get("formsemestre_id"); const formsemestre_id = url.searchParams.get("formsemestre_id");
const order_info_key = JSON.stringify([url.pathname, formsemestre_id]); const order_info_key = JSON.stringify([url.pathname, formsemestre_id]);
const etudids_key = JSON.stringify(["etudids", url.origin, formsemestre_id]);
const noms_key = JSON.stringify(["noms", url.origin, formsemestre_id]);
let order_info; let order_info;
if (formsemestre_id) { if (formsemestre_id) {
const x = localStorage.getItem(order_info_key); const x = localStorage.getItem(order_info_key);
@ -157,6 +159,7 @@ $(function () {
} }
}); });
} }
try {
let table = $('table.table_recap').DataTable( let table = $('table.table_recap').DataTable(
{ {
paging: false, paging: false,
@ -226,14 +229,19 @@ $(function () {
document.querySelectorAll("td.identite_court").forEach(e => { document.querySelectorAll("td.identite_court").forEach(e => {
noms.push(e.dataset.nomprenom); noms.push(e.dataset.nomprenom);
}); });
const etudids_key = JSON.stringify(["etudids", url.origin, formsemestre_id]);
localStorage.setItem(etudids_key, JSON.stringify(etudids)); localStorage.setItem(etudids_key, JSON.stringify(etudids));
const noms_key = JSON.stringify(["noms", url.origin, formsemestre_id]);
localStorage.setItem(noms_key, JSON.stringify(noms)); localStorage.setItem(noms_key, JSON.stringify(noms));
}, },
"order": order_info, "order": order_info,
} }
); );
} catch (error) {
// l'erreur peut etre causee par un ancien storage:
localStorage.removeItem(etudids_key);
localStorage.removeItem(noms_key);
localStorage.removeItem(order_info_key);
location.reload();
}
update_buttons_labels(table); update_buttons_labels(table);
}); });
$('table.table_recap tbody').on('click', 'tr', function () { $('table.table_recap tbody').on('click', 'tr', function () {