]> _ Git - fluidbook-toolbox.git/commitdiff
wip #3924 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 12 Oct 2020 18:51:27 +0000 (20:51 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 12 Oct 2020 18:51:27 +0000 (20:51 +0200)
resources/quiz/js/main.js

index 0444888200f7f674e27bd90ff65ffa970f08d5ec..f2190995003de04d1a7c0485b4ebe310ab650be7 100644 (file)
@@ -15,7 +15,6 @@
 
         $(window).on('resize', resize);
 
-
         function resize() {
             // Window size that reserve enough space for all questions and avoid scroll jumps
             var maxHeight = 0;
@@ -90,6 +89,8 @@
             var rev = $(data).find('review');
             showReview = (rev.length === 0 || rev.text() === '1');
             threshold = 0;
+            instantReview = $(data).find('instantReview').text() === '1';
+            logAttempts = $(data).find('logattempts').text() === '1';
 
             if ($(data).find('threshold').length > 0 && !isNaN(parseFloat($(data).find('threshold').text()))) {
                 threshold = parseFloat($(data).find('threshold').text());
                 var type = $(this).attr('type');
                 var multiple = $(this).attr('multiple') == '1';
                 var multipleclass = multiple ? ' multiple' : '';
-                var question = '<section class="question' + multipleclass + '" data-q="' + qn + ' data-type="' + type + '">';
+                var question = '<section class="question' + multipleclass + '" data-q="' + qn + '" data-type="' + type + '">';
                 question += '<div class="label"><h3>' + sprintf(getTranslation('question'), qn) + '</h3> ' + $(this).find('label').text() + '</div>';
                 question += '<div class="answers">';
                 question += '</div>';
                 if (multiple) {
-                    question += '<a href="#" class="validatemulti">' + getTranslation('validateAnswers') + '</a>';
-                } else if (type !== 'multiple') {
                     question += '<a href="#" class="validatemulti">' + getTranslation('validateAnswer') + '</a>';
+                } else if (type !== 'multiple') {
+                    question += '<a href="#" class="validatemulti">' + getTranslation('validateAnswerSingular') + '</a>';
                 }
                 question += '</section>';
 
             TweenMax.fromTo($(prev), 0.5, {left: 0, opacity: 1}, {
                 left: -w - 50, opacity: 0, onComplete: function () {
                     $(prev).hide();
-                   endTransition();
+                    endTransition();
                 }
             });
             resizeContainer();
             setScormValue('cmi.core.lesson_status', 'completed');
             setSCORMLocation({q: 1});
 
-            checkScore();
+            var passed = checkScore();
+            if (logAttempts) {
+                $.ajax('https://toolbox.fluidbook.com/quizlog/',
+                    {
+                        method: 'post',
+                        data: logdata,
+                    }
+                );
+            }
         }
 
         function checkScore() {
-
             var normalizedScore = score / totalQuestions;
             $('#results > h2').hide();
+            var passed;
             if (threshold === 0) {
                 $('.defaultMessage').show();
+                passed = true;
             } else if (normalizedScore >= threshold) {
                 $(".passedMessage").show();
                 execAction(passedAction);
+                passed = true;
             } else {
                 $('.failedMessage').show();
                 execAction(failedAction);
+                passed = false;
             }
         }
 
 
         function displayBadge(correct) {
             resize();
+            if (!instantReview) {
+                nextScreen();
+                return;
+            }
             if (correct) {
                 $("#badge").addClass('correct').removeClass('incorrect');
             } else {