diff --git a/src/main/webapp/WEB-INF/pages/main_new.jsp b/src/main/webapp/WEB-INF/pages/main_new.jsp index f0ab6621c..3448a872e 100644 --- a/src/main/webapp/WEB-INF/pages/main_new.jsp +++ b/src/main/webapp/WEB-INF/pages/main_new.jsp @@ -98,29 +98,21 @@
' + this.sourceView.model.get('content') + ''); break; } + $(showId).show(); GoatUtils.scrollToHelp() - };; + }; - this.showHints = function() { - console.log('show Hints'); + this.onShowHints = function() { + this.lessonHintView.render(); }; this.restartLesson = function() { - console.log('restart lesson'); + self=this; + $.ajax({ + url:'service/restartlesson.mvc', + method:'GET' + }).then(function() { + self.loadLesson(self.screen,self.menu); + }); }; }; diff --git a/src/main/webapp/js/goatApp/controller/MenuController.js b/src/main/webapp/js/goatApp/controller/MenuController.js index abe675dde..a8c154b50 100644 --- a/src/main/webapp/js/goatApp/controller/MenuController.js +++ b/src/main/webapp/js/goatApp/controller/MenuController.js @@ -10,7 +10,7 @@ define(['jquery','underscore','backbone','goatApp/view/MenuView'], this.listenTo(this.menuView,'lesson:click',this.renderTitle); } - this.updateMenu = function() { + this.updateMenu = function(curLesson) { }, diff --git a/src/main/webapp/js/goatApp/model/HTMLContentModel.js b/src/main/webapp/js/goatApp/model/HTMLContentModel.js index 78803d463..fd5ac05f5 100644 --- a/src/main/webapp/js/goatApp/model/HTMLContentModel.js +++ b/src/main/webapp/js/goatApp/model/HTMLContentModel.js @@ -2,26 +2,24 @@ define(['jquery', 'underscore', 'backbone'], function($,_,Backbone) { - //TODO: make a base class to extend for items with 'traditional data' (e.g. LessonContentData, this ... others?) return Backbone.Model.extend({ //url:'service/lessonplan.mvc', fetch: function (options) { options = options || {}; return Backbone.Model.prototype.fetch.call(this, _.extend({ dataType: "html"}, options)); }, + loadData: function() { var self=this; this.fetch().then(function(data) { self.setContent(data); - self.onModelLoaded(); }); }, + setContent: function(content) { this.set('content',content); - this.trigger('loaded'); - }, - onModelLoaded: function() { this.checkNullModel(); + this.trigger('loaded'); } }); }); \ No newline at end of file diff --git a/src/main/webapp/js/goatApp/model/LessonHintCollection.js b/src/main/webapp/js/goatApp/model/LessonHintCollection.js index dd64fea6d..24a59aab5 100644 --- a/src/main/webapp/js/goatApp/model/LessonHintCollection.js +++ b/src/main/webapp/js/goatApp/model/LessonHintCollection.js @@ -2,23 +2,31 @@ define(['jquery', 'underscore', 'backbone', 'goatApp/model/LessonHintModel'], - function($,_,Backbone,LessonHintModel) { + + function($, + _, + Backbone, + LessonHintModel) { + return Backbone.Collection.extend({ + model: LessonHintModel, + url:'service/hint.mvc', + initialize: function () { + var self = this; + this.fetch().then(function (data) { + this.models = data; + self.onDataLoaded(); + }); + }, - return Backbone.Collection.extend({ - model: LessonHintModel, - url:'service/hint.mvc', - initialize: function () { - var self = this; - this.fetch().then(function (data) { - this.models = data; - self.onDataLoaded(); - }); - }, - onDataLoaded:function() { - this.trigger('hints:loaded');//copied over as boiler-plate ... use this event trigger? - }, - checkNullModel:function() { - // - } - }); + onDataLoaded:function() { + this.trigger('loaded'); + }, + + checkNullModel:function() { + if (this.models[0].indexOf('There are no hints defined.') > -1) { + this.reset([]); + //return this.models; + } + } + }); }); \ No newline at end of file diff --git a/src/main/webapp/js/goatApp/model/LessonPlanModel.js b/src/main/webapp/js/goatApp/model/LessonPlanModel.js index 88a3cc15a..7f23e8a46 100644 --- a/src/main/webapp/js/goatApp/model/LessonPlanModel.js +++ b/src/main/webapp/js/goatApp/model/LessonPlanModel.js @@ -9,10 +9,9 @@ define(['jquery', return HTMLContentModel.extend({ url:'service/lessonplan.mvc', checkNullModel: function() { - if (this.get('content').indexOf('Plan is not available for this lesson.') > -1) { + if (this.get('content').indexOf('Could not find lesson plan for') > -1) { this.set('content',null); } } - }); }); \ No newline at end of file diff --git a/src/main/webapp/js/goatApp/model/LessonSolutionModel.js b/src/main/webapp/js/goatApp/model/LessonSolutionModel.js index ef249864d..b7b7561ce 100644 --- a/src/main/webapp/js/goatApp/model/LessonSolutionModel.js +++ b/src/main/webapp/js/goatApp/model/LessonSolutionModel.js @@ -9,7 +9,7 @@ define(['jquery', return HTMLContentModel.extend({ url:'service/solution.mvc', checkNullModel: function() { - if (this.get('content').indexOf('Solution is not available. Contact') === 0) { + if (this.get('content').indexOf('Could not find the solution file or solution file does not exist') === 0) { this.set('content',null); } } diff --git a/src/main/webapp/js/goatApp/model/LessonSourceModel.js b/src/main/webapp/js/goatApp/model/LessonSourceModel.js index 6e0b054a9..e6fc08625 100644 --- a/src/main/webapp/js/goatApp/model/LessonSourceModel.js +++ b/src/main/webapp/js/goatApp/model/LessonSourceModel.js @@ -10,7 +10,7 @@ define(['jquery', url:'service/source.mvc', checkNullModel: function () { //TODO: move this function into HTMLContentModel and make the string a property of this 'child' model - if (this.get('content').indexOf("No source listing found") > -1) { + if (this.get('content').indexOf("Could not find the source file or") > -1) { this.set('content',null); } } diff --git a/src/main/webapp/js/goatApp/view/GoatRouter.js b/src/main/webapp/js/goatApp/view/GoatRouter.js index 7d4dda3d8..d0ecb94c4 100644 --- a/src/main/webapp/js/goatApp/view/GoatRouter.js +++ b/src/main/webapp/js/goatApp/view/GoatRouter.js @@ -18,9 +18,11 @@ define(['jquery', 'welcome':'welcomeRoute', 'attack/:scr/:menu':'attackRoute' // }, + lessonController: new LessonController({ lessonView:lessonView }), + menuController: new MenuController({ menuView:menuView, titleView:titleView @@ -32,7 +34,6 @@ define(['jquery', this.menuController.initMenu(); goatRouter.on('route:attackRoute', function(scr,menu) { - console.log('attack route'); this.lessonController.loadLesson(scr,menu); this.menuController.updateMenu(scr,menu); //update menu @@ -42,7 +43,14 @@ define(['jquery', }); Backbone.history.start(); + this.listenTo('menu:reload',this.reloadMenu) + }, + + reloadMenu: function (curLesson) { + this.menuController.updateMenu(curLesson); } + + }); return GoatAppRouter; diff --git a/src/main/webapp/js/goatApp/view/HelpControlsView.js b/src/main/webapp/js/goatApp/view/HelpControlsView.js index 347ad8ae1..2c331e728 100644 --- a/src/main/webapp/js/goatApp/view/HelpControlsView.js +++ b/src/main/webapp/js/goatApp/view/HelpControlsView.js @@ -22,6 +22,8 @@ function($,_,Backbone) { 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); @@ -38,7 +40,8 @@ function($,_,Backbone) { 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); }, @@ -56,6 +59,9 @@ function($,_,Backbone) { showHints: function() { this.trigger('hints:show','hints'); + }, + restartLesson: function() { + this.trigger('lesson:restart'); } }); }); \ No newline at end of file diff --git a/src/main/webapp/js/goatApp/view/LessonContentView.js b/src/main/webapp/js/goatApp/view/LessonContentView.js index cdfda57d7..77592a742 100644 --- a/src/main/webapp/js/goatApp/view/LessonContentView.js +++ b/src/main/webapp/js/goatApp/view/LessonContentView.js @@ -6,7 +6,7 @@ define(['jquery', 'goatApp/model/LessonContentData'], function($,_,Backbone,JQueryForm,LessonData) { return Backbone.View.extend({ - el:'#lessonContentWrapper', //TODO << get this fixed up in DOM + el:'#lesson-content-wrapper', //TODO << get this fixed up in DOM initialize: function(options) { options = options || {}; }, diff --git a/src/main/webapp/js/goatApp/view/LessonHintView.js b/src/main/webapp/js/goatApp/view/LessonHintView.js index e61b086d5..63971b938 100644 --- a/src/main/webapp/js/goatApp/view/LessonHintView.js +++ b/src/main/webapp/js/goatApp/view/LessonHintView.js @@ -7,16 +7,65 @@ function($, Backbone, LessonHintCollection) { return Backbone.View.extend({ - el:'#lessonHelpWrapper .lessonHelp.lessonHint', - initialize: function() { - this.collection = new LessonHintCollection(); - this.listenTo(this.collection,'hints:loaded',this.onModelLoaded); + el:'#lesson-hint-container', + events: { + "click #show-next-hint": "showNextHint", + "click #show-prev-hint": "showPrevHint" }, - render:function(title) { + 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'); + } } + }); }); \ No newline at end of file diff --git a/src/main/webapp/js/goatApp/view/MenuView.js b/src/main/webapp/js/goatApp/view/MenuView.js index e4956ed63..5ea5cafd2 100644 --- a/src/main/webapp/js/goatApp/view/MenuView.js +++ b/src/main/webapp/js/goatApp/view/MenuView.js @@ -49,18 +49,24 @@ define(['jquery', for (var j=0; j < lessons.length;j++) { var lessonItem = $('