Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/927: reverse order of completion events #928

Merged
merged 1 commit into from
Feb 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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