Skip to content

Commit

Permalink
Merge pull request #32 from moloko/master
Browse files Browse the repository at this point in the history
updates to scormWrapper
  • Loading branch information
darylhedley committed Sep 30, 2014
2 parents 93de84f + 666290a commit f2b0bc5
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 445 deletions.
3 changes: 2 additions & 1 deletion js/scormData.json → example.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// to be added to course/config.json
{
"_spoor": {
"_tracking": {
Expand All @@ -8,7 +9,7 @@
"_reporting": {
"_comment": "Your options here are 'completed', 'passed', 'failed', and 'incomplete'",
"_onTrackingCriteriaMet": "completed",
"_onQuizFailure": "incomplete"
"_onAssessmentFailure": "incomplete"
}
}
}
166 changes: 55 additions & 111 deletions js/adapt-contrib-spoor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,38 @@ define(function(require) {
},

SCOStart: function() {
var sw = scormWrapper;
if (sw.initialize()) {
sw.setVersion("1.2");
this.set('initialised', true);
var lessonStatus = sw.getStatus().toLowerCase();

if (lessonStatus === "not attempted" || lessonStatus === "unknown" || lessonStatus === undefined) {
sw.setIncomplete();
}
}
/**
* force use of SCORM 1.2 - as some LMSes (SABA, for instance) present both APIs to the SCO and, if given the choice,
* the pipwerks code will automatically select the SCORM 2004 API - which can lead to unexpected behaviour.
* this does obviously mean you'll have to manually change (or just remove) this next line if you want SCORM 2004 output
*/
//TODO allow version to be set via config.json
scormWrapper.setVersion("1.2");

if (scormWrapper.initialize()) {
this.set('initialised', true);
}
},

SCOFinish:function() {
if (!this.get('_SCOFinishCalled')) {
this.set('SCOFinishCalled', true);
scormWrapper.finish();
}
SCOFinish: function() {
if (!this.get('_SCOFinishCalled')) {
this.set('SCOFinishCalled', true);
scormWrapper.finish();
}
},

onDataReady: function() {
this.loadSuspendData();
this.assignSessionId();
this.setupListeners();
this.loadSuspendData();
this.assignSessionId();
this.setupListeners();
},

setupListeners: function() {
Adapt.blocks.on('change:_isComplete', this.onBlockComplete, this);
Adapt.course.on('change:_isComplete', this.onCourseComplete, this);
Adapt.on('assessment:complete', this.onAssessmentComplete, this);
Adapt.on('questionView:complete', this.onQuestionComplete, this);
Adapt.on('questionView:reset', this.onQuestionReset, this);
Adapt.blocks.on('change:_isComplete', this.onBlockComplete, this);
Adapt.course.on('change:_isComplete', this.onCourseComplete, this);
Adapt.on('assessment:complete', this.onAssessmentComplete, this);
Adapt.on('questionView:complete', this.onQuestionComplete, this);
Adapt.on('questionView:reset', this.onQuestionReset, this);
},

loadSuspendData: function() {
Expand All @@ -78,32 +79,35 @@ define(function(require) {
},

onBlockComplete: function(block) {
this.set('lastCompletedBlock', block);
this.set('lastCompletedBlock', block);
this.persistSuspendData();
},

onCourseComplete: function() {
if(Adapt.course.get('_isComplete') === true) {
this.set('_attempts', this.get('_attempts')+1);
}
_.defer(function waitForBlockComplete() {
this.persistSuspendData();
});
_.defer(_.bind(this.checkTrackingCriteriaMet, this));
},

onAssessmentComplete: function(event) {
if(this.data._tracking._shouldSubmitScore) {
scormWrapper.setScore(event.scoreAsPercent, 0, 100);
}
if (event.isPass) {
Adapt.course.set('_isAssessmentPassed', event.isPass);
this.persistSuspendData();
} else {
var onAssessmentFailure = this.data._reporting._onAssessmentFailure;
if (onAssessmentFailure !== "" && onAssessmentFailure !== "incomplete") {
this.setLessonStatus(onAssessmentFailure);
}
}
Adapt.course.set('_isAssessmentPassed', event.isPass)

this.persistSuspendData();

if(this.data._tracking._shouldSubmitScore) {
scormWrapper.setScore(event.scoreAsPercent, 0, 100);
}

if (event.isPass) {
_.defer(_.bind(this.checkTrackingCriteriaMet, this));
} else {
var onAssessmentFailure = this.data._reporting._onAssessmentFailure;
if (onAssessmentFailure !== "") {
this.persistSuspendData();
scormWrapper.setStatus(onAssessmentFailure);
}
}
},

onQuestionComplete: function(questionView) {
Expand All @@ -116,78 +120,18 @@ define(function(require) {
}
},

repopulateCompletionData: function() {
var suspendData = this.get('_suspendData');

if (suspendData.spoor.completion !== "") {
this.restoreProgress(suspendData);
}
},

restoreProgress: function(suspendData) {
if (suspendData.spoor.completion === "courseComplete") {
Adapt.course.set('_isComplete', true);
Adapt.course.setOnChildren('_isComplete', true);
} else {
_.each(this.get('_blockCompletionArray'), function(blockCompletion, blockTrackingId) {
if (blockCompletion === 1) {
this.markBlockAsComplete({block: Adapt.blocks.findWhere({_trackingId: blockTrackingId}), includeChildren: true});
}
}, this);
}
Adapt.course.set('_isAssessmentPassed', suspendData.spoor._isAssessmentPassed);
this.set('_suspendData', suspendData);
this.sendCompletionString();
},

SCOFinish:function() {
if (!this.get('_SCOFinishCalled')) {
this.set('SCOFinishCalled', true);
scormWrapper.finish();
}
},

SCOStart: function() {
// this.set('scormWrapper', this.data._testingMode') ? this.get('testingLMS : ScormWrapper.getInstance());
var sw = scormWrapper;
if (sw.initialize()) {
/**
* force use of version SCORM 1.2 as some LMSes (SABA, for instance) present both APIs and, if given the choice,
* the pipwerks code will automatically select the SCORM 2004 API - which can lead to unexpected behaviour.
*/
sw.setVersion("1.2");
this.set('initialised', true);
}
},
persistSuspendData: function(){
var courseCriteriaMet = this.data._tracking._requireCourseCompleted ? Adapt.course.get('_isComplete') : true,
assessmentCriteriaMet = this.data._tracking._requireAssessmentPassed ? Adapt.course.get('_isAssessmentPassed') : true;

if(courseCriteriaMet && assessmentCriteriaMet) {
this.setLessonStatus(this.data._reporting._onTrackingCriteriaMet);
}
scormWrapper.setSuspendData(JSON.stringify(serialiser.serialise()));
},

setLessonStatus:function(status){
switch (status){
case "incomplete":
scormWrapper.setIncomplete();
break;
case "completed":
scormWrapper.setCompleted();
break;
case "passed":
scormWrapper.setPassed();
break;
case "failed":
scormWrapper.setFailed();
break;
default:
console.warn("cmi.core.lesson_status of " + status + " is not supported.");
break;
}
}
persistSuspendData: function() {
scormWrapper.setSuspendData(JSON.stringify(serialiser.serialise()));
},

checkTrackingCriteriaMet: function() {
var courseCriteriaMet = this.data._tracking._requireCourseCompleted ? Adapt.course.get('_isComplete') : true;
var assessmentCriteriaMet = this.data._tracking._requireAssessmentPassed ? Adapt.course.get('_isAssessmentPassed') : true;

if(courseCriteriaMet && assessmentCriteriaMet) {
scormWrapper.setStatus(this.data._reporting._onTrackingCriteriaMet);
}
}

});
Adapt.on('app:dataReady', function() {
Expand Down
Loading

0 comments on commit f2b0bc5

Please sign in to comment.