]> _ Git - hf-scorm-package.git/commitdiff
wip #4907 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 15 Dec 2021 15:02:34 +0000 (16:02 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 15 Dec 2021 15:02:34 +0000 (16:02 +0100)
js/libs/scorm/facade.js
js/scormpackage.js
packages/QZ/QZ.zip [new file with mode: 0644]
packages/QZ/imsmanifest.xml [new file with mode: 0644]
packages/QZ/js/main.js
style/style.css
style/style.sass

index 78e60d9a9ac446efbe3871bc6ab493d001201ba5..eed23e5a03daadfede7897e09648b5cb94de45f5 100644 (file)
@@ -2,26 +2,45 @@ function SCORMFacade() {
 }
 
 SCORMFacade.prototype = {
+    LMSInitialize: function () {
+        return this.Initialize();
+    },
     Initialize: function () {
         this._log('Init');
         return true;
     },
+    LMSFinish: function () {
+        return this.Terminate();
+    },
     Terminate: function () {
         this._log('Terminate');
-        return finishScorm();
+        closeSubSCO();
+        return true;
+    },
+    LMSGetValue: function (key) {
+        return this.GetValue(key);
     },
     GetValue: function (key) {
-        this._log('Get value ' + key);
         var d = savedState[currentModule.id];
-
+        var res;
         if (key === 'cmi.core.lesson_status' || key === 'cmi.completion_status') {
-            return d.completion_status;
+            res = d.completion_status;
         } else if (key === 'cmi.location' || key === 'cmi.core.lesson_location') {
-            return JSON.stringify(d.location);
+            if (typeof d.location === 'string' || typeof d.location === 'number') {
+                res = d.location;
+            } else {
+                res = JSON.stringify(d.location);
+            }
         } else if (key === 'cmi.success_status') {
-            return d.success_status;
+            res = d.success_status;
+        } else {
+            res = d.cmi[key] === null ? '' : d.cmi[key];
         }
-        return d.cmi[key] === null ? 'null' : d.cmi[key];
+        this._log('Get value ' + key + ' :: ' + res);
+        return res;
+    },
+    LMSSetValue: function (key, value) {
+        return this.SetValue(key, value);
     },
     SetValue: function (key, value) {
         this._log('Set value ' + key + ' :: ' + value);
@@ -42,17 +61,28 @@ SCORMFacade.prototype = {
         setModuleState(currentModule.id, data);
         return true;
     },
+    LMSCommit: function (d) {
+        return this.Commit(d);
+    },
     Commit: function (d) {
-        this._log('Commit');
         return true;
     },
+    LMSGetLastError: function () {
+        return this.GetLastError();
+    },
     GetLastError: function () {
         return 0;
     },
-    GetErrorString: function () {
+    LMSGetErrorString: function (code) {
+        return this.GetErrorString(code);
+    },
+    GetErrorString: function (code) {
         return '';
     },
-    GetDiagnostic: function () {
+    LMSGetDiagnostic: function (code) {
+        return this.GetDiagnostic(code);
+    },
+    GetDiagnostic: function (code) {
         return '';
     },
     _log: function (log) {
index 0cdc6d7f0074c1fd1174de4e564311787d7574ab..f23d4005ab7194ed7c7ecd9e04a8a25fc491c493 100644 (file)
@@ -89,8 +89,7 @@ function initScorm() {
     initState();
     setContents();
     initEvents();
-    window.API = null;
-    window.API_1484_11 = new SCORMFacade();
+    window.API = window.API_1484_11 = new SCORMFacade();
     return SCORM_OK;
 }
 
@@ -113,7 +112,7 @@ function initState() {
 
 
     $.each(DATA.modules, function (k, v) {
-        var defaultState = {completion_status: 'incomplete', success_status: 'unknown', score: 0, location: {}, cmi: {}};
+        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;
         } else {
@@ -208,16 +207,12 @@ function openSubSCO(id) {
     $("#sco").attr('src', path);
 
     if (!module.scorm) {
-        setModuleState(module.id, {completion_status: 'completed', success_status: 'passed', score: 100});
+        setModuleState(module.id, {completion_status: 'completed', success_status: 'passed'});
     }
 }
 
 function setModuleState(id, data) {
-    console.log('setModuleState', id, JSON.stringify(data));
-    console.log(JSON.stringify(window.savedState));
     $.extend(true, window.savedState[id], data);
-    console.log(window.savedState[id]);
-    console.log(JSON.stringify(window.savedState));
     saveStatus();
     setContents();
 }
@@ -247,16 +242,35 @@ function setContents() {
 
     $.each(DATA.modules, function (k, v) {
         var s = window.savedState[v.id];
+        var score = calcScore(s);
         var tr = $('<tr data-type="' + v.type + '" data-id="' + v.id + '"><td class="i">' + getSpriteIcon('icon-' + v.type) + '</td></tr>');
         $('tbody').append(tr);
         tr.append('<td class="t">' + v.title + '</td>');
         tr.append('<td class="y">' + types[v.type] + '</td>');
         tr.append('<td class="c">' + (v.mandatory ? vcheck : xcheck) + '</td>');
         tr.append('<td class="c">' + (s.completion_status === 'completed' ? vcheck : xcheck) + '</td>');
-        tr.append('<td class="score c" data-score="' + s.score + '"><div>' + s.score + ' %</div></td>');
+        tr.append('<td class="score c" data-score="' + score + '"><div>' + (score === 0 ? '-' : score + ' %') + '</div></td>');
     });
 }
 
+function calcScore(s) {
+    var raw = doubleQuestionMark(s.cmi['cmi.core.score.raw'], s.cmi['cmi.score.raw'], 0);
+    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);
+    var scale = max - min;
+    var norm = raw - min;
+    return 100 * (norm / scale);
+}
+
+function doubleQuestionMark() {
+    for (var i = 0; i < arguments.length; i++) {
+        if (arguments[i] === undefined || arguments[i]===null) {
+            continue;
+        }
+        return arguments[i];
+    }
+}
+
 (function (global) {
     'use strict';
     if (!global.console) {
diff --git a/packages/QZ/QZ.zip b/packages/QZ/QZ.zip
new file mode 100644 (file)
index 0000000..cb2eeb2
Binary files /dev/null and b/packages/QZ/QZ.zip differ
diff --git a/packages/QZ/imsmanifest.xml b/packages/QZ/imsmanifest.xml
new file mode 100644 (file)
index 0000000..b5f65e3
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest
+        xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2"
+        xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_rootv1p2p1"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2"
+        identifier="MANIFEST-90878C16-EB60-D648-94ED-9651972B5F38"
+        xsi:schemaLocation="http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
+                            http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd
+                            http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd">
+    <metadata>
+        <schema>ADL SCORM</schema>
+        <schemaversion>1.2</schemaversion>
+    </metadata>
+    <organizations default="ACME-ORG-1350650111249">
+        <organization identifier="ACME-ORG-1350650111249" structure="hierarchical">
+            <title>HF SCORM Multiple Package</title>
+            <item identifier="HF_SCORM_PACKAGE" identifierref="HF_SCORM_PACKAGE" isvisible="true">
+                <title>HF SCORM Multiple Package</title>
+            </item>
+        </organization>
+    </organizations>
+    <resources>
+        <resource type="webcontent" adlcp:scormtype="sco" identifier="HF_SCORM_PACKAGE" href="index.html">
+            <file href="index.html"/>
+        </resource>
+    </resources>
+</manifest>
\ No newline at end of file
index c9a25f893489e4ae759a7540adb1825a998992f9..7092b4adf9efa4deea57a9a7a8392166933162fb 100644 (file)
             $("main").append(results);
 
             $(document).on('quizinit', function (event, state) {
+                console.log(state);
                 init(state)
             });
             initScormEvents();
index d253454d1d57493bba41dff1fe2ee758340c1177..96cbb68572157798a27b0380a6e932ddb3a2ca79 100644 (file)
@@ -192,7 +192,7 @@ header h1 {
 }
 #wrapper main table tbody td.score div {
   white-space: nowrap;
-  width: 60px;
+  width: 70px;
   padding: 5px;
   margin: 0 auto;
   background-color: #e4ff19;
index 7dbc73c29e5df994136819d3d2818525bdf081c1..cd7e52a9f64806bdb7bb954981298a9eeb5ae828 100644 (file)
@@ -153,7 +153,7 @@ header
           &.score
             div
               white-space: nowrap
-              width: 60px
+              width: 70px
               padding: 5px
               margin: 0 auto
               background-color: #e4ff19