diff --git a/js/statements/abstractStatementModel.js b/js/statements/abstractStatementModel.js index fb412d2..06d8f4c 100644 --- a/js/statements/abstractStatementModel.js +++ b/js/statements/abstractStatementModel.js @@ -1,176 +1,176 @@ -define([ - 'core/js/adapt', - '../utils' -], function(Adapt, Utils) { +import Adapt from "core/js/adapt"; +import Utils from "../utils"; - var AbstractStatementModel = Backbone.Model.extend({ +export default class AbstractStatementModel extends Backbone.Model { - defaults: { + defaults() { + return { recipeLang: 'en', lang: 'en', activityId: null, registration: null, revision: null, + contentRelease: null, actor: null, contextActivities: { grouping: [] } - }, + }; + } - getData: function(model, state) { - const statement = new ADL.XAPIStatement(); - statement.id = ADL.ruuid(); - statement.actor = new ADL.XAPIStatement.Agent(this.get('actor')); - statement.verb = this.getVerb(model); - statement.object = this.getObject(model); - statement.context = this.getContext(model, state); - statement.timestamp = Utils.getTimestamp(); + getData(model, state) { + const statement = new ADL.XAPIStatement(); + statement.id = ADL.ruuid(); + statement.actor = new ADL.XAPIStatement.Agent(this.get('actor')); + statement.verb = this.getVerb(model); + statement.object = this.getObject(model); + statement.context = this.getContext(model, state); + statement.timestamp = Utils.getTimestamp(); - return statement; - }, + return statement; + } - getVerb: function(model) { - // intentionally empty to be overriden by subclass - }, + getVerb(model) { + // intentionally empty to be overriden by subclass + } - getActivityType: function(model) { - // intentionally empty to be overriden by subclass - }, + getActivityType(model) { + // intentionally empty to be overriden by subclass + } - getObject: function(model) { - const object = new ADL.XAPIStatement.Activity(this.getUniqueIri(model)); + getObject(model) { + const object = new ADL.XAPIStatement.Activity(this.getUniqueIri(model)); - const definition = { - type: this.getActivityType(model), - name: this.getName(model) - }; + const definition = { + type: this.getActivityType(model), + name: this.getName(model) + }; - const extensions = this.getObjectExtensions(model); + const extensions = this.getObjectExtensions(model); - if (!(_.isEmpty(extensions))) definition.extensions = extensions; + if (!(_.isEmpty(extensions))) definition.extensions = extensions; - object.definition = definition; + object.definition = definition; - return object; - }, + return object; + } - getObjectExtensions: function(model) { - const extensions = {}; - const type = model.get('_type'); + getObjectExtensions(model) { + const extensions = {}; + const type = model.get('_type'); - if (type) extensions['https://adaptlearning.org/xapi/extension/model'] = type; + if (type) extensions['https://adaptlearning.org/xapi/extension/model'] = type; - return extensions; - }, + return extensions; + } - getContext: function(model, state) { - const context = { - contextActivities: this.getContextActivities(model), - extensions: this.getContextExtensions(model, state), - language: this.get('lang') - }; + getContext(model, state) { + const context = { + contextActivities: this.getContextActivities(model), + extensions: this.getContextExtensions(model, state), + language: this.get('lang') + }; - const registration = this.get('registration'); - if (registration) context.registration = registration; + const registration = this.get('registration'); + if (registration) context.registration = registration; - const revision = this.get('revision'); - if (revision) context.revision = revision; + const revision = this.get('revision'); + if (revision) context.revision = revision; - return context; - }, + return context; + } - getContextActivities: function(model) { - const contextActivities = _.clone(this.get('contextActivities')); - contextActivities.grouping = this.getContextActivitiesGrouping(model); + getContextActivities(model) { + const contextActivities = _.clone(this.get('contextActivities')); + contextActivities.grouping = this.getContextActivitiesGrouping(model); - return contextActivities; - }, + return contextActivities; + } - getContextActivitiesGrouping: function(model) { - const grouping = this.get('contextActivities').grouping.slice(); + getContextActivitiesGrouping(model) { + const grouping = this.get('contextActivities').grouping.slice(); - grouping.push(this.getCourseContextActivity()); + grouping.push(this.getCourseContextActivity()); - const modelType = model.get('_type'); - - if (modelType && modelType !== 'course') { - grouping.push.apply(grouping, this.getContentObjectsContextActivities(model)); - } + const modelType = model.get('_type'); - return grouping; - }, - - getCourseContextActivity: function() { - const object = AbstractStatementModel.prototype.getObject.call(this, Adapt.course); - object.definition.type = ADL.activityTypes.course; + if (modelType && modelType !== 'course') { + grouping.push.apply(grouping, this.getContentObjectsContextActivities(model)); + } - return object; - }, + return grouping; + } - getContentObjectsContextActivities: function(model) { - const contentObjects = model.getAncestorModels(true).filter(function(model) { - const modelType = model.get('_type'); - const isContentObject = modelType === 'menu' || modelType === 'page'; + getCourseContextActivity() { + const object = AbstractStatementModel.prototype.getObject.call(this, Adapt.course); + object.definition.type = ADL.activityTypes.course; - if (isContentObject) return model; - }); + return object; + } - contentObjects.reverse(); + getContentObjectsContextActivities(model) { + const contentObjects = model.getAncestorModels(true).filter(function(model) { + const modelType = model.get('_type'); + const isContentObject = modelType === 'menu' || modelType === 'page'; - const activities = []; + if (isContentObject) return model; + }); - contentObjects.forEach(function(model) { - activities.push(this.getContentObjectContextActivity(model)); - }, this); + contentObjects.reverse(); - return activities; - }, + const activities = []; - getContentObjectContextActivity: function(model) { - const modelType = model.get('_type'); - const isContentObject = modelType === 'menu' || modelType === 'page'; - const contentObject = (isContentObject) ? model : model.findAncestor('contentObjects'); - const object = AbstractStatementModel.prototype.getObject.call(this, contentObject); - object.definition.type = ADL.activityTypes.module; + contentObjects.forEach(function(model) { + activities.push(this.getContentObjectContextActivity(model)); + }, this); - return object; - }, + return activities; + } - getContextExtensions: function(model, state) { - const buildConfig = Adapt.build; - const frameworkVersion = (buildConfig) ? buildConfig.get('package').version : '<3.0.0'; + getContentObjectContextActivity(model) { + const modelType = model.get('_type'); + const isContentObject = modelType === 'menu' || modelType === 'page'; + const contentObject = (isContentObject) ? model : model.findAncestor('contentObjects'); + const object = AbstractStatementModel.prototype.getObject.call(this, contentObject); + object.definition.type = ADL.activityTypes.module; - const extensions = { - 'https://adaptlearning.org/xapi/extension/framework': 'Adapt', - 'https://adaptlearning.org/xapi/extension/framework_version': frameworkVersion - }; + return object; + } - return extensions; - }, + getContextExtensions(model, state) { + const buildConfig = Adapt.build; + const frameworkVersion = (buildConfig) ? buildConfig.get('package').version : '<3.0.0'; + const specificationRevision = this.get('revision'); + const contentRelease = this.get('contentRelease'); - getName: function(model) { - const name = {}; - name[this.get('lang')] = model.get('title') || model.get('displayTitle'); + const extensions = { + 'https://adaptlearning.org/xapi/extension/framework': 'Adapt', + 'https://adaptlearning.org/xapi/extension/framework_version': frameworkVersion, + 'https://adaptlearning.org/xapi/extension/specification_revision': specificationRevision, + 'https://adaptlearning.org/xapi/extension/content_release': contentRelease + }; - return name; - }, + return extensions; + } - getUniqueIri: function(model) { - let iri = this.get('activityId'); + getName(model) { + const name = {}; + name[this.get('lang')] = model.get('title') || model.get('displayTitle'); - if (model && model.get('_type') !== 'course') { - iri += '/' + model.get('_id'); - } + return name; + } - return iri; - }, + getUniqueIri(model) { + let iri = this.get('activityId'); - getISO8601Duration: function(milliseconds) { - return Utils.getISO8601Duration(milliseconds); + if (model && model.get('_type') !== 'course') { + iri += '/' + model.get('_id'); } - }); - - return AbstractStatementModel; + return iri; + } -}); + getISO8601Duration(milliseconds) { + return Utils.getISO8601Duration(milliseconds); + } +}