]> _ Git - fluidbook-toolbox-quiz.git/commitdiff
wip #6186 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 21 Sep 2023 14:40:28 +0000 (16:40 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 21 Sep 2023 14:40:28 +0000 (16:40 +0200)
js/quiz.attemptslog.js [new file with mode: 0644]
js/quiz.js
js/quiz.score.js
js/quiz.scorm.js
js/quiz.screens.js

diff --git a/js/quiz.attemptslog.js b/js/quiz.attemptslog.js
new file mode 100644 (file)
index 0000000..42dbb3d
--- /dev/null
@@ -0,0 +1,8 @@
+function QuizAttemptsLog(quiz) {
+    this.quiz = quiz;
+
+}
+
+QuizAttemptsLog.prototype = {}
+
+export default QuizAttemptsLog;
index 00ffaf9dfed9b5fd7c1080c23e9cd9db075be267..a796ecb75b65a244e305ebb6b583c0c29d805107 100644 (file)
@@ -1,6 +1,5 @@
 import $ from "cash-dom";
 import 'swiper/css';
-import {CubeSCORM} from '/application/resources/scorm/scorm';
 
 import QuizResize from "./quiz.resize";
 import QuizAnimations from "./quiz.animations";
@@ -14,8 +13,9 @@ import QuizProgressbar from "./quiz.progressbar";
 import QuizL10n from "./quiz.l10n";
 import QuizDraganddrop from "./quiz.draganddrop";
 import QuizMatch from "./quiz.match";
+import QuizAttemptsLog from "./quiz.attemptslog";
+
 
-window.cubeSCORM = new CubeSCORM();
 window.$ = window.jQuery = $;
 
 import ResizeObserver from 'resize-observer-polyfill';
@@ -38,7 +38,6 @@ Quiz.prototype = {
         this.animations = new QuizAnimations(this);
         this.question = new QuizQuestion(this);
         this.score = new QuizScore(this);
-        this.scorm = new QuizScorm(this);
         this.resize = new QuizResize(this);
         this.utils = new QuizUtils(this);
         this.accessibility = new QuizAccessibility(this);
@@ -47,16 +46,38 @@ Quiz.prototype = {
         this.l10n = new QuizL10n(this);
         this.draganddrop = new QuizDraganddrop(this);
         this.match = new QuizMatch(this);
+        this.attemptsLog = new QuizAttemptsLog(this);
+
+        this.scorm = new QuizScorm(this);
+    },
+
+    initQuiz: function (state) {
+        const $this = this;
 
         // La fonction resize est appelée à chaque fois qu'un resize de la fenêtre survient (et à l'init de l'app)
         $(window).on('resize', function () {
             $this.quizResize();
         });
-        this.quizResize();
-        $('#quiz').addClass('ready');
 
-        // Afficher l'écran d'introduction et lancer l'animation
-        this.screens.intro.show();
+        let callback = function () {
+            $this.quizResize();
+            $('#quiz').addClass('ready');
+        }
+
+        console.log(state);
+
+        if (state.q === undefined || state.q === -1) {
+            // Afficher l'écran d'introduction et lancer l'animation
+            this.screens.intro.show();
+            this.score.init();
+            callback();
+        } else {
+            let i;
+            for (i = 0; i - 1 < state.q; i++) {
+                this.score.setAnswer(i, state.a[i]);
+            }
+            this.screens.showScreen('q-' + i, callback);
+        }
         this.progressbar.update();
     },
 
index 64f912f54a8758d8ab3060c19e00bf617af626b8..665bcb9639ce3fab8b5a88d5b03e43a919cb7e8a 100644 (file)
@@ -9,7 +9,6 @@ function QuizScore(quiz) {
     this.questionStatus = [];
     this.answers = [];
     this.lastAnsweredQuestion = -1;
-    this.init();
 }
 
 QuizScore.prototype = {
@@ -139,7 +138,7 @@ QuizScore.prototype = {
         return min_score;
     },
 
-    updateScore: function () {
+    updateScore: function (saveState) {
         this.maxScore = 0;
         this.score = 0;
         this.logQuestions = [];
@@ -148,14 +147,14 @@ QuizScore.prototype = {
             this.checkQuestion(qn);
         }
 
-        let state = {
+        this.quiz.scorm.saveState(this.getCurrentState());
+    },
+
+    getCurrentState: function () {
+        return {
             q: this.lastAnsweredQuestion + 1, a: this.answers
         };
-
-        if (cubeSCORM.SCORM) {
-            cubeSCORM.setSCORMLocation(state);
-        }
-    },
+    }
 };
 
 export default QuizScore;
index 1a6409d1830fe49338bc6707123c1dac7ddf2f9b..1d347d8f9a111d3e127201fb68c098194719a737 100644 (file)
@@ -1,7 +1,55 @@
+import {CubeSCORM} from '/application/resources/scorm/scorm';
+
+window.cubeSCORM = new CubeSCORM();
+
 function QuizScorm(quiz) {
     this.quiz = quiz;
+    this.inited = false;
+    this.enabled = false;
+    //this.defaultState = {q: -1, a: []};
+    this.defaultState = {q: 0, a: [[1,1,2,1,2]]};
+    this.skipSaveState = false;
+
+    this.init();
+
 }
 
-QuizScorm.prototype = {};
+QuizScorm.prototype = {
+
+    init: function () {
+        if (cubeSCORM.SCORM_INITED) {
+            return;
+        }
+
+        let disableScorm = window.parent !== undefined && window.parent.fluidbook !== undefined;
+
+        cubeSCORM.initScorm(disableScorm);
+        this.enabled = cubeSCORM.SCORM_OK;
+        this.inited = true;
+
+        const $this = this;
+
+        setTimeout(function () {
+            $this.skipSaveState = true;
+            $this.quiz.initQuiz(cubeSCORM.getScormLocation($this.defaultState));
+            $this.skipSaveState = false;
+        }, 50)
+    },
+
+    completed: function (passed) {
+        cubeSCORM.scormMarkAsComplete();
+        cubeSCORM.setScormValue('success_status', this.quiz.score.passed ? 'passed' : 'failed');
+        cubeSCORM.setSCORMScore(this.quiz.score.getNormalizedScore(true), 100, 0, this.quiz.score.getNormalizedScore());
+        this.saveState(this.defaultState)
+    },
+
+    saveState: function (state) {
+        console.log(state);
+        if (this.skipSaveState) {
+            return;
+        }
+        cubeSCORM.setSCORMLocation(state);
+    }
+};
 
 export default QuizScorm;
index 513e927c7d38feaa69a5930538e6913f47035de3..b4b8c0f306d55b330880844ebac5f90a15f309cf 100644 (file)
@@ -124,8 +124,6 @@ QuizScreens.prototype = {
         const $this = this;
         let screenToShow = $('[data-screen="' + screen + '"]');
         this.hideCurrentScreen(function () {
-
-
             $this.resetCountdownBackground();
             screenToShow.removeClass("none").addClass("next active-screen");
             if (callback !== undefined) {
@@ -140,7 +138,6 @@ QuizScreens.prototype = {
             //
             $this.animateContent(screenToShow);
 
-
             // Reset form to prevent browser letting a option selected after a refresh
             $this.resetForm();
             $this.currentQuestionAnswers = [];