diff --git a/bower.json b/bower.json index 44c4015..9e86576 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "adapt-contrib-narrative", "version": "7.8.0", - "framework": ">=5.31.2", + "framework": ">=5.35.6", "homepage": "https://github.com/adaptlearning/adapt-contrib-narrative", "bugs": "https://github.com/adaptlearning/adapt-contrib-narrative/issues", "component": "narrative", diff --git a/js/NarrativeModel.js b/js/NarrativeModel.js index 4b45ec0..80adfd7 100644 --- a/js/NarrativeModel.js +++ b/js/NarrativeModel.js @@ -1,3 +1,24 @@ import ItemsComponentModel from 'core/js/models/itemsComponentModel'; -export default class NarrativeModel extends ItemsComponentModel {} +export default class NarrativeModel extends ItemsComponentModel { + restoreUserAnswers() { + const numberArray = this.get('_userAnswer'); + if (!numberArray) return; + const children = this.getChildren(); + const shouldRestoreActiveItem = (numberArray.length > children.length); + if (shouldRestoreActiveItem) { + const activeItemIndex = numberArray.pop(); + this.setActiveItem(activeItemIndex); + } + children.forEach(child => child.set('_isVisited', Boolean(numberArray[child.get('_index')]))); + } + + storeUserAnswer() { + const items = this.getChildren().slice(0); + items.sort((a, b) => a.get('_index') - b.get('_index')); + const numberArray = items.map(child => child.get('_isVisited') ? 1 : 0); + const activeItem = this.getActiveItem(); + if (activeItem) numberArray.push(activeItem.get('_index')); + this.set('_userAnswer', numberArray); + } +} diff --git a/package.json b/package.json index 44c4015..9e86576 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "adapt-contrib-narrative", "version": "7.8.0", - "framework": ">=5.31.2", + "framework": ">=5.35.6", "homepage": "https://github.com/adaptlearning/adapt-contrib-narrative", "bugs": "https://github.com/adaptlearning/adapt-contrib-narrative/issues", "component": "narrative",