diff --git a/webgoat-container/src/main/resources/static/js/goatApp/controller/LessonController.js b/webgoat-container/src/main/resources/static/js/goatApp/controller/LessonController.js index 3f77f1f54..c12544765 100644 --- a/webgoat-container/src/main/resources/static/js/goatApp/controller/LessonController.js +++ b/webgoat-container/src/main/resources/static/js/goatApp/controller/LessonController.js @@ -61,7 +61,12 @@ define(['jquery', this.menuButtonView = new MenuButtonView(); }; - this.loadLesson = function(name) { + this.loadLesson = function(name,pageNum) { + if (this.name === name) { + this.lessonContentView.navToPage(pageNum) + return; + } + this.titleView = new TitleView(); this.helpsLoaded = {}; if (typeof(name) === 'undefined' || name === null) { @@ -195,6 +200,14 @@ define(['jquery', }); }; + this.testHandler = function(param) { + console.log('test handler'); + this.lessonContentView.showTestParam(param); + }; + }; + + + return Controller; }); diff --git a/webgoat-container/src/main/resources/static/js/goatApp/view/GoatRouter.js b/webgoat-container/src/main/resources/static/js/goatApp/view/GoatRouter.js index 41301bb1a..ee17193bc 100644 --- a/webgoat-container/src/main/resources/static/js/goatApp/view/GoatRouter.js +++ b/webgoat-container/src/main/resources/static/js/goatApp/view/GoatRouter.js @@ -22,11 +22,12 @@ define(['jquery', var GoatAppRouter = Backbone.Router.extend({ routes: { 'welcome':'welcomeRoute', - 'lesson/:name':'lessonRoute' - //'attack/:scr/:menu/:stage':'attackRoute', - //'attack/:scr/:menu/*stage/:num':'attackRoute', + 'lesson/:name':'lessonRoute', + 'lesson/:name/:pageNum':'lessonPageRoute', + 'test/:param':'testRoute' }, + lessonController: new LessonController({ lessonContentView: lessonContentView }), @@ -41,14 +42,17 @@ define(['jquery', // this.menuController.initMenu(); webgoat = {}; webgoat.customjs = {}; - webgoat.customjs.jquery = $; + webgoat.customjs.jquery = $; //passing jquery into custom js scope ... still klunky, but works for now -// goatRouter.on('route:attackRoute', function(scr,menu,stage,num) { -// this.lessonController.loadLesson(scr,menu,stage,num); -// this.menuController.updateMenu(scr,menu); -// }); goatRouter.on('route:lessonRoute', function(name) { - this.lessonController.loadLesson(name); + this.lessonController.loadLesson(name,0); + //TODO - update menu code from below + this.menuController.updateMenu(name); + }); + + goatRouter.on('route:lessonPageRoute', function(name,pageNum) { + pageNum = (_.isNumber(parseInt(pageNum))) ? parseInt(pageNum) : 0; + this.lessonController.loadLesson(name,pageNum); //TODO - update menu code from below this.menuController.updateMenu(name); }); @@ -56,6 +60,15 @@ define(['jquery', goatRouter.on('route:welcomeRoute', function() { this.lessonController.loadWelcome(); }); + + goatRouter.on('route:welcomeRoute', function() { + this.lessonController.loadWelcome(); + }); + + goatRouter.on('route:testRoute', function(param) { + this.lessonController.testHandler(param); + }); + goatRouter.on("route", function(route, params) {}); Backbone.history.start(); diff --git a/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js b/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js index 7f69e36e5..2ebb25d80 100644 --- a/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js +++ b/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js @@ -46,6 +46,14 @@ define(['jquery', } }, + setCurrentPage: function (pageNum) { + this.currentPage = (_.isNumber(pageNum) && pageNum < this.numPages) ? pageNum : 0; + }, + + getCurrentPage: function () { + return this.currentPage; + }, + makeFormsAjax: function () { this.$form = $('form.attack-form'); // turn off standard submit @@ -79,7 +87,7 @@ define(['jquery', return false; }, - onSuccessResponse: function(data) { + onSuccessResponse: function(data) { console.log(data); this.renderFeedback(data.feedback); @@ -88,14 +96,14 @@ define(['jquery', this.trigger('lesson:complete'); } return false; - }, + }, - onErrorResponse: function (a,b,c) { + onErrorResponse: function (a,b,c) { console.error(a); console.error(b); console.error(c); return false; - }, + }, ajaxifyAttackHref: function() { // rewrite any links with hrefs point to relative attack URLs var self = this; @@ -120,7 +128,7 @@ define(['jquery', addPaginationControls: function() { var pagingControlsDiv; - this.$el.html(); + //this.$el.html(); //prev var prevPageButton = $('',{class:'glyphicon-class glyphicon glyphicon-circle-arrow-left show-prev-page'}); prevPageButton.unbind().on('click',this.decrementPageView.bind(this)); @@ -190,6 +198,46 @@ define(['jquery', showCurContentPage: function(isIncrement) { this.$contentPages.hide(); this.$el.find(this.$contentPages[this.currentPage]).show(); + }, + + navToPage: function (pageNum) { + this.setCurrentPage(pageNum);//provides validation + this.showCurContentPage(this.currentPage); + this.hideShowNavButtons(); + }, + + hideShowNavButtons: function () { + //one page only + if (this.numPages === 1) { + this.hidePrevPageButton(); + this.hideNextPageButton(); + } + //first page + if (this.currentPage === 0) { + this.hidePrevPageButton(); + if (this.numPages > 1) { + this.showNextPageButton(); + } + return; + } + // > first page, but not last + if (this.currentPage > 0 && this.currentPage < this.numPages -1) { + this.showNextPageButton(); + this.showPrevPageButton(); + return; + } + // last page and more than one page + if (this.currentPage === this.numPages -1 && this.numPages > 1) { + this.hideNextPageButton(); + this.showPrevPageButton(); + return; + } + + }, + + /* for testing */ + showTestParam: function (param) { + this.$el.find('.lesson-content').html('test:' + param); } });