adding direct to page navigation route
This commit is contained in:
parent
4940a12d0d
commit
0aa9c29256
@ -61,7 +61,12 @@ define(['jquery',
|
|||||||
this.menuButtonView = new MenuButtonView();
|
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.titleView = new TitleView();
|
||||||
this.helpsLoaded = {};
|
this.helpsLoaded = {};
|
||||||
if (typeof(name) === 'undefined' || name === null) {
|
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;
|
return Controller;
|
||||||
});
|
});
|
||||||
|
@ -22,11 +22,12 @@ define(['jquery',
|
|||||||
var GoatAppRouter = Backbone.Router.extend({
|
var GoatAppRouter = Backbone.Router.extend({
|
||||||
routes: {
|
routes: {
|
||||||
'welcome':'welcomeRoute',
|
'welcome':'welcomeRoute',
|
||||||
'lesson/:name':'lessonRoute'
|
'lesson/:name':'lessonRoute',
|
||||||
//'attack/:scr/:menu/:stage':'attackRoute',
|
'lesson/:name/:pageNum':'lessonPageRoute',
|
||||||
//'attack/:scr/:menu/*stage/:num':'attackRoute',
|
'test/:param':'testRoute'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
lessonController: new LessonController({
|
lessonController: new LessonController({
|
||||||
lessonContentView: lessonContentView
|
lessonContentView: lessonContentView
|
||||||
}),
|
}),
|
||||||
@ -41,14 +42,17 @@ define(['jquery',
|
|||||||
// this.menuController.initMenu();
|
// this.menuController.initMenu();
|
||||||
webgoat = {};
|
webgoat = {};
|
||||||
webgoat.customjs = {};
|
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) {
|
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
|
//TODO - update menu code from below
|
||||||
this.menuController.updateMenu(name);
|
this.menuController.updateMenu(name);
|
||||||
});
|
});
|
||||||
@ -56,6 +60,15 @@ define(['jquery',
|
|||||||
goatRouter.on('route:welcomeRoute', function() {
|
goatRouter.on('route:welcomeRoute', function() {
|
||||||
this.lessonController.loadWelcome();
|
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) {});
|
goatRouter.on("route", function(route, params) {});
|
||||||
|
|
||||||
Backbone.history.start();
|
Backbone.history.start();
|
||||||
|
@ -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 () {
|
makeFormsAjax: function () {
|
||||||
this.$form = $('form.attack-form');
|
this.$form = $('form.attack-form');
|
||||||
// turn off standard submit
|
// turn off standard submit
|
||||||
@ -79,7 +87,7 @@ define(['jquery',
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
onSuccessResponse: function(data) {
|
onSuccessResponse: function(data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
this.renderFeedback(data.feedback);
|
this.renderFeedback(data.feedback);
|
||||||
|
|
||||||
@ -88,14 +96,14 @@ define(['jquery',
|
|||||||
this.trigger('lesson:complete');
|
this.trigger('lesson:complete');
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
onErrorResponse: function (a,b,c) {
|
onErrorResponse: function (a,b,c) {
|
||||||
console.error(a);
|
console.error(a);
|
||||||
console.error(b);
|
console.error(b);
|
||||||
console.error(c);
|
console.error(c);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
ajaxifyAttackHref: function() { // rewrite any links with hrefs point to relative attack URLs
|
ajaxifyAttackHref: function() { // rewrite any links with hrefs point to relative attack URLs
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -120,7 +128,7 @@ define(['jquery',
|
|||||||
|
|
||||||
addPaginationControls: function() {
|
addPaginationControls: function() {
|
||||||
var pagingControlsDiv;
|
var pagingControlsDiv;
|
||||||
this.$el.html();
|
//this.$el.html();
|
||||||
//prev
|
//prev
|
||||||
var prevPageButton = $('<span>',{class:'glyphicon-class glyphicon glyphicon-circle-arrow-left show-prev-page'});
|
var prevPageButton = $('<span>',{class:'glyphicon-class glyphicon glyphicon-circle-arrow-left show-prev-page'});
|
||||||
prevPageButton.unbind().on('click',this.decrementPageView.bind(this));
|
prevPageButton.unbind().on('click',this.decrementPageView.bind(this));
|
||||||
@ -190,6 +198,46 @@ define(['jquery',
|
|||||||
showCurContentPage: function(isIncrement) {
|
showCurContentPage: function(isIncrement) {
|
||||||
this.$contentPages.hide();
|
this.$contentPages.hide();
|
||||||
this.$el.find(this.$contentPages[this.currentPage]).show();
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user