From 5f727fa0fba11133a961917e6f04fab50827109e Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 19 Aug 2024 04:27:36 +0530 Subject: [PATCH] Updated SCORM Package --- _sources/lectures/TWP52_en.rst | 5 +++- _static/APIWrapper.js | 14 +++++++++ _static/SCORMFunctions.js | 22 ++++++++++++++ _static/auth.js | 52 ++++++++++++++++++++++++++++++++++ scorm_package/chapter1.html | 5 ++++ scorm_package/chapter2.html | 12 ++++++-- scorm_package/imsmanifest.xml | 26 +++++++++++------ scorm_package/login.html | 21 ++++++++++++++ scorm_package/signup.html | 20 +++++++++++++ 9 files changed, 165 insertions(+), 12 deletions(-) create mode 100644 _static/auth.js create mode 100644 scorm_package/login.html create mode 100644 scorm_package/signup.html diff --git a/_sources/lectures/TWP52_en.rst b/_sources/lectures/TWP52_en.rst index b2c46915e..518fd3b8c 100644 --- a/_sources/lectures/TWP52_en.rst +++ b/_sources/lectures/TWP52_en.rst @@ -306,7 +306,10 @@ Review .. raw:: html - :file: ../../scorm_package/chapter1.html + + .. disqus:: :shortname: pyzombis diff --git a/_static/APIWrapper.js b/_static/APIWrapper.js index 4f1753ddb..b37d2f2da 100644 --- a/_static/APIWrapper.js +++ b/_static/APIWrapper.js @@ -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 ""; +} diff --git a/_static/SCORMFunctions.js b/_static/SCORMFunctions.js index e94380937..30f1f62fa 100644 --- a/_static/SCORMFunctions.js +++ b/_static/SCORMFunctions.js @@ -1,10 +1,12 @@ // 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."); } @@ -12,6 +14,13 @@ function unloadPage() { 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") { @@ -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) { @@ -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); } diff --git a/_static/auth.js b/_static/auth.js new file mode 100644 index 000000000..1b478cfdd --- /dev/null +++ b/_static/auth.js @@ -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; diff --git a/scorm_package/chapter1.html b/scorm_package/chapter1.html index 75a19d558..6d51ab2a9 100644 --- a/scorm_package/chapter1.html +++ b/scorm_package/chapter1.html @@ -6,11 +6,16 @@ Chapter 1 +

Chapter 1: Introduction

+

Checking completion status...

+ + + diff --git a/scorm_package/chapter2.html b/scorm_package/chapter2.html index 9ebae3f91..f3e3f9f55 100644 --- a/scorm_package/chapter2.html +++ b/scorm_package/chapter2.html @@ -6,10 +6,16 @@ Chapter 2 + - +

Chapter 2: Uff

-

Complete this chapter by clicking the button below.

- + +

Checking completion status...

+ + + + + diff --git a/scorm_package/imsmanifest.xml b/scorm_package/imsmanifest.xml index 8fed7e6a0..59ef4aba7 100644 --- a/scorm_package/imsmanifest.xml +++ b/scorm_package/imsmanifest.xml @@ -24,15 +24,25 @@ - - - + + + + - - - + + + + - - + + + + + + + + + + \ No newline at end of file diff --git a/scorm_package/login.html b/scorm_package/login.html new file mode 100644 index 000000000..5c1416ca4 --- /dev/null +++ b/scorm_package/login.html @@ -0,0 +1,21 @@ + + + + + + Login + + + +

Login

+
+
+
+
+
+ Remember Me

+ +
+

Don't have an account? Sign Up

+ + diff --git a/scorm_package/signup.html b/scorm_package/signup.html new file mode 100644 index 000000000..43f2e7651 --- /dev/null +++ b/scorm_package/signup.html @@ -0,0 +1,20 @@ + + + + + + Sign Up + + + +

Sign Up

+
+
+
+
+

+ +
+

Already have an account? Login

+ +