work-arounds, fixes for page initialization and some clean-up

This commit is contained in:
Jason 2018-05-03 10:25:34 -06:00 committed by Nanne Baars
parent ac1b9e8311
commit 91d9db5f80
3 changed files with 20 additions and 45 deletions

View File

@ -73,6 +73,7 @@ define(['jquery',
}
this.loadLesson = function(name,pageNum) {
if (this.name === name) {
this.listenToOnce(this.lessonHintView, 'hints:showButton', this.onShowHintsButton);
this.listenTo(this.lessonHintView, 'hints:hideButton', this.onHideHintsButton);
@ -83,15 +84,15 @@ define(['jquery',
return;
}
if (pageNum && !this.name) {
//placeholder
}
this.helpsLoaded = {};
if (typeof(name) === 'undefined' || name === null) {
//TODO: implement lesson not found or return to welcome page?
}
this.lessonContent.loadData({'name':name});
// this.planView = {};
// this.solutionView = {};
// this.sourceView = {};
// this.lessonHintView = {};
this.name = name;
};
@ -124,10 +125,7 @@ define(['jquery',
this.helpControlsView = null;
this.lessonContentView.model = this.lessonContent;
this.lessonContentView.render();
//this.planView = new PlanView();
//this.solutionView = new SolutionView();
//this.sourceView = new SourceView();
//TODO: consider moving hintView as child of lessonContentView ...
if (this.lessonHintView) {
this.lessonHintView.stopListening();
this.lessonHintView = null;
@ -152,35 +150,6 @@ define(['jquery',
this.helpsLoaded[curHelp.helpElement] = curHelp.value;
};
// this.hideShowHelps = function(showHelp) {
// var showId = '#lesson-' + showHelp + '-row';
// var contentId = '#lesson-' + showHelp + '-content';
// $('.lesson-help').not(showId).hide();
// if (!showId) {
// return;
// }
//
// if ($(showId).is(':visible')) {
// $(showId).hide();
// return;
// } else {
// //TODO: move individual .html operations into individual help views
// switch(showHelp) {
// case 'plan':
// $(contentId).html(this.planView.model.get('content'));
// break;
// case 'solution':
// $(showId).html(this.solutionView.model.get('content'));
// break;
// case 'source':
// $(contentId).html('<pre>' + this.sourceView.model.get('content') + '</pre>');
// break;
// }
// $(showId).show();
// GoatUtils.scrollToHelp()
// }
// };
this.showHintsView = function() {
this.lessonHintView.render();
if (this.lessonHintView.getHintsCount > 0) {

View File

@ -59,7 +59,7 @@ define(['jquery',
var currentPage = (!isNaN(startPageNum) && startPageNum && startPageNum < this.$contentPages) ? startPageNum : 0;
//init views & pagination
this.showCurContentPage(currentPage);
this.paginationControlView = new PaginationControlView(this.$contentPages,this.model.get('lessonUrl'));
this.paginationControlView = new PaginationControlView(this.$contentPages,this.model.get('lessonUrl'),startPageNum);
},
updatePagination: function() {
@ -187,13 +187,19 @@ define(['jquery',
return endpoints;
},
onNavToPage: function(pageNum) {
var assignmentPaths = this.findAssigmentEndpointsOnPage(pageNum);
this.trigger('endpoints:filtered',assignmentPaths);
},
navToPage: function (pageNum) {
this.paginationControlView.setCurrentPage(pageNum);//provides validation
this.showCurContentPage(this.paginationControlView.currentPage);
this.paginationControlView.render();
this.paginationControlView.hideShowNavButtons();
var assignmentPaths = this.findAssigmentEndpointsOnPage(pageNum);
this.trigger('endpoints:filtered',assignmentPaths);
this.onNavToPage(pageNum);
//var assignmentPaths = this.findAssigmentEndpointsOnPage(pageNum);
//this.trigger('endpoints:filtered',assignmentPaths);
},
/* for testing */

View File

@ -12,14 +12,14 @@ define(['jquery',
template: PaginationTemplate,
el: '#lesson-page-controls',
initialize: function ($contentPages,baseLessonUrl) {
initialize: function ($contentPages,baseLessonUrl,initPageNum) {
this.$contentPages = $contentPages;
this.collection = new LessonOverviewCollection();
this.listenTo(this.collection, 'reset', this.render);
this.numPages = this.$contentPages.length;
this.baseUrl = baseLessonUrl;
this.collection.fetch({reset:true});
this.initPagination();
this.initPagination(initPageNum);
//this.render();
},
@ -117,9 +117,9 @@ define(['jquery',
$('span.glyphicon-class.glyphicon.glyphicon-circle-arrow-right.show-next-page').hide();
},
initPagination: function() {
//track pagination state in this view ... start at 0
this.currentPage = 0;
initPagination: function(initPageNum) {
//track pagination state in this view ... start at 0 .. unless a pageNum was provided
this.currentPage = !initPageNum ? 0 : initPageNum;
},
setCurrentPage: function (pageNum) {