diff --git a/src/main/webapp/js/goatApp/controller/LessonController.js b/src/main/webapp/js/goatApp/controller/LessonController.js index a7cc41e43..baca5e707 100644 --- a/src/main/webapp/js/goatApp/controller/LessonController.js +++ b/src/main/webapp/js/goatApp/controller/LessonController.js @@ -2,20 +2,34 @@ define(['jquery', 'underscore', 'libs/backbone', 'goatApp/model/LessonContentData', - 'goatApp/view/LessonContentView' + 'goatApp/view/LessonContentView', + 'goatApp/view/PlanView', + 'goatApp/view/SourceView', + 'goatApp/view/SolutionView', ], - function($,_,Backbone,LessonContentData,LessonContentView) { + function($, + _, + Backbone, + LessonContentData, + LessonContentView, + PlanView, + SourceView, + SolutionView + ) { 'use strict' var Controller = function(options) { - this.lessonView = options.lessonView; this.lessonContent = new LessonContentData(); + this.lessonView = options.lessonView; + /*this.planView = new PlanView(); + this.solutionView = new SolutionView(); + this.sourceView = new SourceView(); + */ _.extend(Controller.prototype,Backbone.Events); this.start = function() { this.listenTo(this.lessonContent,'contentLoaded',this.onContentLoaded); - } //load View, which can pull data @@ -35,14 +49,13 @@ define(['jquery', //load cookies/parameters view - //load title view (initially hidden) - + //load title view (initially hidden) << currently handled via menu click but need to be able to handle via routed request //plan view (initially hidden) - + this.planView = new PlanView(); //solution view (initially hidden) - + this.solutionView = new SolutionView(); //source (initially hidden) - + this.sourceView = new SourceView(); //load help controls view (contextul to what helps are available) } diff --git a/src/main/webapp/js/goatApp/model/HTMLContentModel.js b/src/main/webapp/js/goatApp/model/HTMLContentModel.js new file mode 100644 index 000000000..78803d463 --- /dev/null +++ b/src/main/webapp/js/goatApp/model/HTMLContentModel.js @@ -0,0 +1,27 @@ +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(); + } + }); +}); \ No newline at end of file diff --git a/src/main/webapp/js/goatApp/model/LessonContentData.js b/src/main/webapp/js/goatApp/model/LessonContentData.js index 2f35df9c4..4a1002657 100644 --- a/src/main/webapp/js/goatApp/model/LessonContentData.js +++ b/src/main/webapp/js/goatApp/model/LessonContentData.js @@ -1,9 +1,13 @@ define(['jquery', 'underscore', - 'backbone'], - function($,_,Backbone){ + 'backbone', + 'goatApp/model/HTMLContentModel'], + function($, + _, + Backbone, + HTMLContentModel){ - return Backbone.Model.extend({ + return HTMLContentModel.extend({ urlRoot:null, defaults: { items:null, @@ -15,7 +19,7 @@ define(['jquery', this.baseUrlRoot = 'attack?Screen=';// }, loadData: function(options) { - this.urlRoot = this.baseUrlRoot + +options.screen + '&menu=' + options.menu; + this.urlRoot = this.baseUrlRoot +options.screen + '&menu=' + options.menu; this.set('menuParam',options.menu); this.set('screenParam',options.screen); @@ -31,13 +35,6 @@ define(['jquery', fetch: function (options) { options = options || {}; return Backbone.Model.prototype.fetch.call(this, _.extend({ dataType: "html"}, options)); - // var self=this; - // Backbone.Model.prototype.fetch.apply(this, arguments).then( - // function(content){ - // self.setContent(content); - // }); - - // //override with prototype } }); }); \ 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 new file mode 100644 index 000000000..1fc56320b --- /dev/null +++ b/src/main/webapp/js/goatApp/model/LessonPlanModel.js @@ -0,0 +1,19 @@ +define(['jquery', + 'underscore', + 'backbone', + 'goatApp/model/HTMLContentModel'], + function($, + _, + Backbone, + HTMLContentModel) { + //TODO: make a base class to extend for items with 'traditional data' (e.g. LessonContentData, this ... others?) + return HTMLContentModel.extend({ + url:'service/lessonplan.mvc', + checkNullModel: function() { + if (this.get('content').indexOf('Plan is not available for this lesson.') > -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 new file mode 100644 index 000000000..ef249864d --- /dev/null +++ b/src/main/webapp/js/goatApp/model/LessonSolutionModel.js @@ -0,0 +1,18 @@ +define(['jquery', + 'underscore', + 'backbone', + 'goatApp/model/HTMLContentModel'], + function($, + _, + Backbone, + HTMLContentModel) { + return HTMLContentModel.extend({ + url:'service/solution.mvc', + checkNullModel: function() { + if (this.get('content').indexOf('Solution is not available. Contact') === 0) { + this.set('content',null); + } + } + + }); +}); \ No newline at end of file diff --git a/src/main/webapp/js/goatApp/model/LessonSourceModel.js b/src/main/webapp/js/goatApp/model/LessonSourceModel.js new file mode 100644 index 000000000..6e0b054a9 --- /dev/null +++ b/src/main/webapp/js/goatApp/model/LessonSourceModel.js @@ -0,0 +1,19 @@ +define(['jquery', + 'underscore', + 'backbone', + 'goatApp/model/HTMLContentModel'], + function($, + _, + Backbone, + HTMLContentModel) { + return HTMLContentModel.extend({ + 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) { + this.set('content',null); + } + } + + }); +}); \ No newline at end of file diff --git a/src/main/webapp/js/goatApp/view/HelpControlsView.js b/src/main/webapp/js/goatApp/view/HelpControlsView.js new file mode 100644 index 000000000..6917085b1 --- /dev/null +++ b/src/main/webapp/js/goatApp/view/HelpControlsView.js @@ -0,0 +1,11 @@ +define(['jquery', + 'underscore', + 'backbone'], +function($,_,Backbone) { + return Backbone.View.extend({ + el:'#lessonHelp', //Check this + render:function(title) { + + } + }); +}); \ 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 b7df3f83a..cdfda57d7 100644 --- a/src/main/webapp/js/goatApp/view/LessonContentView.js +++ b/src/main/webapp/js/goatApp/view/LessonContentView.js @@ -11,7 +11,6 @@ function($,_,Backbone,JQueryForm,LessonData) { options = options || {}; }, render: function() { - //alert('render'); this.$el.html(this.model.get('content')); this.makeFormsAjax(); }, diff --git a/src/main/webapp/js/goatApp/view/MenuView.js b/src/main/webapp/js/goatApp/view/MenuView.js index b723a25f4..e4956ed63 100644 --- a/src/main/webapp/js/goatApp/view/MenuView.js +++ b/src/main/webapp/js/goatApp/view/MenuView.js @@ -75,7 +75,6 @@ define(['jquery', } }, triggerTitleRender: function (title) { - console.debug('title:'+title); this.trigger('lesson:click',title); }, expandCategory: function (id) { @@ -86,17 +85,12 @@ define(['jquery', 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; } - this.openMenu = id; - this.$el.find('.lessonsAndStages').not('ul#' + id).slideUp(300); - /* //legacy angular code that may be usefl - if ($scope.expandMe) { - $('ul#' + id).slideDown(300).attr('isOpen', 1); - } - */ } }); }); \ No newline at end of file diff --git a/src/main/webapp/js/goatApp/view/PlanView.js b/src/main/webapp/js/goatApp/view/PlanView.js new file mode 100644 index 000000000..bf0befaef --- /dev/null +++ b/src/main/webapp/js/goatApp/view/PlanView.js @@ -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() { + // ??? + } + }); +}); \ No newline at end of file diff --git a/src/main/webapp/js/goatApp/view/SolutionView.js b/src/main/webapp/js/goatApp/view/SolutionView.js new file mode 100644 index 000000000..e7564ca2c --- /dev/null +++ b/src/main/webapp/js/goatApp/view/SolutionView.js @@ -0,0 +1,20 @@ +define(['jquery', + 'underscore', + 'backbone', + 'goatApp/model/LessonSolutionModel'], +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(); + }, + render:function(title) { + + }, + onModelLoaded: function() { + // ??? + } + }); +}); \ No newline at end of file diff --git a/src/main/webapp/js/goatApp/view/SourceView.js b/src/main/webapp/js/goatApp/view/SourceView.js new file mode 100644 index 000000000..338300b56 --- /dev/null +++ b/src/main/webapp/js/goatApp/view/SourceView.js @@ -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() { + // ??? + } + }); +}); \ No newline at end of file