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

This commit is contained in:
Jason 2018-05-03 10:25:34 -06:00
parent 20e45da8ae
commit 6cfefba0ee
3 changed files with 20 additions and 45 deletions

View File

@ -73,6 +73,7 @@ define(['jquery',
} }
this.loadLesson = function(name,pageNum) { this.loadLesson = function(name,pageNum) {
if (this.name === name) { if (this.name === name) {
this.listenToOnce(this.lessonHintView, 'hints:showButton', this.onShowHintsButton); this.listenToOnce(this.lessonHintView, 'hints:showButton', this.onShowHintsButton);
this.listenTo(this.lessonHintView, 'hints:hideButton', this.onHideHintsButton); this.listenTo(this.lessonHintView, 'hints:hideButton', this.onHideHintsButton);
@ -83,15 +84,15 @@ define(['jquery',
return; return;
} }
if (pageNum && !this.name) {
//placeholder
}
this.helpsLoaded = {}; this.helpsLoaded = {};
if (typeof(name) === 'undefined' || name === null) { if (typeof(name) === 'undefined' || name === null) {
//TODO: implement lesson not found or return to welcome page? //TODO: implement lesson not found or return to welcome page?
} }
this.lessonContent.loadData({'name':name}); this.lessonContent.loadData({'name':name});
// this.planView = {};
// this.solutionView = {};
// this.sourceView = {};
// this.lessonHintView = {};
this.name = name; this.name = name;
}; };
@ -124,10 +125,7 @@ define(['jquery',
this.helpControlsView = null; this.helpControlsView = null;
this.lessonContentView.model = this.lessonContent; this.lessonContentView.model = this.lessonContent;
this.lessonContentView.render(); this.lessonContentView.render();
//TODO: consider moving hintView as child of lessonContentView ...
//this.planView = new PlanView();
//this.solutionView = new SolutionView();
//this.sourceView = new SourceView();
if (this.lessonHintView) { if (this.lessonHintView) {
this.lessonHintView.stopListening(); this.lessonHintView.stopListening();
this.lessonHintView = null; this.lessonHintView = null;
@ -152,35 +150,6 @@ define(['jquery',
this.helpsLoaded[curHelp.helpElement] = curHelp.value; 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.showHintsView = function() {
this.lessonHintView.render(); this.lessonHintView.render();
if (this.lessonHintView.getHintsCount > 0) { if (this.lessonHintView.getHintsCount > 0) {

View File

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

View File

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