Skip to content

Commit

Permalink
work-arounds, fixes for page initialization and some clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
misfir3 committed May 3, 2018
1 parent 20e45da commit 6cfefba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
};

Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6cfefba

Please sign in to comment.