From: Vincent Vanwaelscappel Date: Thu, 21 Sep 2023 14:40:28 +0000 (+0200) Subject: wip #6186 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=59d7928e1f7bebdccbeb03770d9c46e7a0e46853;p=fluidbook-toolbox-quiz.git wip #6186 @1.5 --- diff --git a/js/quiz.attemptslog.js b/js/quiz.attemptslog.js new file mode 100644 index 0000000..42dbb3d --- /dev/null +++ b/js/quiz.attemptslog.js @@ -0,0 +1,8 @@ +function QuizAttemptsLog(quiz) { + this.quiz = quiz; + +} + +QuizAttemptsLog.prototype = {} + +export default QuizAttemptsLog; diff --git a/js/quiz.js b/js/quiz.js index 00ffaf9..a796ecb 100644 --- a/js/quiz.js +++ b/js/quiz.js @@ -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(); }, diff --git a/js/quiz.score.js b/js/quiz.score.js index 64f912f..665bcb9 100644 --- a/js/quiz.score.js +++ b/js/quiz.score.js @@ -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; diff --git a/js/quiz.scorm.js b/js/quiz.scorm.js index 1a6409d..1d347d8 100644 --- a/js/quiz.scorm.js +++ b/js/quiz.scorm.js @@ -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; diff --git a/js/quiz.screens.js b/js/quiz.screens.js index 513e927..b4b8c0f 100644 --- a/js/quiz.screens.js +++ b/js/quiz.screens.js @@ -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 = [];