Skip to content

Commit

Permalink
Merge pull request #951 from adaptlearning/issue/910
Browse files Browse the repository at this point in the history
issue/910: added requireCompletionOf: X
  • Loading branch information
moloko committed Mar 7, 2016
2 parents 6c5b5b4 + f7999f2 commit a9ab8c7
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions src/core/js/models/adaptModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define(function (require) {
_canReset: false,
_isComplete: false,
_isInteractionComplete: false,
_requireCompletionOf: -1,
_isEnabled: true,
_isResetOnRevisit: false,
_isAvailable: true,
Expand Down Expand Up @@ -96,14 +97,22 @@ define(function (require) {
_.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;

var isComplete = false;

//number of mandatory children that must be complete or -1 for all
var requireCompletionOf = this.get("_requireCompletionOf");

if (requireCompletionOf === -1) {
// Check if any return _isComplete:false
// If not - set this model to _isComplete: true
isComplete = (availableChildren.findWhere({_isComplete: false, _isOptional: false}) === undefined);
} else {
isComplete = (availableChildren.where({_isComplete: true, _isOptional: false}).length >= requireCompletionOf );
}
this.set({_isComplete: true});

this.set({_isComplete:isComplete});

}, this));
},

Expand All @@ -112,14 +121,22 @@ define(function (require) {
_.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;

var isInteractionComplete = false;

//number of mandatory children that must be complete or -1 for all
var requireCompletionOf = this.get("_requireCompletionOf")

if (requireCompletionOf === -1) {
// Check if any return _isInteractionComplete:false
// If not - set this model to _isInteractionComplete: true
isInteractionComplete = (availableChildren.findWhere({_isInteractionComplete: false, _isOptional: false}) === undefined);
} else {
isInteractionComplete = (availableChildren.where({_isInteractionComplete: true, _isOptional: false}).length >= requireCompletionOf);
}
this.set({_isInteractionComplete: true});

this.set({_isInteractionComplete:isInteractionComplete});

}, this));
},

Expand Down

0 comments on commit a9ab8c7

Please sign in to comment.