hints view fix. still a redundant call issue, but logging separately

This commit is contained in:
Jason White
2017-05-10 13:07:29 +01:00
parent 194a327ad5
commit 118079233d
5 changed files with 65 additions and 35 deletions

View File

@ -12,18 +12,14 @@ function($,_,Backbone) {
this.hasPlan = options.hasPlan;
this.hasSolution = options.hasSolution;
this.hasSource = options.hasSource;
var self = this;
Backbone.on('navigatedToPage', function(nav) {
self.showHideHintsButton(nav)
});
},
showHideHintsButton: function(nav) {
if (typeof nav['assignmentPath'] !== 'undefined') {
this.$el.find('#show-hints-button').unbind().on('click',this.showHints.bind(this)).show();
} else {
$('#show-hints-button').hide();
}
showHintsButton: function(nav) {
this.$el.find('#show-hints-button').unbind().on('click',this.showHints.bind(this)).show();
},
hideHintsButton: function(){
$('#show-hints-button').hide();
},
render:function(title) {

View File

@ -19,8 +19,10 @@ function($,
this.listenTo(this.collection,'loaded',this.onModelLoaded);
this.hideHints();
var self = this;
// different way to do this?
Backbone.on('navigatedToPage', function(nav){
self.selectHints(nav)
self.selectHints(nav);
// end event delegation??
});
},
@ -61,14 +63,25 @@ function($,
*
* @param nav the json structure for navigating
*/
selectHints: function(nav) {
this.curHint = 0;
var assignmentPath = nav['assignmentPath'];
if (assignmentPath != null) {
this.hintsToShow = this.collection.getHintsForAssignment(assignmentPath);
filterHints: function(endpoints) {
this.hintsToShow = [];
_.each(endpoints, this.filterHint, this);
if (this.hintsToShow.length > 0) {
this.trigger('hints:showButton');
} else {
this.hintsToShow = new Array();
}
this.trigger('hints:hideButton');
}
},
filterHint: function(endpoint) {
var self = this;
_.each(this.collection.models, function(hintModel) {
if (endpoint.indexOf(hintModel.get('assignmentPath')) > -1) {
self.hintsToShow.push(hintModel.get('hint'));
}
});
console.log(this.hintsToShow);
},
onModelLoaded: function() {
@ -97,7 +110,7 @@ function($,
if(this.hintsToShow.length == 0) {
// this.hideHints();
} else {
this.$el.find('#lesson-hint-content').html(polyglot.t(this.hintsToShow[curHint].get('hint')));
this.$el.find('#lesson-hint-content').html(polyglot.t(this.hintsToShow[curHint]));
}
},

View File

@ -153,13 +153,15 @@ define(['jquery',
this.$el.find(this.$contentPages[pageNum]).show();
},
findAssigmentEndpointOnPage: function(pageNumber) {
var contentPage = this.$contentPages[this.currentPage];
var form = $('form.attack-form', contentPage);
var action = form.attr('action')
if (action !== undefined) {
return action;
findAssigmentEndpointsOnPage: function(pageNumber) {
var contentPage = this.$contentPages[pageNumber];
var endpoints = []; //going to assume uniqueness since these are assignments
var pageForms = $(contentPage).find('form.attack-form');
for (var i=0; i<pageForms.length; i++) {
endpoints.push(pageForms[i].action);
}
console.log(endpoints);
return endpoints;
},
navToPage: function (pageNum) {
@ -167,8 +169,8 @@ define(['jquery',
this.showCurContentPage(this.paginationControlView.currentPage);
this.paginationControlView.render();
this.paginationControlView.hideShowNavButtons();
var assignmentPath = this.findAssigmentEndpointOnPage(pageNum);
Backbone.trigger('navigatedToPage',{'pageNumber':pageNum, 'assignmentPath' : assignmentPath});
var assignmentPaths = this.findAssigmentEndpointsOnPage(pageNum);
this.trigger('endpoints:filtered',assignmentPaths);
},
/* for testing */