From: Vincent Vanwaelscappel Date: Wed, 15 Dec 2021 17:12:02 +0000 (+0100) Subject: wip #4907 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=f2125ef1f1fca4d648b1f01ac69098a01d6d0efd;p=hf-scorm-package.git wip #4907 @1.5 --- diff --git a/HF_Scorm_Package.zip b/HF_Scorm_Package.zip new file mode 100644 index 0000000..1da905d Binary files /dev/null and b/HF_Scorm_Package.zip differ diff --git a/data.js b/data.js index 5a5b57d..7442536 100644 --- a/data.js +++ b/data.js @@ -2,7 +2,7 @@ const DATA = { "title": "Title of the project", "modules": [ { - "id": 0, + "id": "0", "title": "Title of the module", "type": "IN", "path": "packages/IN/HF_IN_PositiveCulture_v1_UK EN_outlined.pdf", @@ -10,7 +10,7 @@ const DATA = { "scorm": false, }, { - "id": 1, + "id": "1", "title": "Title of the module", "type": "AN", "path": "packages/AN/HF_AN_038_Building a positive culture_UK EN.mp4", @@ -18,7 +18,7 @@ const DATA = { "scorm": false, }, { - "id": 2, + "id": "2", "title": "Title of the module", "type": "VI", "path": "packages/Ti5/TI5_100_Positive-Culture_UK EN.mp4", @@ -26,7 +26,7 @@ const DATA = { "scorm": false, }, { - "id": 3, + "id": "3", "title": "Title of the module", "type": "FB", "path": "packages/FB/index.html", @@ -34,7 +34,7 @@ const DATA = { "scorm": true, }, { - "id": 4, + "id": "4", "title": "Title of the module", "type": "QZ", "path": "packages/QZ/index.html", diff --git a/imsmanifest.xml b/imsmanifest.xml index b5f65e3..5aebe97 100644 --- a/imsmanifest.xml +++ b/imsmanifest.xml @@ -1,26 +1,40 @@ - - + + ADL SCORM - 1.2 + 2004 4th Edition - - - HF SCORM Multiple Package - - HF SCORM Multiple Package + + + HF Scorm Multi Package + + HF Scorm Multi Package + + + continue + previous + exit + exitAll + suspendAll + abandonAll + + - + diff --git a/js/scormpackage.js b/js/scormpackage.js index f23d400..964f160 100644 --- a/js/scormpackage.js +++ b/js/scormpackage.js @@ -94,6 +94,12 @@ function initScorm() { } function initState() { + + if (SCORM_LOCATION_INITED) { + return; + } + SCORM_LOCATION_INITED = true; + var currentLocation = ''; if (SCORM_OK) { currentLocation = getScormValue('location'); @@ -105,18 +111,21 @@ function initState() { window.savedState = JSON.parse(currentLocation); } + console.log(currentLocation, window.savedState); + if (window.savedState === undefined || window.savedState === null || window.savedState === 'null') { window.savedState = {}; } - + var clone = $.extend(true, {}, window.savedState); $.each(DATA.modules, function (k, v) { + var id = v.id.toString(); var defaultState = {completion_status: 'incomplete', success_status: 'unknown', score: 0, location: '', cmi: {}}; - if (window.savedState[v.id] === undefined || window.savedState[v.id] === null) { - window.savedState[v.id] = defaultState; + if (clone[id] === undefined || clone[id] === null) { + window.savedState[id] = defaultState; } else { - $.extend(true, window.savedState[v.id], defaultState); + window.savedState[id] = $.extend(true, defaultState, clone[id]); } }); } @@ -135,9 +144,7 @@ function finishScorm() { } setSessionTime(); pipwerks.SCORM.save(); - if (fluidbook.settings.multilang === '') { - pipwerks.SCORM.quit(); - } + pipwerks.SCORM.quit(); } function scormExit() { @@ -145,14 +152,6 @@ function scormExit() { return; } var v = 'suspend'; - if (fluidbook.settings.scorm_force_attempts) { - if (pipwerks.SCORM.version === '1.2') { - v = 'logout'; - } else { - v = 'normal'; - } - } - setScormValue('exit', v); } @@ -212,13 +211,48 @@ function openSubSCO(id) { } function setModuleState(id, data) { - $.extend(true, window.savedState[id], data); + var clone = $.extend(true, {}, window.savedState[id]); + window.savedState[id] = $.extend(true, {}, clone, data); saveStatus(); setContents(); } function saveStatus() { + if (!SCORM_LOCATION_INITED) { + return; + } setSCORMLocation(window.savedState); + var completed = true; + var globalScore = 0; + var globalScoreItems = 0; + for (var k in DATA.modules) { + var m = DATA.modules[k]; + var s = window.savedState[m.id]; + if (m.mandatory && s.completion_status !== 'completed' && s.completion_status !== 'passed') { + completed = false; + } + var score = calcScore(s); + if (!isNaN(score) && score >= 0) { + globalScore += score; + globalScoreItems++; + } + } + var score100 = globalScore / globalScoreItems; + if (isNaN(score100)) { + score100 = -1; + } + if (score100 > 0) { + setScormValue('cmi.score.raw', score100); + setScormValue('cmi.score.scaled', score100 / 100); + setScormValue('cmi.score.min', 0); + setScormValue('cmi.score.max', 100); + } + if (!isNaN(score100) && score100 > 0) { + setScormValue('success_status', 'passed'); + } else { + setScormValue('success_status', 'unknown'); + } + setScormValue('status', completed ? 'completed' : 'incomplete'); } function getModuleData(id) { @@ -232,6 +266,9 @@ function getModuleData(id) { } function setContents() { + if (!SCORM_LOCATION_INITED) { + return; + } var vcheck = getSpriteIcon('check-ok'); var xcheck = getSpriteIcon('check-nok'); var types = {IN: 'Infographic PDF', AN: 'Animation', VI: 'Video', FB: 'Fluidbook', PC: 'Podcast HTML', QZ: 'Quiz'}; @@ -249,22 +286,30 @@ function setContents() { tr.append('' + types[v.type] + ''); tr.append('' + (v.mandatory ? vcheck : xcheck) + ''); tr.append('' + (s.completion_status === 'completed' ? vcheck : xcheck) + ''); - tr.append('
' + (score === 0 ? '-' : score + ' %') + '
'); + tr.append('
' + (score < 0 ? '-' : score + ' %') + '
'); }); } function calcScore(s) { - var raw = doubleQuestionMark(s.cmi['cmi.core.score.raw'], s.cmi['cmi.score.raw'], 0); + if (s === undefined) { + return -1; + } + var raw = doubleQuestionMark(s.cmi['cmi.core.score.raw'], s.cmi['cmi.score.raw'], -1); var max = doubleQuestionMark(s.cmi['cmi.core.score.max'], s.cmi['cmi.score.max'], 100); var min = doubleQuestionMark(s.cmi['cmi.core.score.min'], s.cmi['cmi.score.min'], 0); + + console.log(raw, max, min); var scale = max - min; var norm = raw - min; + if (isNaN(scale) || isNaN(norm)) { + return -1; + } return 100 * (norm / scale); } function doubleQuestionMark() { for (var i = 0; i < arguments.length; i++) { - if (arguments[i] === undefined || arguments[i]===null) { + if (arguments[i] === undefined || arguments[i] === null) { continue; } return arguments[i]; @@ -300,15 +345,6 @@ function initScormEvents() { finishScorm(); }); - if (SCORM_LOCATION_INITED) { - return; - } - SCORM_LOCATION_INITED = true; - - - initEvents(); - setContents(); - setInterval(function () { pipwerks.SCORM.save(); }, 5000); @@ -350,9 +386,6 @@ function setScormValue(elementName, value) { return false; } var result = pipwerks.SCORM.set(cmi, value); - if (fluidbook.settings.scorm_immediate_commit) { - pipwerks.SCORM.save(); - } return result; } diff --git a/packages/QZ/js/main.js b/packages/QZ/js/main.js index 7092b4a..c9a25f8 100644 --- a/packages/QZ/js/main.js +++ b/packages/QZ/js/main.js @@ -115,7 +115,6 @@ $("main").append(results); $(document).on('quizinit', function (event, state) { - console.log(state); init(state) }); initScormEvents();