]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6184 @0:5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Jul 2023 16:54:35 +0000 (18:54 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Jul 2023 16:54:35 +0000 (18:54 +0200)
resources/quizv2/js/quiz.animations.js
resources/quizv2/js/quiz.score.js

index 59fa52232f5696357cc1bfd714685298264dbfd2..28ab9c2e94099b24c99d7105a7823b06748d1007 100644 (file)
@@ -9,11 +9,10 @@ QuizAnimations.prototype = {
     // Load the animation "name" in container
     load: function (name, container, replace) {
         let json = this.quiz.data.animations[name];
-        if(json) {
-            $.each(replace, function (k, v) {
-                json = json.replace(new RegExp(k, 'g'), v);
-        });
-
+        if (json) {
+            for (const k in replace) {
+                json = json.replace(new RegExp(k, 'g'), replace[k]);
+            }
             lottie.loadAnimation({
                 container: $(container).get(0),
                 renderer: 'svg',
index 2120abe9596440d94258252e571f599e5a883874..b6ca34d93fcbc7c11ee590ab2a2fb8d9b81c9a72 100644 (file)
@@ -20,6 +20,7 @@ QuizScore.prototype = {
         this.lastAnsweredQuestion = questionIndex;
         this.answers[questionIndex] = answers;
         this.updateScore();
+        return {ok: this.questionStatus[questionIndex].ok, status: this.questionStatus};
     },
 
     checkQuestion: function (questionIndex) {
@@ -34,44 +35,49 @@ QuizScore.prototype = {
 
         let answersStatus = [];
         let userAnswers = this.answers[questionIndex];
-
-        let $this = this;
-        if (question.type === 'multiple') {
-            // Le score de la question
-            let min_score = this.getMinScore(question);
-            let this_score = 0;
-            $.each(question.answers, function (answerIndex, answer) {
-                let checkedByUser = userAnswers.indexOf(answerIndex) >= 0;
-                if (answer.correct === 1) {
-                    if (checkedByUser) {
-                        // C'est une bonne réponse et elle a été cochée par l'utilisateur
-                        this_score += answer.score;
-                        answersStatus[answerIndex] = 'ok';
-                    } else {
-                        // C'est une bonne réponse mais elle n'a pas été cochée par l'utilisateur
-                        answersStatus[answerIndex] = 'missed';
-                    }
-                } else {
-                    if (checkedByUser) {
-                        // C'est une mauvaise réponse et elle a été cochée par l'utilisateur
-                        this_score -= answer.score;
-                        answersStatus[answerIndex] = 'nok';
+        if (userAnswers === undefined || userAnswers === null) {
+            ok = null;
+        } else {
+            let $this = this;
+            if (question.type === 'multiple') {
+                // Le score de la question
+                let min_score = this.getMinScore(question);
+                let this_score = 0;
+                for (const answerIndex in question.answers) {
+                    const answer = question.answers[answerIndex];
+                    let checkedByUser = userAnswers.indexOf(answerIndex) >= 0;
+                    if (answer.correct === 1) {
+                        if (checkedByUser) {
+                            // C'est une bonne réponse et elle a été cochée par l'utilisateur
+                            this_score += answer.score;
+                            answersStatus[answerIndex] = 'ok';
+                        } else {
+                            // C'est une bonne réponse mais elle n'a pas été cochée par l'utilisateur
+                            answersStatus[answerIndex] = 'missed';
+                        }
                     } else {
-                        // C'est une bonne réponse et elle n'a pas été cochée par l'utilisateur
-                        answersStatus[answerIndex] = 'neutral';
+                        if (checkedByUser) {
+                            // C'est une mauvaise réponse et elle a été cochée par l'utilisateur
+                            this_score -= answer.score;
+                            answersStatus[answerIndex] = 'nok';
+
+                        } else {
+                            // C'est une bonne réponse et elle n'a pas été cochée par l'utilisateur
+                            answersStatus[answerIndex] = 'neutral';
+                        }
                     }
                 }
-            });
 
-            ok = this_score >= min_score;
+                ok = this_score >= min_score;
 
-            log.answer = a;
-        } else {
-            log.answer = $(this).find('input,textarea,select').val();
-        }
+                log.answer = a;
+            } else {
+                log.answer = $(this).find('input,textarea,select').val();
+            }
 
-        if (!count) {
-            ok = null;
+            if (!count) {
+                ok = null;
+            }
         }
 
         this.questionStatus[questionIndex] = {'status': ok, 'answers': answersStatus};
@@ -90,11 +96,12 @@ QuizScore.prototype = {
         let min_score = parseInt(question.min_score);
         if (min_score === 0) {
             min_score = 0;
-            $.each(question.answers, function (answerIndex, answer) {
+            for (const answerIndex in question.answers) {
+                let answer = question.answers[answerIndex];
                 if (answer.correct) {
                     min_score += answer.score;
                 }
-            });
+            }
         }
         return min_score;
     },
@@ -103,11 +110,9 @@ QuizScore.prototype = {
         this.score = 0;
         this.logQuestions = [];
 
-        let $this = this;
-
-        $.each(this.quiz.questions, function (qn, question) {
-            $this.checkQuestion(qn);
-        });
+        for (const qn in this.quiz.questions) {
+            this.checkQuestion(qn);
+        }
 
         let state = {
             q: this.lastAnsweredQuestion + 1, a: this.answers