From 059fb44be558290fda433eeb60ab832561167b6f Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Sun, 31 Jan 2016 14:12:56 +0000 Subject: [PATCH] bugfix/927: reverse order of completion events --- src/core/js/models/adaptModel.js | 52 ++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/core/js/models/adaptModel.js b/src/core/js/models/adaptModel.js index cb105e7a5..55ac1d643 100644 --- a/src/core/js/models/adaptModel.js +++ b/src/core/js/models/adaptModel.js @@ -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); }, @@ -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); + }); }, @@ -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) {