mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-07-22 08:53:28 +02:00
Rank calculation optimized
This commit is contained in:
@ -113,33 +113,47 @@ function reset () {
|
||||
* Apply all transactions: all notes in `notes` buy each item in `buttons`
|
||||
*/
|
||||
function consumeAll () {
|
||||
console.log("consumeAll lancée")
|
||||
if (LOCK) { return }
|
||||
|
||||
LOCK = true
|
||||
|
||||
let error = false
|
||||
|
||||
if (notes_display.length === 0) {
|
||||
document.getElementById('note').classList.add('is-invalid')
|
||||
$('#note_list').html(li('', '<strong>Ajoutez des familles.</strong>', 'text-danger'))
|
||||
// ... gestion erreur ...
|
||||
error = true
|
||||
}
|
||||
|
||||
if (buttons.length === 0) {
|
||||
$('#consos_list').html(li('', '<strong>Ajoutez des défis.</strong>', 'text-danger'))
|
||||
// ... gestion erreur ...
|
||||
error = true
|
||||
}
|
||||
|
||||
if (error) {
|
||||
LOCK = false
|
||||
return
|
||||
}
|
||||
|
||||
notes_display.forEach(function (family) {
|
||||
buttons.forEach(function (challenge) {
|
||||
grantAchievement(family, challenge)
|
||||
})
|
||||
// Récupérer les IDs des familles et des challenges
|
||||
const family_ids = notes_display.map(fam => fam.id)
|
||||
const challenge_ids = buttons.map(chal => chal.id)
|
||||
|
||||
$.ajax({
|
||||
url: '/family/api/family/achievements/batch/',
|
||||
type: 'POST',
|
||||
data: JSON.stringify({
|
||||
families: family_ids,
|
||||
challenges: challenge_ids
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
headers: {
|
||||
'X-CSRFToken': CSRF_TOKEN
|
||||
},
|
||||
success: function () {
|
||||
reset()
|
||||
addMsg("Défis validés pour les familles !", 'success', 5000)
|
||||
},
|
||||
error: function (e) {
|
||||
reset()
|
||||
addMsg("Erreur lors de la création des achievements.",'danger',5000)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user