Skip to content

Commit

Permalink
Merge branch 'adlnet:master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasturrell authored Aug 4, 2021
2 parents 059a47f + 964724b commit 6e20d32
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
17 changes: 13 additions & 4 deletions Examples/AUExample1.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="Scripts/cmi5Controller.js"></script>
<script src="Scripts/xapiwrapper.min.js"></script>
<script src="Scripts/cmi5Wrapper.js"></script>
<script src="Scripts/moment.min.js"></script>
<link href="Content/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="Content/bootstrap-theme.min.css" rel="stylesheet" type="text/css"/>
<link href="Content/prettify.min.css" rel="stylesheet" type="text/css"/>
Expand Down Expand Up @@ -157,6 +158,13 @@
// Enable the "next" button
jq("#btnNext").prop("disabled", false);
}

function GetDuration() {
var start = moment(cmi5Controller.getStartDateTime());
var end = moment(Date.now());

return moment.duration(end.diff(start), "ms").toISOString();
}

function GoPage(pageNo) {
// Hides all pages except the requested page number.
Expand All @@ -169,15 +177,16 @@
var score = testScore / 100;

// Send passed/failed
var duration = GetDuration();
if (score >= cmi5Controller.getMasteryScore()) {
SendStatement("Passed", score);
SendStatement("Passed", score, duration);
} else {
SendStatement("Failed", score);
SendStatement("Failed", score, duration);
}

// Since the student reached page 2 of a two page course, it is completed.
// Send a "cmi5 defined" completed statement.
SendStatement("Completed");
SendStatement("Completed", undefined, duration);
}

function sentStatement(resp, obj) {
Expand Down Expand Up @@ -232,7 +241,7 @@
<h3 class="panel-title">Training Page 1</h3>
</div>
<div class="col-md-8">
<button style="float: right;" type="button" class="btn btn-default" onclick="FinishAU();">Return to LMS</button>
<button style="float: right;" type="button" class="btn btn-default" onclick="FinishAU(GetDuration());">Return to LMS</button>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions Examples/Scripts/cmi5Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var cmi5Controller = (function () {
// Public properties
// **********************

// Initalize properties that are passed on the launch command line
// Initialize properties that are passed on the launch command line
this.endPoint = "";
this.fetchUrl = "";
this.registration = "";
Expand Down Expand Up @@ -84,7 +84,7 @@ var cmi5Controller = (function () {

// All activites required by cmi5Controller.startUp() have been performed. We can return
// to the calling AU by executing the callback passed to cmi5Controller.startUp().
startDateTime = new Date(); // Time of launch
startDateTime = Date.now(); // Time of launch
initializedCallback();
}

Expand Down
16 changes: 12 additions & 4 deletions Examples/Scripts/cmi5Wrapper.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
function FinishAU() {
function FinishAU(duration) {
// ToDo List:
// 1) Calculate duration
SendStatement("Terminated");
SendStatement("Terminated",undefined,duration, undefined, returnToLMS);
cmi5Controller.goLMS();
}

function SendStatement(verbName, score, duration, progress) {
function returnToLMS() {
cmi5Controller.goLMS();
}

function SendStatement(verbName, score, duration, progress, callBack) {
// What verb is to be sent?
var verbUpper = verbName.toUpperCase();
var verb;
Expand Down Expand Up @@ -96,7 +100,11 @@ function SendStatement(verbName, score, duration, progress) {
}
}

cmi5Controller.sendStatement(stmt, sentStatement);
if (callBack && typeof callBack === "function") {
cmi5Controller.sendStatement(stmt, callBack);
} else {
cmi5Controller.sendStatement(stmt, sentStatement);
}

} else {
console.log("Invalid verb passed: " + verbName);
Expand Down
2 changes: 2 additions & 0 deletions Examples/Scripts/moment.min.js

Large diffs are not rendered by default.

0 comments on commit 6e20d32

Please sign in to comment.