Moved Maven multiproject setup
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'goatApp/controller/LessonController',
|
||||
'goatApp/controller/MenuController',
|
||||
'goatApp/view/LessonContentView',
|
||||
'goatApp/view/MenuView',
|
||||
'goatApp/view/TitleView'
|
||||
], function ($,_,Backbone,LessonController,MenuController,LessonContentView,MenuView,TitleView) {
|
||||
|
||||
var lessonView = new LessonContentView();
|
||||
var menuView = new MenuView();
|
||||
var titleView = new TitleView();
|
||||
|
||||
var GoatAppRouter = Backbone.Router.extend({
|
||||
routes: {
|
||||
//#....
|
||||
'welcome':'welcomeRoute',
|
||||
'attack/:scr/:menu':'attackRoute' //
|
||||
},
|
||||
|
||||
lessonController: new LessonController({
|
||||
lessonView:lessonView
|
||||
}),
|
||||
|
||||
menuController: new MenuController({
|
||||
menuView:menuView,
|
||||
titleView:titleView
|
||||
}),
|
||||
|
||||
init:function() {
|
||||
goatRouter = new GoatAppRouter();
|
||||
this.lessonController.start();
|
||||
this.menuController.initMenu();
|
||||
|
||||
goatRouter.on('route:attackRoute', function(scr,menu) {
|
||||
this.lessonController.loadLesson(scr,menu);
|
||||
this.menuController.updateMenu(scr,menu);
|
||||
//update menu
|
||||
});
|
||||
goatRouter.on('route:welcomeRoute', function() {
|
||||
alert('welcome route');
|
||||
});
|
||||
|
||||
Backbone.history.start();
|
||||
this.listenTo('menu:reload',this.reloadMenu)
|
||||
},
|
||||
|
||||
reloadMenu: function (curLesson) {
|
||||
this.menuController.updateMenu(curLesson);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
return GoatAppRouter;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone'],
|
||||
function($,_,Backbone) {
|
||||
return Backbone.View.extend({
|
||||
el:'#help-controls', //Check this
|
||||
helpButtons: {
|
||||
//TODO: move this into a template
|
||||
showSource:$('<button>',{id:'show-source-button','class':'btn btn-primary btn-xs help-button',type:'button',text:'Java [Source]'}),
|
||||
showSolution:$('<button>',{id:'show-solution-button','class':'btn btn-primary btn-xs help-button',type:'button',text:'Solution'}),
|
||||
showPlan:$('<button>',{id:'show-plan-button','class':'btn btn-primary btn-xs help-button',type:'button',text:'Lesson Plan]'}),
|
||||
showHints:$('<button>',{id:'show-hints-button','class':'btn btn-primary btn-xs help-button',type:'button',text:'Hints'}),
|
||||
restartLesson:$('<button>',{id:'restart-lesson-button','class':'btn btn-xs help-button',type:'button',text:'Restart Lesson'})
|
||||
},
|
||||
initialize: function (options) {
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
this.hasPlan = options.hasPlan;
|
||||
this.hasSolution = options.hasSolution;
|
||||
this.hasSource = options.hasSource;
|
||||
this.hasHints = options.hasHints;
|
||||
},
|
||||
render:function(title) {
|
||||
this.$el.html();
|
||||
|
||||
if (this.hasSource) {
|
||||
this.helpButtons.showSource.unbind().on('click',_.bind(this.showSource,this));
|
||||
this.$el.append(this.helpButtons.showSource);
|
||||
}
|
||||
if (this.hasSolution) {
|
||||
this.helpButtons.showSolution.unbind().on('click',_.bind(this.showSolution,this));
|
||||
this.$el.append(this.helpButtons.showSolution);
|
||||
}
|
||||
if (this.hasPlan) {
|
||||
this.helpButtons.showPlan.unbind().on('click',_.bind(this.showPlan,this));
|
||||
this.$el.append(this.helpButtons.showPlan);
|
||||
}
|
||||
if (this.hasHints) {
|
||||
this.helpButtons.showHints.unbind().on('click',_.bind(this.showHints,this));
|
||||
this.$el.append(this.helpButtons.showHints);
|
||||
}
|
||||
|
||||
this.helpButtons.restartLesson.unbind().on('click',_.bind(this.restartLesson,this));
|
||||
this.$el.append(this.helpButtons.restartLesson);
|
||||
},
|
||||
|
||||
showSource: function() {
|
||||
this.trigger('source:show','source');
|
||||
},
|
||||
|
||||
showSolution: function() {
|
||||
this.trigger('solution:show','solution');
|
||||
},
|
||||
|
||||
showPlan: function() {
|
||||
this.trigger('plan:show','plan');
|
||||
},
|
||||
|
||||
showHints: function() {
|
||||
this.trigger('hints:show','hints');
|
||||
},
|
||||
restartLesson: function() {
|
||||
this.trigger('lesson:restart');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'goatApp/model/LessonSourceModel'],
|
||||
function($,
|
||||
_,
|
||||
Backbone,
|
||||
LessonSourceModel) {
|
||||
return Backbone.View.extend({
|
||||
el:'#lessonHelpWrapper .lessonHelp.lessonPlan', //Check this
|
||||
initialize: function() {
|
||||
this.model = new LessonSourceModel();
|
||||
this.listenTo(this.model,'loaded',this.onModelLoaded);
|
||||
this.model.loadData();
|
||||
},
|
||||
render:function(title) {
|
||||
|
||||
},
|
||||
onModelLoaded: function() {
|
||||
this.trigger(this.loadedMessage,this.helpElement);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
//LessonContentView
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'libs/jquery.form',
|
||||
'goatApp/model/LessonContentData'],
|
||||
function($,_,Backbone,JQueryForm,LessonData) {
|
||||
return Backbone.View.extend({
|
||||
el:'#lesson-content-wrapper', //TODO << get this fixed up in DOM
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
},
|
||||
render: function() {
|
||||
this.$el.html(this.model.get('content'));
|
||||
this.makeFormsAjax();
|
||||
},
|
||||
//TODO: reimplement this in custom fashion maybe?
|
||||
makeFormsAjax: function () {
|
||||
var options = {
|
||||
//target: '#lesson_content', // target element(s) to be updated with server response
|
||||
//beforeSubmit: GoatUtils.showRequest, // pre-submit callback, comment out after debugging
|
||||
//success: GoatUtils.showResponse // post-submit callback, comment out after debugging
|
||||
success:this.reLoadView.bind(this),
|
||||
url:'attack?Screen=' + this.model.get('screenParam') + '&menu=' + this.model.get('menuParam'),
|
||||
type:'GET'
|
||||
// $.ajax options can be used here too, for example:
|
||||
//timeout: 3000
|
||||
};
|
||||
//hook forms //TODO: clarify form selectors later
|
||||
$("form").ajaxForm(options);
|
||||
},
|
||||
reLoadView: function(content) {
|
||||
this.model.setContent(content);
|
||||
this.render();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'goatApp/model/LessonHintCollection'],
|
||||
function($,
|
||||
_,
|
||||
Backbone,
|
||||
LessonHintCollection) {
|
||||
return Backbone.View.extend({
|
||||
el:'#lesson-hint-container',
|
||||
events: {
|
||||
"click #show-next-hint": "showNextHint",
|
||||
"click #show-prev-hint": "showPrevHint"
|
||||
},
|
||||
initialize: function() {
|
||||
this.curHint=0;
|
||||
this.collection = new LessonHintCollection();
|
||||
this.listenTo(this.collection,'loaded',this.onModelLoaded);
|
||||
|
||||
},
|
||||
|
||||
render:function() {
|
||||
if (this.$el.is(':visible')) {
|
||||
this.$el.hide(350);
|
||||
} else {
|
||||
this.$el.show(350);
|
||||
}
|
||||
|
||||
if (this.collection.length > 0) {
|
||||
this.hideShowPrevNextButtons();
|
||||
}
|
||||
this.displayHint(this.curHint);
|
||||
|
||||
},
|
||||
|
||||
onModelLoaded: function() {
|
||||
this.trigger('hints:loaded',{'helpElement':'hints','value':true})
|
||||
},
|
||||
|
||||
showNextHint: function() {
|
||||
this.curHint = (this.curHint < this.collection.length -1) ? this.curHint+1 : this.curHint;
|
||||
this.hideShowPrevNextButtons();
|
||||
this.displayHint(this.curHint);
|
||||
},
|
||||
|
||||
showPrevHint: function() {
|
||||
this.curHint = (this.curHint > 0) ? this.curHint-1 : this.curHint;
|
||||
this.hideShowPrevNextButtons();
|
||||
this.displayHint(this.curHint);
|
||||
},
|
||||
|
||||
displayHint: function(curHint) {
|
||||
this.$el.find('#lesson-hint-content').html(this.collection.models[curHint].get('hint'));
|
||||
},
|
||||
|
||||
hideShowPrevNextButtons: function() {
|
||||
if (this.curHint === this.collection.length -1) {
|
||||
this.$el.find('#show-next-hint').css('visibility','hidden');
|
||||
} else {
|
||||
this.$el.find('#show-next-hint').css('visibility','visible');
|
||||
}
|
||||
|
||||
if (this.curHint === 0) {
|
||||
this.$el.find('#show-prev-hint').css('visibility','hidden');
|
||||
} else {
|
||||
this.$el.find('#show-prev-hint').css('visibility','visible');
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'goatApp/support/GoatUtils',
|
||||
'goatApp/view/MenuItemView'],
|
||||
function(
|
||||
$,
|
||||
_,
|
||||
Backbone,
|
||||
GoatUtils,
|
||||
MenuItemView) {
|
||||
|
||||
return Backbone.View.extend({
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
this.items = options.items;
|
||||
},
|
||||
render: function() {
|
||||
var viewItems = [];
|
||||
for (var i=0;i<this.items.length;i++) {
|
||||
var listItem = $('<li>',{text:this.items[i].name});
|
||||
//viewItems
|
||||
viewItems.push(listItem);
|
||||
}
|
||||
return viewItems;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone'], function($,_,Backbone) {
|
||||
|
||||
return Backbone.View.extend({
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
105
webgoat-container/src/main/webapp/js/goatApp/view/MenuView.js
Normal file
105
webgoat-container/src/main/webapp/js/goatApp/view/MenuView.js
Normal file
@@ -0,0 +1,105 @@
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'goatApp/model/MenuCollection',
|
||||
'goatApp/view/MenuItemView',
|
||||
'goatApp/support/GoatUtils'],
|
||||
function(
|
||||
$,
|
||||
_,
|
||||
Backbone,
|
||||
MenuCollection,
|
||||
MenuItemView,
|
||||
GoatUtils) {
|
||||
return Backbone.View.extend({
|
||||
el:'#menu-container',
|
||||
//TODO: set template
|
||||
initialize: function() {
|
||||
this.collection = new MenuCollection();
|
||||
this.listenTo(this.collection,'menuData:loaded',this.render);
|
||||
this.listenTo(this,'menu:click',this.accordionMenu);
|
||||
},
|
||||
// rendering top level menu
|
||||
render: function (model){
|
||||
//for now, just brute force
|
||||
//TODO: refactor into sub-views/components
|
||||
var items, catItems, stages;
|
||||
items = this.collection.models; // top level items
|
||||
var menuMarkup = '';
|
||||
var menuUl = $('<ul>',{class:'nano-content'});
|
||||
for(var i=0;i<items.length;i++) { //CATEGORY LEVEL
|
||||
var catId, category, catLink, catArrow, catLinkText, lessonName, stageName;
|
||||
catId = GoatUtils.makeId(items[i].get('name'));
|
||||
category = $('<li>',{class:'sub-menu ng-scope'});
|
||||
catLink = $('<a>',{'category':catId});
|
||||
catArrow = $('<i>',{class:'fa fa-angle-right pull-right'});
|
||||
catLinkText = $('<span>',{text:items[i].get('name')});
|
||||
|
||||
catLink.append(catArrow);
|
||||
catLink.append(catLinkText);
|
||||
//TODO: refactor this along with sub-views/components
|
||||
var self = this;
|
||||
catLink.click(_.bind(this.expandCategory,this,catId));
|
||||
category.append(catLink);
|
||||
// lesson level (first children level)
|
||||
//var lessons = new MenuItemView({items:items[i].get('children')}).render();
|
||||
var lessons=items[i].get('children');
|
||||
if (lessons) {
|
||||
var categoryLessonList = $('<ul>',{class:'slideDown lessonsAndStages',id:catId}); //keepOpen
|
||||
for (var j=0; j < lessons.length;j++) {
|
||||
var lessonItem = $('<li>');
|
||||
lessonName = lessons[j].name;
|
||||
|
||||
var lessonLink = $('<a>',{href:lessons[j].link,text:lessonName,id:lessonName});
|
||||
lessonLink.click(_.bind(this.titleRender,this,lessonName));
|
||||
lessonItem.append(lessonLink);
|
||||
//check for lab/stages
|
||||
categoryLessonList.append(lessonItem);
|
||||
if (lessons[j].complete) {
|
||||
lessonItem.append($('<span>',{class:'glyphicon glyphicon-check lesson-complete'}));
|
||||
}
|
||||
var stages = lessons[j].children;
|
||||
for (k=0; k < stages.length; k++) {
|
||||
var stageName = stages[k].name;
|
||||
var stageLink = $('<a>',{href:stages[k].link,text:stageName,id:GoatUtils.makeId(stageName)});
|
||||
stageSpan.append(stageLink);
|
||||
categoryLessonList.append(stageSpan);
|
||||
if (stages[j].complete) {
|
||||
stageSpan.append($('<span>',{class:'glyphicon glyphicon-check lesson-complete'}));
|
||||
}
|
||||
}
|
||||
}
|
||||
category.append(categoryLessonList);
|
||||
}
|
||||
|
||||
menuUl.append(category);
|
||||
}
|
||||
this.$el.append(menuUl);
|
||||
//if we need to keep a menu open
|
||||
if (this.openMenu) {
|
||||
this.accordionMenu(this.openMenu);
|
||||
}
|
||||
},
|
||||
|
||||
titleRender: function (title) {
|
||||
this.trigger('lesson:click',title);
|
||||
},
|
||||
|
||||
expandCategory: function (id) {
|
||||
if (id) {
|
||||
this.accordionMenu(id);
|
||||
}
|
||||
},
|
||||
|
||||
accordionMenu: function(id) {
|
||||
if (this.openMenu !== id) {
|
||||
this.$el.find('#' + id).slideDown(300);
|
||||
this.openMenu = id;
|
||||
} else { //it's open
|
||||
this.$el.find('#' + id).slideUp(300).attr('isOpen', 0);
|
||||
this.openMenu = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'goatApp/model/LessonPlanModel'],
|
||||
function($,
|
||||
_,
|
||||
Backbone,
|
||||
LessonPlanModel) {
|
||||
return Backbone.View.extend({
|
||||
el:'#lessonHelpWrapper .lessonHelp.lessonPlan', //Check this
|
||||
initialize: function() {
|
||||
this.model = new LessonPlanModel();
|
||||
this.listenTo(this.model,'loaded',this.onModelLoaded);
|
||||
this.model.loadData();
|
||||
},
|
||||
render:function(title) {
|
||||
|
||||
},
|
||||
onModelLoaded: function() {
|
||||
this.trigger('plan:loaded',{'helpElement':'plan','value':true});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'goatApp/model/LessonSolutionModel'],
|
||||
//TODO: create a base 'HelpView class'
|
||||
function($,_,Backbone,LessonSolutionModel) {
|
||||
return Backbone.View.extend({
|
||||
el:'#lessonHelpWrapper .lessonHelp.lessonSolution', //Check this
|
||||
initialize: function() {
|
||||
this.model = new LessonSolutionModel();
|
||||
this.listenTo(this.model,'loaded',this.onModelLoaded);
|
||||
this.model.loadData();
|
||||
//TODO: handle error cases
|
||||
},
|
||||
render:function(title) {
|
||||
|
||||
},
|
||||
onModelLoaded: function() {
|
||||
this.trigger('solution:loaded',{'helpElement':'solution','value':true});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'goatApp/model/LessonSourceModel',
|
||||
'goatApp/view/HelpView'],
|
||||
function($,
|
||||
_,
|
||||
Backbone,
|
||||
LessonSourceModel,
|
||||
HelpView) {
|
||||
return HelpView.extend({
|
||||
helpElement:{'helpElement':'source','value':true},
|
||||
loadedMessage:'source:loaded',
|
||||
el:'#lessonHelpWrapper .lessonHelp.lessonPlan', //Check this
|
||||
initialize: function() {
|
||||
this.model = new LessonSourceModel();
|
||||
this.listenTo(this.model,'loaded',this.onModelLoaded);
|
||||
this.model.loadData();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
define(['jquery',
|
||||
'underscore',
|
||||
'backbone'],
|
||||
function($,_,Backbone) {
|
||||
return Backbone.View.extend({
|
||||
el:'#header #lesson-title-wrapper',
|
||||
render:function(title) {
|
||||
var lessonTitleEl = $('<h1>',{id:'lesson-title',text:title});
|
||||
this.$el.html(lessonTitleEl);
|
||||
//this.$el.append(lessonTitleEl);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user