incremental progress on new UI code, mod to AbstractLesson for menu

This commit is contained in:
Jason White
2015-05-12 22:32:56 -04:00
parent 53c4ffc1cf
commit 8aa4b8109f
17 changed files with 5061 additions and 41 deletions

View File

@ -4,7 +4,7 @@ define(['jquery',
'goatApp/model/LessonContentData',
'goatApp/view/LessonContentView'
],
function($,_,Backbone,LessonContent) {
function($,_,Backbone,LessonContentData,LessonContentView) {
'use strict'
@ -12,14 +12,15 @@ define(['jquery',
this.lessonView = options.lessonView;
this.lessonContent = new LessonContentData();
_.extend(this,Backbone.Events);
_.extend(Controller.prototype,Backbone.Events);
this.start = function() {
this.listenTo(this.lessonContent,'contentLoaded',this.onContentLoaded);
}
//load View, which can pull data
this.loadLesson = function(scr,menu) {
this.lessonContent.loadContent({
this.lessonContent.loadData({
'screen': encodeURIComponent(scr),
'menu': encodeURIComponent(menu),
});
@ -29,8 +30,19 @@ define(['jquery',
this.onContentLoaded = function() {
//this.lessonView = new LessonContentView({content:LessonContent.content});
//this.lessonView.render();
console.debug('loading other stuff');
this.lessonView.model = this.lessonContent;
this.lessonView.render();
//load cookies/parameters view
//load help view
//load title
//plan
//solution
//source
}
};

View File

@ -1,4 +1,17 @@
define(['jquery','underscore','backbone','goatApp/model/MenuData','goatApp/view/MenuView'],
function($,_,Backbone,MenuData,MenuView) {
define(['jquery','underscore','backbone','goatApp/view/MenuView'],
function($,_,Backbone,MenuView) {
Controller = function(options){
options = options || {};
this.menuView = options.menuView;
this.initMenu = function() {
console.debug('initing menu');
}
this.updateMenu = function() {
}
};
return Controller;
});

View File

@ -1,13 +1,13 @@
define(['jquery','underscore','backbone','goatApp/view/goatRouter','goatApp/controller/LessonController','goatApp/controller/MenuController'],
function($,_,Backbone,Router,LessonController,MenuController){
define(['jquery','underscore','backbone','goatApp/view/GoatRouter'],
function($,_,Backbone,Router){
'use strict'
//var goatRouter = new Router();
return {
initApp: function() {
//TODO: add query/ability to load from where they left off
console.log('initApp')
//Router.init();
var goatRouter = new Router();
goatRouter.init();
}
}
};
});

View File

@ -1,4 +1,7 @@
define(['jquery', 'underscore','backbone'], function($,_,Backbone){
define(['jquery',
'underscore',
'backbone'],
function($,_,Backbone){
return Backbone.Model.extend({
urlRoot:null,
@ -11,12 +14,36 @@ define(['jquery', 'underscore','backbone'], function($,_,Backbone){
},
loadData: function(options) {
this.urlRoot = this.baseUrlRoot + +options.screen + '&menu=' + options.menu;
var self = this;
this.fetch().then(function(content){
alert('content loaded');
self.content = content;
self.trigger('contentLoaded');
var self=this;
this.fetch().then(function(data) {
self.setContent(data);
});
// success: function(content) {
// console.log("content:" + content);
// },
// error: function(err) {
// console.log("error:" + err);
// },
// done: function(a,b) {
// console.log(a);
// console.log(b);
// }
// });
},
setContent: function(content) {
this.set('content',content);
this.trigger('contentLoaded');
},
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
}
});
});

View File

@ -0,0 +1,21 @@
define(['jquery',
'underscore',
'backbone',
'goatApp/model/MenuItemModel'],
function($,_,Backbone,MenuItemModel) {
return Backbone.Collection.extend({
model: MenuItemModel,
url:'service/lessonmenu.mvc',
initialize: function () {
var self = this;
this.fetch().then(function (data) {
this.models = data;
self.onDataLoaded();
});
},
onDataLoaded:function() {
this.trigger('menuData:loaded');
}
});
});

View File

@ -0,0 +1,51 @@
define(['jquery',
'underscore',
'backbone'],
function($,_,Backbone) {
return Backbone.Model.extend({
});
});
// accordionMenu = function(id) {
// if ($('ul#' + id).attr('isOpen') == 0) {
// $scope.expandMe = true;
// } else {
// $('ul#' + id).slideUp(300).attr('isOpen', 0);u
// return;
// }
// $scope.openMenu = id;
// $('.lessonsAndStages').not('ul#' + id).slideUp(300).attr('isOpen', 0);
// if ($scope.expandMe) {
// $('ul#' + id).slideDown(300).attr('isOpen', 1);
// }
// }
//urlRoot:'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;
// }
// });

View File

@ -0,0 +1,46 @@
define(['jquery',
'underscore',
'backbone',
'goatApp/controller/LessonController',
'goatApp/controller/MenuController',
'goatApp/view/LessonContentView',
'goatApp/view/MenuView'
], function ($,_,Backbone,LessonController,MenuController,LessonContentView,MenuView) {
var lessonView = new LessonContentView();
var menuView = new MenuView();
var GoatAppRouter = Backbone.Router.extend({
routes: {
//#....
'welcome':'welcomeRoute',
'attack/:scr/:menu':'attackRoute' //
},
lessonController: new LessonController({
lessonView:lessonView
}),
menuController: new MenuController({
menuView:menuView
}),
init:function() {
goatRouter = new GoatAppRouter();
this.lessonController.start();
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
});
goatRouter.on('route:welcomeRoute', function() {
alert('welcome route');
});
Backbone.history.start();
}
});
return GoatAppRouter;
});

View File

@ -4,22 +4,16 @@ define(['jquery',
'backbone',
'goatApp/model/LessonContentData'],
function($,_,Backbone,LessonData) {
var contentView = Backbone.View.extend({
el:'#lessonContent',
return Backbone.View.extend({
el:'#lessonContentWrapper', //TODO << get this fixed up in DOM
initialize: function(options) {
//this.content = options.content;
this.lessonData = {};
this.listenTo(this.lessonData,'sync',this.render);
},
loadLesson: function(options) {
this.lessonData = new LessonData(options.screen,options.menu);
options = options || {};
},
render: function() {
alert('render');
this.$el.html(this.content);
//alert('render');
this.$el.html(this.model.get('content'));
}
});
return contentView;
});

View File

@ -0,0 +1,14 @@
define(['jquery',
'underscore',
'backbone'], function($,_,Backbone) {
return Backbone.View.extend({
initialize: function(options) {
options = options || {};
}
});
});

View File

@ -1,12 +1,19 @@
define(['jquery','underscore','backbone','goatApp/model/MenuData'], function($,_,Backbone,MenuData) {
define(['jquery',
'underscore',
'backbone',
'goatApp/model/MenuItemCollection'],
function($,_,Backbone,MenuItemCollection) {
return Backbone.View.extend({
el:'#menuContainer',
//TODO: set template
initialize: function() {
this.collection = new MenuItemCollection();
this.listenTo(this.collection,'menuData:loaded',this.render);
},
render: function (model){
//TODO: implement own HTML Encoder
this.$el.html(buildMenu(items));
this.$el.html('render ' + this.collection.length + ' items');//buildMenu(items)
},
buildMenu: function(items) {
@ -44,6 +51,7 @@ define(['jquery','underscore','backbone','goatApp/model/MenuData'], function($,_
$(goatConstants.getDOMContainers().lessonMenu).html('').append($wholeMenu);
};
}
},
});
});