Skip to content

Commit

Permalink
Updated SCORM Package
Browse files Browse the repository at this point in the history
  • Loading branch information
its-ChaTTy committed Aug 18, 2024
1 parent 73f24da commit 5f727fa
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 12 deletions.
5 changes: 4 additions & 1 deletion _sources/lectures/TWP52_en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@ Review


.. raw:: html
:file: ../../scorm_package/chapter1.html

<iframe src="https://dev.python.org.ar/mod/scorm/player.php?a=7&scoid=16" width="100%" height="600px">
Your browser does not support iframes.
</iframe>

.. disqus::
:shortname: pyzombis
Expand Down
14 changes: 14 additions & 0 deletions _static/APIWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,17 @@ function setProgress(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 "";
}
22 changes: 22 additions & 0 deletions _static/SCORMFunctions.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
// 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") {
Expand All @@ -29,6 +38,9 @@ function completeChapter(chapter) {
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) {
Expand All @@ -37,4 +49,14 @@ function resetChapter(chapter) {
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);
}
52 changes: 52 additions & 0 deletions _static/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// auth.js

function registerUser() {
const username = document.getElementById('newUsername').value;
const password = document.getElementById('newPassword').value;

// Store the new user in local storage
localStorage.setItem('username', username);
localStorage.setItem('password', password);

alert('Registration successful! Please log in.');
window.location.href = '../scorm_package/login.html';
return false;
}

function loginUser() {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
const rememberMe = document.getElementById('rememberMe').checked;

const storedUsername = localStorage.getItem('username');
const storedPassword = localStorage.getItem('password');

if (username === storedUsername && password === storedPassword) {
if (rememberMe) {
localStorage.setItem('loggedInUser', username);
}
sessionStorage.setItem('loggedInUser', username);
alert('Login successful!');
window.location.href = '../scorm_package/chapter1.html'; // Redirect to the first chapter
} else {
alert('Invalid username or password!');
}
return false;
}

function logoutUser() {
sessionStorage.removeItem('loggedInUser');
alert('You have been logged out.');
window.location.href = '../scorm_package/login.html';
}

function checkLogin() {
const loggedInUser = sessionStorage.getItem('loggedInUser') || localStorage.getItem('loggedInUser');

if (!loggedInUser) {
alert('You are not logged in. Please log in first.');
window.location.href = '../scorm_package/login.html';
}
}

window.onload = checkLogin;
5 changes: 5 additions & 0 deletions scorm_package/chapter1.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
<title>Chapter 1</title>
<script src="../_static/APIWrapper.js"></script>
<script src="../_static/SCORMFunctions.js"></script>
<script src="../_static/auth.js"></script>
</head>
<body onload="loadChapter('chapter1')" onunload="unloadPage()">
<h1>Chapter 1: Introduction</h1>
<button onclick="logoutUser()">Logout</button>
<p id="completion-status">Checking completion status...</p>
<button id="complete-button" onclick="completeChapter('chapter1')">Mark this Chapter as Completed</button>
<button id="reset-button" onclick="resetChapter('chapter1')">Reset Progress</button>

<!-- Textbox for user to write and save data -->
<textarea id="chapter-textbox" rows="10" cols="50" placeholder="Write your notes here..."></textarea>
</body>
</html>
12 changes: 9 additions & 3 deletions scorm_package/chapter2.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
<title>Chapter 2</title>
<script src="../_static/APIWrapper.js"></script>
<script src="../_static/SCORMFunctions.js"></script>
<script src="../_static/auth.js"></script>
</head>
<body onload="loadPage()" onunload="unloadPage()">
<body onload="loadChapter('chapter2')" onunload="unloadPage()">
<h1>Chapter 2: Uff</h1>
<p>Complete this chapter by clicking the button below.</p>
<button onclick="completeChapter('chapter2')">Complete Chapter 2</button>
<button onclick="logoutUser()">Logout</button>
<p id="completion-status">Checking completion status...</p>
<button id="complete-button" onclick="completeChapter('chapter2')">Mark this Chapter as Completed</button>
<button id="reset-button" onclick="resetChapter('chapter2')">Reset Progress</button>

<!-- Textbox for user to write and save data -->
<textarea id="chapter-textbox" rows="10" cols="50" placeholder="Write your notes here..."></textarea>
</body>
</html>
26 changes: 18 additions & 8 deletions scorm_package/imsmanifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,25 @@
</organizations>
<resources>
<resource identifier="resource1" type="webcontent" adlcp:scormtype="sco" href="chapter1.html">
<file href="chapter1.html"/>
<file href="../_static/SCORMFunctions.js"/>
<file href="../_static/APIWrapper.js"/>
<file href="chapter1.html"/>
<file href="../_static/SCORMFunctions.js"/>
<file href="../_static/APIWrapper.js"/>
<file href="../_static/auth.js"/>
</resource>
<resource identifier="resource2" type="webcontent" adlcp:scormtype="sco" href="chapter2.html">
<file href="chapter2.html"/>
<file href="../_static/SCORMFunctions.js"/>
<file href="../_static/APIWrapper.js"/>
<file href="chapter2.html"/>
<file href="../_static/SCORMFunctions.js"/>
<file href="../_static/APIWrapper.js"/>
<file href="../_static/auth.js"/>
</resource>
<!-- Add more resources for additional chapters -->
</resources>
<resource identifier="loginResource" type="webcontent" adlcp:scormtype="sco" href="login.html">
<file href="login.html"/>
<file href="../_static/auth.js"/>
</resource>
<resource identifier="signupResource" type="webcontent" adlcp:scormtype="sco" href="signup.html">
<file href="signup.html"/>
<file href="../_static/auth.js"/>
</resource>
<!-- Add more resources as needed -->
</resources>
</manifest>
21 changes: 21 additions & 0 deletions scorm_package/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<script src="../_static/auth.js"></script>
</head>
<body>
<h1>Login</h1>
<form onsubmit="return loginUser()">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username" required><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password" required><br>
<input type="checkbox" id="rememberMe" name="rememberMe"> Remember Me<br><br>
<input type="submit" value="Login">
</form>
<p>Don't have an account? <a href="signup.html">Sign Up</a></p>
</body>
</html>
20 changes: 20 additions & 0 deletions scorm_package/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up</title>
<script src="../_static/auth.js"></script>
</head>
<body>
<h1>Sign Up</h1>
<form onsubmit="return registerUser()">
<label for="newUsername">Username:</label><br>
<input type="text" id="newUsername" name="newUsername" required><br>
<label for="newPassword">Password:</label><br>
<input type="password" id="newPassword" name="newPassword" required><br><br>
<input type="submit" value="Sign Up">
</form>
<p>Already have an account? <a href="login.html">Login</a></p>
</body>
</html>

0 comments on commit 5f727fa

Please sign in to comment.