-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ea9400e
commit d6864c3
Showing
51 changed files
with
4,380 additions
and
1,916 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,173 +1,173 @@ | ||
define([ | ||
'core/js/adapt', | ||
'./offlineStorage', | ||
'./errorNotificationModel', | ||
'./launchModel', | ||
'./statementModel', | ||
'./stateModel', | ||
'libraries/xapiwrapper.min', | ||
'libraries/url-polyfill', | ||
'libraries/fetch-polyfill', | ||
'libraries/promise-polyfill.min' | ||
'core/js/adapt', | ||
'./offlineStorage', | ||
'./errorNotificationModel', | ||
'./launchModel', | ||
'./statementModel', | ||
'./stateModel', | ||
'libraries/xapiwrapper.min', | ||
'libraries/url-polyfill', | ||
'libraries/fetch-polyfill', | ||
'libraries/promise-polyfill.min' | ||
], function(Adapt, OfflineStorage, ErrorNotificationModel, LaunchModel, StatementModel, StateModel) { | ||
|
||
var xAPI = Backbone.Controller.extend({ | ||
const xAPI = Backbone.Controller.extend({ | ||
|
||
_isInitialized: false, | ||
_config: null, | ||
_activityId: null, | ||
_restoredLanguage: null, | ||
_currentLanguage: null, | ||
errorNotificationModel: null, | ||
launchModel: null, | ||
statementModel: null, | ||
stateModel: null, | ||
|
||
initialize: function() { | ||
this.listenToOnce(Adapt, 'offlineStorage:prepare', this.onPrepareOfflineStorage); | ||
}, | ||
|
||
initializeErrorNotification: function() { | ||
var config = this._config._errors; | ||
|
||
this.errorNotificationModel = new ErrorNotificationModel(config); | ||
}, | ||
_isInitialized: false, | ||
_config: null, | ||
_activityId: null, | ||
_restoredLanguage: null, | ||
_currentLanguage: null, | ||
errorNotificationModel: null, | ||
launchModel: null, | ||
statementModel: null, | ||
stateModel: null, | ||
|
||
initialize: function() { | ||
this.listenToOnce(Adapt, 'offlineStorage:prepare', this.onPrepareOfflineStorage); | ||
}, | ||
|
||
initializeErrorNotification: function() { | ||
const config = this._config._errors; | ||
|
||
this.errorNotificationModel = new ErrorNotificationModel(config); | ||
}, | ||
|
||
initializeLaunch: function() { | ||
this.listenToOnce(Adapt, { | ||
'xapi:launchInitialized': this.onLaunchInitialized, | ||
'xapi:launchFailed': this.onLaunchFailed | ||
}); | ||
initializeLaunch: function() { | ||
this.listenToOnce(Adapt, { | ||
'xapi:launchInitialized': this.onLaunchInitialized, | ||
'xapi:launchFailed': this.onLaunchFailed | ||
}); | ||
|
||
this.launchModel = new LaunchModel(); | ||
}, | ||
this.launchModel = new LaunchModel(); | ||
}, | ||
|
||
initializeState: function() { | ||
this.listenTo(Adapt, 'xapi:stateLoaded', this.onStateLoaded); | ||
initializeState: function() { | ||
this.listenTo(Adapt, 'xapi:stateLoaded', this.onStateLoaded); | ||
|
||
var config = { | ||
activityId: this.getActivityId(), | ||
registration: this.launchModel.get('registration'), | ||
actor: this.launchModel.get('actor') | ||
}; | ||
const config = { | ||
activityId: this.getActivityId(), | ||
registration: this.launchModel.get('registration'), | ||
actor: this.launchModel.get('actor') | ||
}; | ||
|
||
this.stateModel = new StateModel(config, { | ||
wrapper: this.launchModel.getWrapper(), | ||
_tracking: this._config._tracking | ||
}); | ||
}, | ||
this.stateModel = new StateModel(config, { | ||
wrapper: this.launchModel.getWrapper(), | ||
_tracking: this._config._tracking | ||
}); | ||
}, | ||
|
||
initializeStatement: function() { | ||
var config = { | ||
activityId: this.getActivityId(), | ||
registration: this.launchModel.get('registration'), | ||
revision: this._config._revision || null, | ||
actor: this.launchModel.get('actor'), | ||
contextActivities: this.launchModel.get('contextActivities') | ||
}; | ||
initializeStatement: function() { | ||
const config = { | ||
activityId: this.getActivityId(), | ||
registration: this.launchModel.get('registration'), | ||
revision: this._config._revision || null, | ||
actor: this.launchModel.get('actor'), | ||
contextActivities: this.launchModel.get('contextActivities') | ||
}; | ||
|
||
this.statementModel = new StatementModel(config, { | ||
wrapper: this.launchModel.getWrapper(), | ||
_tracking: this._config._tracking | ||
}); | ||
}, | ||
this.statementModel = new StatementModel(config, { | ||
wrapper: this.launchModel.getWrapper(), | ||
_tracking: this._config._tracking | ||
}); | ||
}, | ||
|
||
getActivityId: function() { | ||
if (this._activityId) return this._activityId; | ||
getActivityId: function() { | ||
if (this._activityId) return this._activityId; | ||
|
||
var lrs = this.launchModel.getWrapper().lrs; | ||
// if using cmi5 the activityId MUST come from the query string for "cmi.defined" statements | ||
var activityId = lrs.activityId || lrs.activity_id || this._config._activityId; | ||
const lrs = this.launchModel.getWrapper().lrs; | ||
// if using cmi5 the activityId MUST come from the query string for "cmi.defined" statements | ||
let activityId = lrs.activityId || lrs.activity_id || this._config._activityId; | ||
|
||
// @todo: should activityId be derived from URL? Would suggest not as the domain may not be controlled by the author/vendor | ||
if (!activityId) Adapt.trigger('xapi:activityIdError'); | ||
// @todo: should activityId be derived from URL? Would suggest not as the domain may not be controlled by the author/vendor | ||
if (!activityId) Adapt.trigger('xapi:activityIdError'); | ||
|
||
// remove trailing slash if included | ||
activityId = activityId.replace(/\/?$/, ""); | ||
// remove trailing slash if included | ||
activityId = activityId.replace(/\/?$/, ''); | ||
|
||
return activityId; | ||
}, | ||
return activityId; | ||
}, | ||
|
||
// @todo: offlineStorage conflict with adapt-contrib-spoor | ||
onPrepareOfflineStorage: function() { | ||
this._config = Adapt.config.get('_xapi'); | ||
// @todo: offlineStorage conflict with adapt-contrib-spoor | ||
onPrepareOfflineStorage: function() { | ||
this._config = Adapt.config.get('_xapi'); | ||
|
||
if (this._config && this._config._isEnabled) { | ||
Adapt.wait.begin(); | ||
if (this._config && this._config._isEnabled) { | ||
Adapt.wait.begin(); | ||
|
||
Adapt.offlineStorage.initialize(OfflineStorage); | ||
Adapt.offlineStorage.initialize(OfflineStorage); | ||
|
||
this.initializeErrorNotification(); | ||
this.initializeLaunch(); | ||
} | ||
}, | ||
this.initializeErrorNotification(); | ||
this.initializeLaunch(); | ||
} | ||
}, | ||
|
||
onLaunchInitialized: function() { | ||
this._activityId = this.getActivityId(); | ||
onLaunchInitialized: function() { | ||
this._activityId = this.getActivityId(); | ||
|
||
if (!this._activityId) { | ||
this.onLaunchFailed(); | ||
if (!this._activityId) { | ||
this.onLaunchFailed(); | ||
|
||
return; | ||
} | ||
return; | ||
} | ||
|
||
this.listenToOnce(Adapt, { | ||
'offlineStorage:ready': this.onOfflineStorageReady, | ||
'app:dataLoaded': this.onDataLoaded, | ||
'adapt:initialize': this.onAdaptInitialize | ||
}); | ||
this.listenToOnce(Adapt, { | ||
'offlineStorage:ready': this.onOfflineStorageReady, | ||
'app:dataLoaded': this.onDataLoaded, | ||
'adapt:initialize': this.onAdaptInitialize | ||
}); | ||
|
||
this.listenTo(Adapt, { | ||
'app:languageChanged': this.onLanguageChanged | ||
}); | ||
this.listenTo(Adapt, { | ||
'app:languageChanged': this.onLanguageChanged | ||
}); | ||
|
||
this.initializeState(); | ||
this.initializeStatement(); | ||
}, | ||
this.initializeState(); | ||
this.initializeStatement(); | ||
}, | ||
|
||
onLaunchFailed: function() { | ||
Adapt.wait.end(); | ||
onLaunchFailed: function() { | ||
Adapt.wait.end(); | ||
|
||
Adapt.offlineStorage.setReadyStatus(); | ||
}, | ||
Adapt.offlineStorage.setReadyStatus(); | ||
}, | ||
|
||
onOfflineStorageReady: function() { | ||
this._restoredLanguage = Adapt.offlineStorage.get('lang'); | ||
}, | ||
onOfflineStorageReady: function() { | ||
this._restoredLanguage = Adapt.offlineStorage.get('lang'); | ||
}, | ||
|
||
onLanguageChanged: function(lang) { | ||
var languageConfig = Adapt.config.get('_languagePicker'); | ||
onLanguageChanged: function(lang) { | ||
const languageConfig = Adapt.config.get('_languagePicker'); | ||
|
||
if (languageConfig && languageConfig._isEnabled && this._restoredLanguage !== lang && this._currentLanguage !== lang) { | ||
// only reset if language has changed since the course was started - not neccessary before | ||
var resetState = this._isInitialized && !languageConfig._restoreStateOnLanguageChange; | ||
if (languageConfig && languageConfig._isEnabled && this._restoredLanguage !== lang && this._currentLanguage !== lang) { | ||
// only reset if language has changed since the course was started - not neccessary before | ||
const resetState = this._isInitialized && !languageConfig._restoreStateOnLanguageChange; | ||
|
||
// @todo: only send when via a user selection? If `"_showOnCourseLoad": false`, this will still be triggered | ||
Adapt.trigger('xapi:languageChanged', lang, resetState); | ||
} | ||
// @todo: only send when via a user selection? If `"_showOnCourseLoad": false`, this will still be triggered | ||
Adapt.trigger('xapi:languageChanged', lang, resetState); | ||
} | ||
|
||
this._restoredLanguage = null; | ||
this._currentLanguage = lang; | ||
}, | ||
this._restoredLanguage = null; | ||
this._currentLanguage = lang; | ||
}, | ||
|
||
onStateLoaded: function() { | ||
Adapt.wait.end(); | ||
onStateLoaded: function() { | ||
Adapt.wait.end(); | ||
|
||
Adapt.offlineStorage.setReadyStatus(); | ||
}, | ||
Adapt.offlineStorage.setReadyStatus(); | ||
}, | ||
|
||
onDataLoaded: function() { | ||
var globals = Adapt.course.get('_globals'); | ||
if (!globals._learnerInfo) globals._learnerInfo = {}; | ||
globals._learnerInfo = Adapt.offlineStorage.get('learnerinfo'); | ||
}, | ||
onDataLoaded: function() { | ||
const globals = Adapt.course.get('_globals'); | ||
if (!globals._learnerInfo) globals._learnerInfo = {}; | ||
globals._learnerInfo = Adapt.offlineStorage.get('learnerinfo'); | ||
}, | ||
|
||
onAdaptInitialize: function() { | ||
this._isInitialized = true; | ||
} | ||
onAdaptInitialize: function() { | ||
this._isInitialized = true; | ||
} | ||
|
||
}); | ||
}); | ||
|
||
return new xAPI(); | ||
return new xAPI(); | ||
|
||
}); |
Oops, something went wrong.