Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load SCORM data through fetch instead of embedding it in the page
fixes #266 The run_attempt view doesn't embed the SCORM data model in the HTML any more. Instead, the client makes a fetch request to a new `/run_attempt/<pk>/scorm_cmi` view, which returns the current SCORM data. This ensures that even if the page has reloaded from the browser's cache, it will only start with the latest data. If the data can't be loaded for some reason, such as no network connection, the student is shown an error message and a button to reload the page. This commit also makes the run attempt and scorm cmi views throw a PermissionDenied error if the attempt would be opened in review mode, but review is not allowed yet, and the user is not an instructor. Previously, a student could open an attempt in review mode by reloading the page, even when it's not allowed yet. An AttemptLaunch record is created each time the SCORM data model is requested. This should give more detail about when a student reloads an attempt by browser navigation instead of by clicking links.
- Loading branch information
1 parent
fc26f47
commit ec43298
Showing
10 changed files
with
173 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
function initialise_api(scorm_cmi) { | ||
var scorm_api_data = js_vars.scorm_api_data; | ||
scorm_api_data.scorm_cmi = scorm_cmi; | ||
try { | ||
var sc = new SCORM_API(scorm_api_data); | ||
window.API_1484_11 = sc.API_1484_11; | ||
} catch(e) { | ||
console.error(e); | ||
alert(gettext("A connection to the server could not be created. Please report this.")); | ||
redirect_to_attempts(); | ||
} | ||
if(document.readyState == 'complete') { | ||
load_iframe(); | ||
} else { | ||
window.addEventListener('load',function() { | ||
load_iframe(); | ||
}); | ||
} | ||
} | ||
|
||
function redirect_to_attempts() { | ||
window.location.href = js_vars.scorm_api_data.show_attempts_url; | ||
} | ||
|
||
function load_iframe() { | ||
var iframe = document.createElement('iframe'); | ||
iframe.setAttribute('id','scorm-player'); | ||
iframe.setAttribute('width','100%'); | ||
iframe.setAttribute('height','100%'); | ||
iframe.setAttribute('src',js_vars.exam_url); | ||
var iframe_container = document.getElementById('scorm-player-container'); | ||
iframe_container.innerHTML = ''; | ||
iframe_container.appendChild(iframe); | ||
} | ||
|
||
function show_loading_error(e) { | ||
document.body.classList.add('terminated'); | ||
document.getElementById('scorm-player-container').style.display = 'none'; | ||
var status_display = document.getElementById('status-display'); | ||
status_display.className = 'loading-error'; | ||
console.error(e); | ||
} | ||
|
||
var js_vars = JSON.parse(document.getElementById('js_vars').textContent); | ||
|
||
fetch(js_vars.cmi_url, {headers: {'Accept': 'application/json'}}).then(function(response) { | ||
if(response.status == 403) { | ||
redirect_to_attempts(); | ||
return; | ||
} | ||
if(response.status != 200) { | ||
throw new Error(_("There was an error fetching the attempt data.")); | ||
} | ||
response.json().then(function(data) { initialise_api(data); }); | ||
}).catch(show_loading_error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% load i18n %}{% blocktranslate with allow_review_from=allow_review_from %}Review will be available from {{allow_review_from}}{% endblocktranslate %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters