recent merge from upstream
This commit is contained in:
parent
33dc855da7
commit
f85132284f
@ -6,7 +6,8 @@ define(['jquery','underscore','backbone','goatApp/view/goatRouter','goatApp/cont
|
|||||||
return {
|
return {
|
||||||
initApp: function() {
|
initApp: function() {
|
||||||
//TODO: add query/ability to load from where they left off
|
//TODO: add query/ability to load from where they left off
|
||||||
Router.init();
|
console.log('initApp')
|
||||||
|
//Router.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -1,20 +0,0 @@
|
|||||||
define(['jquery', 'underscore','backbone'], function($,_,Backbone){
|
|
||||||
|
|
||||||
return Backbone.Model.extend({
|
|
||||||
urlRoot:null,
|
|
||||||
defaults: {
|
|
||||||
items:null,
|
|
||||||
selectedItem:null
|
|
||||||
},
|
|
||||||
initialize: function (options) {
|
|
||||||
var self = this;
|
|
||||||
this.urlRoot = 'attack.jsp?Screen='+options.screen + '&menu=' + options.menu;
|
|
||||||
this.fetch().then(function(content){
|
|
||||||
self.lessonContent = content
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getHint: function (i) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,32 +0,0 @@
|
|||||||
//var goatApp = goatApp || {};
|
|
||||||
|
|
||||||
define(['jquery','underscore','backbone'], function($,_,Backbone) {
|
|
||||||
|
|
||||||
var menuData = Backbone.Model.extend({
|
|
||||||
urlRoot:'/webgoat/service/lessonmenu.mvc',
|
|
||||||
defaults: {
|
|
||||||
items:null,
|
|
||||||
selectedItem:null
|
|
||||||
},
|
|
||||||
initialize: function () {
|
|
||||||
var self = this;
|
|
||||||
this.fetch().then(function(menuItems){
|
|
||||||
menuItems = goatUtils.enhanceMenuData(menuItems,this.selectedItem);
|
|
||||||
this.setDataItems(menuItems);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
update: function() {
|
|
||||||
var self = this;
|
|
||||||
this.fetch().then(function(menuItems) {
|
|
||||||
menuItems = goatUtils.enhanceMenuData(menuItems,this.selectedItem);
|
|
||||||
self.setDataItems(menuItems);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
setDataItems: function (data) {
|
|
||||||
this.items = data;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
@ -1,22 +0,0 @@
|
|||||||
var menuData = Backbone.Model.extend({
|
|
||||||
urlRoot:'/webgoat/service/lessonmenu.mvc',
|
|
||||||
defaults: {
|
|
||||||
items:null,
|
|
||||||
selectedItem:null
|
|
||||||
},
|
|
||||||
initialize: function () {
|
|
||||||
var self = this;
|
|
||||||
this.fetch().then(function(menuItems){
|
|
||||||
menuItems = goatUtils.enhanceMenuData(menuItems,this.selectedItem);
|
|
||||||
self.items = menuItems;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
update: function() {
|
|
||||||
var self = this;
|
|
||||||
this.fetch().then(function(data) {
|
|
||||||
self.items = data;
|
|
||||||
self.render(0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
@ -20,4 +20,6 @@ function($,_,Backbone,LessonData) {
|
|||||||
this.$el.html(this.content);
|
this.$el.html(this.content);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return contentView;
|
||||||
});
|
});
|
@ -5,7 +5,7 @@ define(['jquery',
|
|||||||
'goatApp/controller/MenuController',
|
'goatApp/controller/MenuController',
|
||||||
'goatApp/view/LessonContentView',
|
'goatApp/view/LessonContentView',
|
||||||
'goatApp/view/MenuView'
|
'goatApp/view/MenuView'
|
||||||
], function ($,_,Backbone,LessonController,MenuController,LessonView,MenuView) {
|
], function ($,_,Backbone,LessonController,MenuController,LessonContentView,MenuView) {
|
||||||
|
|
||||||
var lessonView = new LessonContentView();
|
var lessonView = new LessonContentView();
|
||||||
var menuView = new MenuView();
|
var menuView = new MenuView();
|
||||||
@ -20,7 +20,7 @@ define(['jquery',
|
|||||||
}),
|
}),
|
||||||
menuView: new MenuController({
|
menuView: new MenuController({
|
||||||
menuView:menuView
|
menuView:menuView
|
||||||
});
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
var init = function() {
|
var init = function() {
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
//goatConstants
|
|
||||||
|
|
||||||
var goatConstants = {
|
|
||||||
CATEGORYCLASS:'fa-angle-right pull-right',
|
|
||||||
lessonCompleteClass:'glyphicon glyphicon-check lessonComplete',
|
|
||||||
selectedMenuClass:'selected',
|
|
||||||
keepOpenClass:'keepOpen',
|
|
||||||
menuPrefix : [
|
|
||||||
{
|
|
||||||
name:'LESSONS',
|
|
||||||
type:'STATIC',
|
|
||||||
complete:false,
|
|
||||||
link:'',
|
|
||||||
children:null,
|
|
||||||
class:'fa-bars static'
|
|
||||||
}],
|
|
||||||
//services
|
|
||||||
lessonService: 'service/lessonmenu.mvc',
|
|
||||||
cookieService: 'service/cookie.mvc', //cookies_widget.mvc
|
|
||||||
hintService:'service/hint.mvc',
|
|
||||||
sourceService:'service/source.mvc',
|
|
||||||
solutionService:'service/solution.mvc',
|
|
||||||
lessonPlanService:'service/lessonplan.mvc',
|
|
||||||
menuService: 'service/lessonmenu.mvc',
|
|
||||||
lessonTitleService: 'service/lessontitle.mvc',
|
|
||||||
restartLessonService: 'service/restartlesson.mvc',
|
|
||||||
|
|
||||||
// literal messages
|
|
||||||
notFound: 'Could not find',
|
|
||||||
noHints: 'There are no hints defined.',
|
|
||||||
noSourcePulled: 'No source was retrieved for this lesson'
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
@ -1,265 +0,0 @@
|
|||||||
//main goat application file
|
|
||||||
//TODO: reorg
|
|
||||||
|
|
||||||
/* ### GOAT CONTROLLERS ### */
|
|
||||||
|
|
||||||
/* menu controller */
|
|
||||||
var goatMenu = function($scope, $http, $modal, $log, $templateCache) {
|
|
||||||
$scope.cookies = [];
|
|
||||||
$scope.params = [];
|
|
||||||
$scope.renderMenu = function() {
|
|
||||||
goat.data.loadMenu($http).then(//$http({method: 'GET', url: goatConstants.lessonService})
|
|
||||||
function(menuData) {
|
|
||||||
var menuItems = goat.utils.addMenuClasses(goatConstants.menuPrefix.concat(menuData.data));
|
|
||||||
//top-tier 'categories'
|
|
||||||
for (var i = 0; i < menuItems.length; i++) {
|
|
||||||
menuItems[i].id = goat.utils.makeId(menuItems[i].name);//TODO move the replace routine into util function
|
|
||||||
menuItems[i].displayClass = ($scope.openMenu === menuItems[i].id) ? goatConstants.keepOpenClass : '';
|
|
||||||
if (menuItems[i].children) {
|
|
||||||
for (var j = 0; j < menuItems[i].children.length; j++) {
|
|
||||||
menuItems[i].children[j].id = goat.utils.makeId(menuItems[i].children[j].name);
|
|
||||||
//handle selected Menu state
|
|
||||||
if (menuItems[i].children[j].id === $scope.curMenuItemSelected) {
|
|
||||||
menuItems[i].children[j].selectedClass = goatConstants.selectedMenuClass;
|
|
||||||
menuItems[i].selectedClass = goatConstants.selectedMenuClass;
|
|
||||||
}
|
|
||||||
//handle complete state
|
|
||||||
if (menuItems[i].children[j].complete) {
|
|
||||||
menuItems[i].children[j].completeClass = goatConstants.lessonCompleteClass;
|
|
||||||
} else {
|
|
||||||
menuItems[i].children[j].completeClass = '';
|
|
||||||
}
|
|
||||||
if (menuItems[i].children[j].children) {
|
|
||||||
for (var k = 0; k < menuItems[i].children[j].children.length; k++) {
|
|
||||||
//TODO make utility function for name >> id
|
|
||||||
menuItems[i].children[j].children[k].id = goat.utils.makeId(menuItems[i].children[j].children[k].name);
|
|
||||||
//menuItems[i].children[j].children[k].id = menuItems[i].children[j].children[k].name.replace(/\s|\(|\)/g,'');
|
|
||||||
//handle selected Menu state
|
|
||||||
if (menuItems[i].children[j].children[k].id === $scope.curMenuItemSelected) {
|
|
||||||
menuItems[i].children[j].children[k].selectedClass = goatConstants.selectedMenuClass;
|
|
||||||
menuItems[i].children[j].selectedClass = goatConstants.selectedMenuClass;
|
|
||||||
}
|
|
||||||
//handle complete state
|
|
||||||
if (menuItems[i].children[j].children[k].complete) {
|
|
||||||
menuItems[i].children[j].children[k].completeClass = goatConstants.lessonCompleteClass;
|
|
||||||
} else {
|
|
||||||
menuItems[i].children[j].children[k].completeClass = ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$scope.menuTopics = menuItems;
|
|
||||||
//
|
|
||||||
if ($scope.openMenu) {
|
|
||||||
$('ul' + $scope.openMenu).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
function(error) {
|
|
||||||
// TODO - handle this some way other than an alert
|
|
||||||
console.error("Error rendering menu: " + error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.renderLesson = function(id, url, showControls) {//TODO convert to single object parameter
|
|
||||||
$scope.hintIndex = 0;
|
|
||||||
var curScope = $scope;
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
// clean up menus, mark selected
|
|
||||||
$scope.curMenuItemSelected = id;
|
|
||||||
goat.utils.highlightCurrentLessonMenu(id);
|
|
||||||
curScope.parameters = goat.utils.scrapeParams(url);
|
|
||||||
// lesson content
|
|
||||||
goat.data.loadLessonContent($http, url).then(
|
|
||||||
function(reply) {
|
|
||||||
goat.data.loadLessonTitle($http).then(
|
|
||||||
function(reply) {
|
|
||||||
$("#lessonTitle").text(reply.data);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
//TODO encode html or get angular js portion working
|
|
||||||
$("#lesson_content").html(reply.data);
|
|
||||||
//hook forms and links (safe to call twice)
|
|
||||||
// links are hooked with each lesson now (see Java class Screen.getContent())
|
|
||||||
goat.utils.makeFormsAjax();// inject form?
|
|
||||||
goat.utils.ajaxifyAttackHref();
|
|
||||||
$('#leftside-navigation').height($('#main-content').height() + 15)//TODO: get ride of fixed value (15)here
|
|
||||||
//notifies goatLesson Controller of the less change
|
|
||||||
$scope.$emit('lessonUpdate', {params: curScope.parameters, 'showControls': showControls});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
$scope.renderMenu();
|
|
||||||
};
|
|
||||||
$scope.accordionMenu = function(id) {
|
|
||||||
if ($('ul#' + id).attr('isOpen') == 0) {
|
|
||||||
$scope.expandMe = true;
|
|
||||||
} else {
|
|
||||||
$('ul#' + id).slideUp(300).attr('isOpen', 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$scope.openMenu = id;
|
|
||||||
$('.lessonsAndStages').not('ul#' + id).slideUp(300).attr('isOpen', 0);
|
|
||||||
if ($scope.expandMe) {
|
|
||||||
$('ul#' + id).slideDown(300).attr('isOpen', 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$scope.renderMenu();
|
|
||||||
// runs on first loadcan be augmented later to '
|
|
||||||
// resume' for a given user ... currently kluged to start at fixed lesson
|
|
||||||
var url = 'attack?Screen=32&menu=5';
|
|
||||||
angular.element($('#leftside-navigation')).scope().renderLesson(null, url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* lesson controller */
|
|
||||||
var goatLesson = function($scope, $http, $log) {
|
|
||||||
|
|
||||||
$('#hintsView').hide();
|
|
||||||
// adjust menu to lessonContent size if necssary
|
|
||||||
//cookies
|
|
||||||
|
|
||||||
$scope.$on('lessonUpdate', function(params) {
|
|
||||||
$scope.parameters = arguments[1].params;
|
|
||||||
$scope.showHints = (arguments[1].showControls && arguments[1].showControls.showHints);
|
|
||||||
$scope.showSource = (arguments[1].showControls && arguments[1].showControls.showSource);
|
|
||||||
curScope = $scope; //TODO .. update below, this curScope is probably not needed
|
|
||||||
goat.data.loadCookies($http).then(
|
|
||||||
function(resp) {
|
|
||||||
curScope.cookies = resp.data;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
//hints
|
|
||||||
curScope.hintIndex = 0;
|
|
||||||
if ($scope.showHints) {
|
|
||||||
goat.data.loadHints($http).then(
|
|
||||||
function(resp) {
|
|
||||||
curScope.hints = resp.data;
|
|
||||||
if (curScope.hints.length > 0 && curScope.hints[0].hint.indexOf(goatConstants.noHints) === -1) {
|
|
||||||
goat.utils.displayButton('showHintsBtn', true);
|
|
||||||
} else {
|
|
||||||
goat.utils.displayButton('showHintsBtn', false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$scope.hints = null;
|
|
||||||
goat.utils.displayButton('showHintsBtn', false);
|
|
||||||
}
|
|
||||||
//source
|
|
||||||
if ($scope.showSource) {
|
|
||||||
goat.data.loadSource($http).then(
|
|
||||||
function(resp) {
|
|
||||||
curScope.source = resp.data;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$scope.source = goatConstants.noSourcePulled;
|
|
||||||
}
|
|
||||||
|
|
||||||
//plan
|
|
||||||
goat.data.loadPlan($http).then(
|
|
||||||
function(resp) {
|
|
||||||
curScope.plan = resp.data;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
//solution
|
|
||||||
goat.data.loadSolution($http).then(
|
|
||||||
function(resp) {
|
|
||||||
curScope.solution = resp.data;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
//goat.utils.scrollToTop();
|
|
||||||
|
|
||||||
|
|
||||||
$scope.showLessonSource = function() {
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
$('#lesson_source_row').show();
|
|
||||||
goat.utils.scrollToHelp();
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.showLessonPlan = function() {
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
$("#lesson_plan").html($scope.plan);
|
|
||||||
$('#lesson_plan_row').show();
|
|
||||||
goat.utils.scrollToHelp();
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.showLessonSolution = function() {
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
$("#lesson_solution").html($scope.solution);
|
|
||||||
$('#lesson_solution_row').show();
|
|
||||||
goat.utils.scrollToHelp();
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.manageHintButtons = function() {
|
|
||||||
if ($scope.hintIndex === $scope.hints.length - 1) {
|
|
||||||
$('#showNextHintBtn').css('visibility', 'hidden');
|
|
||||||
} else if ($scope.hintIndex < $scope.hints.length - 1) {
|
|
||||||
$('#showNextHintBtn').css('visibility', 'visible');
|
|
||||||
}
|
|
||||||
//
|
|
||||||
if ($scope.hintIndex === 0) {
|
|
||||||
$('#showPrevHintBtn').css('visibility', 'hidden');
|
|
||||||
} else if ($scope.hintIndex > 0) {
|
|
||||||
$('#showPrevHintBtn').css('visibility', 'visible');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.viewHints = function() {
|
|
||||||
if (!$scope.hints) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
$('#lesson_hint_row').show();
|
|
||||||
//goat.utils.scrollToHelp();
|
|
||||||
//TODO
|
|
||||||
$scope.curHint = $scope.hints[$scope.hintIndex].hint;
|
|
||||||
//$scope.curHint = $sce.trustAsHtml($scope.hints[$scope.hintIndex].hint);
|
|
||||||
//TODO get html binding workin in the UI ... in the meantime ...
|
|
||||||
//$scope.renderCurHint();
|
|
||||||
$scope.manageHintButtons();
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.viewNextHint = function() {
|
|
||||||
$scope.hintIndex++;
|
|
||||||
$scope.curHint = $scope.hints[$scope.hintIndex].hint;
|
|
||||||
$scope.renderCurHint();
|
|
||||||
$scope.manageHintButtons();
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.viewPrevHint = function() {
|
|
||||||
$scope.hintIndex--;
|
|
||||||
$scope.curHint = $scope.hints[$scope.hintIndex].hint;
|
|
||||||
$scope.renderCurHint();
|
|
||||||
$scope.manageHintButtons();
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.renderCurHint = function() {
|
|
||||||
$('#curHintContainer').html($scope.curHint);
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.hideHints = function() {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.restartLesson = function() {
|
|
||||||
goat.data.loadRestart($http).then(
|
|
||||||
function(resp) {
|
|
||||||
angular.element($('#leftside-navigation')).scope().renderLesson(null, resp.data, {showSource: $scope.showSource, showHints: $scope.showHints});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.showAbout = function() {
|
|
||||||
$('#aboutModal').modal({
|
|
||||||
//remote: 'about.mvc'
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
|||||||
/* ### GOAT DATA/PROMISES ### */
|
|
||||||
|
|
||||||
goat.data = {
|
|
||||||
/**** jQuery loads ... ****/
|
|
||||||
loadLessonContent: function ($http,_url) {
|
|
||||||
//TODO: switch to $http (angular) later
|
|
||||||
return $http({method:'GET', url: _url});
|
|
||||||
//return $.get(_url, {}, null, "html");
|
|
||||||
},
|
|
||||||
loadCookies: function($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.cookieService});
|
|
||||||
//return $.get(goatConstants.cookieService, {});
|
|
||||||
},
|
|
||||||
loadHints: function ($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.hintService});
|
|
||||||
//return $.get(goatConstants.hintService, {});
|
|
||||||
},
|
|
||||||
loadSource: function($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.sourceService});
|
|
||||||
//return $.get(goatConstants.sourceService, {});
|
|
||||||
},
|
|
||||||
loadSolution: function ($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.solutionService});
|
|
||||||
//return $.get(goatConstants.solutionService, {});
|
|
||||||
},
|
|
||||||
loadPlan: function ($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.lessonPlanService});
|
|
||||||
//return $.get(goatConstants.lessonPlanService, {});
|
|
||||||
},
|
|
||||||
loadParams: function($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.paramsService});
|
|
||||||
//return $.get(goatConstants.paramsService,{});
|
|
||||||
},
|
|
||||||
loadMenu: function($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.lessonService});
|
|
||||||
},
|
|
||||||
loadLessonTitle: function ($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.lessonTitleService});
|
|
||||||
},
|
|
||||||
loadRestart: function ($http) {
|
|
||||||
return $http({method: 'GET', url:goatConstants.restartLessonService})
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
@ -1,110 +0,0 @@
|
|||||||
// goat.lesson name space
|
|
||||||
goat.lesson = {
|
|
||||||
CurLesson: function(_lessonUrl) {
|
|
||||||
return {
|
|
||||||
hints:[],
|
|
||||||
hintIndex:0,
|
|
||||||
solution:null,
|
|
||||||
plan:null,
|
|
||||||
cookiesAndParams:[],
|
|
||||||
params:[],
|
|
||||||
source:null,
|
|
||||||
lessonUrl:(_lessonUrl || null),
|
|
||||||
clearInfo: function() {
|
|
||||||
this.hints = null;
|
|
||||||
this.solution = null;
|
|
||||||
this.plan = null;
|
|
||||||
this.cookies = null;
|
|
||||||
this.source = null;
|
|
||||||
this.params = null;
|
|
||||||
},
|
|
||||||
loadInfo: function() {
|
|
||||||
this.getHints();
|
|
||||||
this.getPlan();
|
|
||||||
this.getSolution();
|
|
||||||
this.getCookies();
|
|
||||||
this.getSource();
|
|
||||||
this.getParams();
|
|
||||||
},
|
|
||||||
getHints:function() {
|
|
||||||
var scope = this;
|
|
||||||
goat.data.loadHints().then(
|
|
||||||
function(resp) {
|
|
||||||
scope.hints = resp.data;
|
|
||||||
if (scope.hints.length > 0 && scope.hints[0].hint.indexOf(goatConstants.noHints) === -1) {
|
|
||||||
goat.utils.displayButton('showHintsBtn',true);
|
|
||||||
} else {
|
|
||||||
goat.utils.displayButton('showHintsBtn',false);
|
|
||||||
}
|
|
||||||
return scope;
|
|
||||||
},
|
|
||||||
function(err){
|
|
||||||
goat.utils.displayButton('showHintsBtn',false);
|
|
||||||
//TODO handle errors
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getSolution:function() {
|
|
||||||
var scope = this;
|
|
||||||
goat.data.loadSolution().then(
|
|
||||||
function(resp) {
|
|
||||||
scope.solution = resp.data;
|
|
||||||
goat.utils.displayButton('showSolutionBtn',true);
|
|
||||||
$('#showSolutionBtn').unbind().click(goat.utils.showLessonSolution);
|
|
||||||
return scope;
|
|
||||||
},
|
|
||||||
function(err){
|
|
||||||
scope.solution = null;
|
|
||||||
goat.utils.displayButton('showSolutionBtn',false);
|
|
||||||
//TODO handle errors
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getPlan: function() {
|
|
||||||
var scope = this;
|
|
||||||
goat.data.loadPlan().then(
|
|
||||||
function(resp) {
|
|
||||||
scope.plan = resp.data;
|
|
||||||
goat.utils.displayButton('showPlanBtn',true);
|
|
||||||
$('#showPlanBtn').unbind().click(goat.utils.showLessonPlan);
|
|
||||||
return scope;
|
|
||||||
},
|
|
||||||
function(err){
|
|
||||||
goat.utils.displayButton('showPlanBtn',false);
|
|
||||||
//TODO handle errors
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getSource: function() {
|
|
||||||
var scope = this;
|
|
||||||
goat.data.loadSource().then(
|
|
||||||
function(resp) {
|
|
||||||
scope.source = resp.data;
|
|
||||||
goat.utils.displayButton('showSourceBtn',true);
|
|
||||||
$('#showSourceBtn').unbind().click(goat.utils.showLessonSource);
|
|
||||||
return scope;
|
|
||||||
},
|
|
||||||
function(err){
|
|
||||||
goat.utils.displayButton('showSourceBtn',false);
|
|
||||||
//TODO handle errors
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getCookies: function() {
|
|
||||||
var scope = this;
|
|
||||||
goat.data.loadCookies().then(
|
|
||||||
function(resp) {
|
|
||||||
scope.cookies = resp.data;
|
|
||||||
return scope;
|
|
||||||
},
|
|
||||||
function(err){
|
|
||||||
//TODO handle errors
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getParams: function() {
|
|
||||||
this.params = goat.utils.scrapeParams(this.lessonUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,189 +0,0 @@
|
|||||||
goat.utils = {
|
|
||||||
//TODO add recursion to handle arr[i].children objects
|
|
||||||
// ... in case lower-level's need classes as well ... don't right now
|
|
||||||
addMenuClasses: function(arr) {
|
|
||||||
for (var i = 0; i < arr.length; i++) {
|
|
||||||
var menuItem = arr[i];
|
|
||||||
//console.log(menuItem);
|
|
||||||
if (menuItem.type && menuItem.type === 'CATEGORY') {
|
|
||||||
menuItem.class = 'fa-angle-right pull-right';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return arr;
|
|
||||||
},
|
|
||||||
debugFormSubmission: false,
|
|
||||||
// pre-submit callback
|
|
||||||
showRequest: function(formData, jqForm, options) {
|
|
||||||
if (goat.utils.debugFormSubmission) {
|
|
||||||
// formData is an array; here we use $.param to convert it to a string to display it
|
|
||||||
// but the form plugin does this for you automatically when it submits the data
|
|
||||||
var queryString = $.param(formData);
|
|
||||||
|
|
||||||
// jqForm is a jQuery object encapsulating the form element. To access the
|
|
||||||
// DOM element for the form do this:
|
|
||||||
// var formElement = jqForm[0];
|
|
||||||
|
|
||||||
alert('About to submit: \n\n' + queryString);
|
|
||||||
}
|
|
||||||
// here we could return false to prevent the form from being submitted;
|
|
||||||
// returning anything other than false will allow the form submit to continue
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
// post-submit callback
|
|
||||||
showResponse: function(responseText, statusText, xhr, $form) {
|
|
||||||
// for normal html responses, the first argument to the success callback
|
|
||||||
// is the XMLHttpRequest object's responseText property
|
|
||||||
|
|
||||||
// if the ajaxForm method was passed an Options Object with the dataType
|
|
||||||
// property set to 'xml' then the first argument to the success callback
|
|
||||||
// is the XMLHttpRequest object's responseXML property
|
|
||||||
|
|
||||||
// if the ajaxForm method was passed an Options Object with the dataType
|
|
||||||
// property set to 'json' then the first argument to the success callback
|
|
||||||
// is the json data object returned by the server
|
|
||||||
if (goat.utils.debugFormSubmission) {
|
|
||||||
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
|
|
||||||
'\n\nThe output div should have already been updated with the responseText.');
|
|
||||||
}
|
|
||||||
// update lesson cookies and params
|
|
||||||
// make any embedded forms ajaxy
|
|
||||||
goat.utils.showLessonCookiesAndParams();
|
|
||||||
// forms and links are now hooked with each standard lesson render (see Java class Screen.getContent())
|
|
||||||
// but these are safe to call twice
|
|
||||||
goat.utils.makeFormsAjax();
|
|
||||||
goat.utils.ajaxifyAttackHref(); //TODO find some way to hook scope for current menu. Likely needs larger refactor which is already started/stashed
|
|
||||||
//refresh menu
|
|
||||||
angular.element($('#leftside-navigation')).scope().renderMenu();
|
|
||||||
},
|
|
||||||
makeFormsAjax: function() {
|
|
||||||
// make all forms ajax forms
|
|
||||||
var options = {
|
|
||||||
target: '#lesson_content', // target element(s) to be updated with server response
|
|
||||||
beforeSubmit: goat.utils.showRequest, // pre-submit callback, comment out after debugging
|
|
||||||
success: goat.utils.showResponse // post-submit callback, comment out after debugging
|
|
||||||
|
|
||||||
// other available options:
|
|
||||||
//url: url // override for form's 'action' attribute
|
|
||||||
//type: type // 'get' or 'post', override for form's 'method' attribute
|
|
||||||
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
|
|
||||||
//clearForm: true // clear all form fields after successful submit
|
|
||||||
//resetForm: true // reset the form after successful submit
|
|
||||||
|
|
||||||
// $.ajax options can be used here too, for example:
|
|
||||||
//timeout: 3000
|
|
||||||
};
|
|
||||||
//console.log("Hooking any lesson forms to make them ajax");
|
|
||||||
$("form").ajaxForm(options);
|
|
||||||
},
|
|
||||||
displayButton: function(id, show) {
|
|
||||||
if ($('#' + id)) {
|
|
||||||
if (show) {
|
|
||||||
$('#' + id).show();
|
|
||||||
} else {
|
|
||||||
$('#' + id).hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
showLessonCookiesAndParams: function() {
|
|
||||||
$.get(goatConstants.cookieService, {}, function(reply) {
|
|
||||||
$("#lesson_cookies").html(reply);
|
|
||||||
}, "html");
|
|
||||||
},
|
|
||||||
showLessonHints: function() {
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
$('#lesson_hint').html();
|
|
||||||
$('#lesson_hint_row').show();
|
|
||||||
},
|
|
||||||
showLessonSource: function(source) {
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
//$('#lesson_source').html("<pre>"+goat.lesson.lessonInfo.source+"</pre>");
|
|
||||||
$('#lesson_source_row').show();
|
|
||||||
goat.utils.scrollToHelp();
|
|
||||||
},
|
|
||||||
showLessonSolution: function() {
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
$('#lesson_solution').html(goat.lesson.lessonInfo.solution);
|
|
||||||
$('#lesson_solution_row').show();
|
|
||||||
goat.utils.scrollToHelp();
|
|
||||||
},
|
|
||||||
showLessonPlan: function(plan) {
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
$("#lesson_plan").html(goat.lesson.lessonInfo.plan);
|
|
||||||
$('#lesson_plan_row').show();
|
|
||||||
goat.utils.scrollToHelp();
|
|
||||||
},
|
|
||||||
scrollToHelp: function() {
|
|
||||||
$('#leftside-navigation').height($('#main-content').height() + 15)
|
|
||||||
var target = $('#lessonHelpsWrapper');
|
|
||||||
goat.utils.scrollEasy(target);
|
|
||||||
},
|
|
||||||
scrollToTop: function() {
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
var target = $('#container');
|
|
||||||
goat.utils.scrollEasy(target);
|
|
||||||
},
|
|
||||||
scrollEasy: function(target) {
|
|
||||||
$('html,body').animate({
|
|
||||||
scrollTop: target.offset().top
|
|
||||||
}, 1000);
|
|
||||||
},
|
|
||||||
scrapeParams: function(url) {
|
|
||||||
if (!url) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var params = url.split('?')[1].split('&');
|
|
||||||
var paramsArr = [];
|
|
||||||
for (var i = 0; i < params.length; i++) {
|
|
||||||
var paramObj = {};
|
|
||||||
paramObj.name = params[i].split('=')[0];
|
|
||||||
paramObj.value = params[i].split('=')[1];
|
|
||||||
paramsArr.push(paramObj);
|
|
||||||
}
|
|
||||||
return paramsArr;
|
|
||||||
},
|
|
||||||
highlightCurrentLessonMenu: function(id) {
|
|
||||||
//TODO: move selectors in first two lines into goatConstants
|
|
||||||
$('ul li.selected').removeClass(goatConstants.selectedMenuClass)
|
|
||||||
$('ul li.selected a.selected').removeClass(goatConstants.selectedMenuClass)
|
|
||||||
$('#' + id).addClass(goatConstants.selectedMenuClass);
|
|
||||||
$('#' + id).parent().addClass(goatConstants.selectedMenuClass);
|
|
||||||
},
|
|
||||||
makeId: function(lessonName) {
|
|
||||||
return lessonName.replace(/\s|\(|\)|\!|\:|\;|\@|\#|\$|\%|\^|\&|\*/g, '');//TODO move the replace routine into util function
|
|
||||||
},
|
|
||||||
ajaxifyAttackHref: function() {
|
|
||||||
/* Jason I commented this implementation out
|
|
||||||
* I think we should show the attack link on the lessons that need it by modifying the lesson
|
|
||||||
* itself or we could add a new button up top for "show lesson link"
|
|
||||||
$.each($('a[href^="attack?"]'),
|
|
||||||
function(i,el) {
|
|
||||||
var url = $(el).attr('href');
|
|
||||||
$(el).attr('href','#');
|
|
||||||
$(el).attr('link',url);
|
|
||||||
//TODO pull currentMenuId
|
|
||||||
$(el).click(
|
|
||||||
function() {
|
|
||||||
var _url = $(el).attr('link');
|
|
||||||
$.get(_url, {success:showResponse});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
// alternate implementation
|
|
||||||
// unbind any bound events so we are safe to be called twice
|
|
||||||
$('#lesson_content a').unbind('click');
|
|
||||||
$('#lesson_content a').bind('click', function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
$.get(this.href, {}, function(response) {
|
|
||||||
$('#lesson_content').html(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
$(window).resize(function() {
|
|
||||||
//$('#leftside-navigation').css('height',$('div.panel-body').height());
|
|
||||||
console.log($(window).height());
|
|
||||||
});
|
|
@ -15,7 +15,7 @@ require.config({
|
|||||||
paths: {
|
paths: {
|
||||||
jquery: 'libs/jquery-1.10.2.min',
|
jquery: 'libs/jquery-1.10.2.min',
|
||||||
underscore: 'libs/underscore-min',
|
underscore: 'libs/underscore-min',
|
||||||
backbone: 'libs/backbone-min'//,
|
backbone: 'libs/backbone-min'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
shim: {
|
shim: {
|
||||||
@ -30,8 +30,5 @@ require.config({
|
|||||||
});
|
});
|
||||||
|
|
||||||
require(['jquery','underscore','backbone','goatApp/goatApp'], function($,_,Backbone,Goat){
|
require(['jquery','underscore','backbone','goatApp/goatApp'], function($,_,Backbone,Goat){
|
||||||
|
|
||||||
Goat.initApp();
|
Goat.initApp();
|
||||||
//var lessonController = new LessonController();
|
|
||||||
|
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user