Skip to content

Commit

Permalink
Merge pull request #928 from adaptlearning/bugfix/927
Browse files Browse the repository at this point in the history
bugfix/927: reverse order of completion events
  • Loading branch information
moloko committed Feb 16, 2016
2 parents 3883543 + 059fb44 commit c8e9f8f
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions src/core/js/models/adaptModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ define(function (require) {

initialize: function () {
// Wait until data is loaded before setting up model
Adapt.once('app:dataLoaded', this.setupModel, this);
this.listenToOnce(Adapt, 'app:dataLoaded', this.setupModel);

},

Expand Down Expand Up @@ -50,11 +50,11 @@ define(function (require) {

if (!this.getChildren()) return;

Adapt[this._children].on({
this.listenTo(Adapt[this._children], {
"change:_isReady": this.checkReadyStatus,
"change:_isComplete": this.checkCompletionStatus,
"change:_isInteractionComplete": this.checkInteractionCompletionStatus
}, this);
});

},

Expand Down Expand Up @@ -92,29 +92,35 @@ define(function (require) {
},

checkCompletionStatus: function () {
// Filter children based upon whether they are available
var availableChildren = new Backbone.Collection(this.getChildren().where({_isAvailable: true}));
// Check if any return _isComplete:false
// If not - set this model to _isComplete: true
if (availableChildren.findWhere({_isComplete: false, _isOptional: false})) {
//cascade reset to menu
this.set({_isComplete:false});
return;
}
this.set({_isComplete: true});
//defer to allow other change:_isComplete handlers to fire before cascasing to parent
_.defer(_.bind(function() {
// Filter children based upon whether they are available
var availableChildren = new Backbone.Collection(this.getChildren().where({_isAvailable: true}));
// Check if any return _isComplete:false
// If not - set this model to _isComplete: true
if (availableChildren.findWhere({_isComplete: false, _isOptional: false})) {
//cascade reset to menu
this.set({_isComplete:false});
return;
}
this.set({_isComplete: true});
}, this));
},

checkInteractionCompletionStatus: function () {
// Filter children based upon whether they are available
var availableChildren = new Backbone.Collection(this.getChildren().where({_isAvailable: true}));
// Check if any return _isInteractionComplete:false
// If not - set this model to _isInteractionComplete: true
if (availableChildren.findWhere({_isInteractionComplete: false, _isOptional: false})) {
//cascade reset to menu
this.set({_isInteractionComplete:false});
return;
}
this.set({_isInteractionComplete: true});
//defer to allow other change:_isInteractionComplete handlers to fire before cascasing to parent
_.defer(_.bind(function() {
// Filter children based upon whether they are available
var availableChildren = new Backbone.Collection(this.getChildren().where({_isAvailable: true}));
// Check if any return _isInteractionComplete:false
// If not - set this model to _isInteractionComplete: true
if (availableChildren.findWhere({_isInteractionComplete: false, _isOptional: false})) {
//cascade reset to menu
this.set({_isInteractionComplete:false});
return;
}
this.set({_isInteractionComplete: true});
}, this));
},

findAncestor: function (ancestors) {
Expand Down

0 comments on commit c8e9f8f

Please sign in to comment.