Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete PyZombis SCORM Package Test #372

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions _sources/lectures/TWP50/TWP50_1_en.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
Introduction to a Graphical User Interface
.. raw:: html
:file: ../_static/APIWrapper.js

.. raw:: html
:file: ../_static/SCORMFunctions.js

|Introduction to a Graphical User Interface
===========================================

+ In programming, just writing code is not enough.
Expand Down Expand Up @@ -39,7 +45,6 @@ Playing Audio
:language: python3
:python3_interpreter: brython


from browser import document, html

url_audio = "" # Add a link of an audio to play it
Expand All @@ -58,7 +63,6 @@ Playing Audio

from browser import document, html, timer


def create_element(url_audio, audio_name):
print(f"Creating the audio element {url_audio}")
document <= html.AUDIO(id=audio_name, src=url_audio)
Expand Down Expand Up @@ -101,3 +105,10 @@ Playing Audio
:width: 10.688cm
:align: center
:alt:

.. raw:: html

<script>
// Save the chapter progress and suspend data at the end of the chapter
completeChapter("Introduction to a Graphical User Interface");
</script>
3 changes: 0 additions & 3 deletions _sources/lectures/TWP52_en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,6 @@ Review
+ RadioButton()
+ OptionMenu()




.. disqus::
:shortname: pyzombis
:identifier: lecture19
59 changes: 59 additions & 0 deletions _static/APIWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SCORM API Wrapper
var findAPITries = 0;
var API = null;

function findAPI(win) {
while ((win.API == null) && (win.parent != null) && (win.parent != win)) {
findAPITries++;
if (findAPITries > 7) {
return null;
}
win = win.parent;
}
return win.API;
}

function getAPI() {
var theAPI = findAPI(window);
if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined")) {
theAPI = findAPI(window.opener);
}
if (theAPI == null) {
alert("Unable to find an API adapter");
}
return theAPI;
}

function initializeAPI() {
API = getAPI();
if (API != null) {
API.LMSInitialize("");
}
}

function terminateAPI() {
if (API != null) {
API.LMSFinish("");
}
}

function setProgress(progress) {
if (API != null) {
API.LMSSetValue("cmi.core.lesson_status", progress);
API.LMSCommit("");
}
}

function setSuspendData(data) {
if (API != null) {
API.LMSSetValue("cmi.suspend_data", data);
API.LMSCommit("");
}
}

function getSuspendData() {
if (API != null) {
return API.LMSGetValue("cmi.suspend_data");
}
return "";
}
62 changes: 62 additions & 0 deletions _static/SCORMFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SCORM Functions

function loadPage() {
initializeAPI();
console.log("SCORM API initialized.");
}

function unloadPage() {
saveTextBoxData(); // Save data when the page is unloaded
terminateAPI();
console.log("SCORM API terminated.");
}

function loadChapter(chapter) {
loadPage();

var suspendData = getSuspendData();
if (suspendData) {
console.log("Suspend data retrieved:", suspendData);
// Restore the text data in the textbox
document.getElementById("chapter-textbox").value = suspendData;
}

var completionStatus = API.LMSGetValue("cmi.core.lesson_status");

if (completionStatus === "completed") {
document.getElementById("completion-status").innerText = "This chapter has been completed.";
document.getElementById("complete-button").style.display = "none";
} else {
document.getElementById("completion-status").innerText = "This chapter has not been completed.";
document.getElementById("reset-button").style.display = "none";
}
}

function completeChapter(chapter) {
setProgress("completed");
alert(chapter + " completed! Progress recorded.");
document.getElementById("completion-status").innerText = "This chapter has been completed.";
document.getElementById("complete-button").style.display = "none";
document.getElementById("reset-button").style.display = "block";

// Optionally save some suspend data when the chapter is completed
setSuspendData(document.getElementById("chapter-textbox").value);
}

function resetChapter(chapter) {
setProgress("incomplete");
alert(chapter + " reset to incomplete.");
document.getElementById("completion-status").innerText = "This chapter has not been completed.";
document.getElementById("complete-button").style.display = "block";
document.getElementById("reset-button").style.display = "none";

// Clear the suspend data if the chapter is reset
setSuspendData("");
document.getElementById("chapter-textbox").value = ""; // Clear the textbox as well
}

function saveTextBoxData() {
// Save the current state of the textbox into suspend data
var textBoxData = document.getElementById("chapter-textbox").value;
setSuspendData(textBoxData);
}
2 changes: 2 additions & 0 deletions _templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@
{% endraw %}
{% endif %}

<script src="../scorm_package/scripts/scorm_functions.js"></script>

{% endblock %}

{# Silence the sidebar's, relbar's #}
Expand Down
28 changes: 28 additions & 0 deletions imsmanifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<manifest identifier="com.example.scormminimal" version="1.2"
xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2"
xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd">
<metadata>
<schema>ADL SCORM</schema>
<schemaversion>1.2</schemaversion>
<adlcp:location>metadata.xml</adlcp:location>
</metadata>
<organizations default="org">
<organization identifier="org">
<title>Your Course Title</title>
<item identifier="item1" identifierref="resource1">
<title>TWP50_1_en</title>
</item>
<!-- Add more items for additional chapters -->
</organization>
</organizations>
<resources>
<resource identifier="resource1" type="webcontent" adlcp:scormtype="sco" href="_sorces/lectures/TWP50/TWP50_1_en.rst">
<file href="_sorces/lectures/TWP50/TWP50_1_en.rst"/>
<file href="_static/SCORMFunctions.js"/>
<file href="_static/APIWrapper.js"/>
</resource>
</resources>
</manifest>
Loading