Skip to content
Permalink
Browse files

Tutorial part 5

  • Loading branch information...
Alex Young
Alex Young committed Dec 27, 2012
1 parent fcd653e commit 82fe08ebff2cbc71350870dcd1a2c1b49f57f22d
Showing with 65 additions and 6 deletions.
  1. +4 −6 app/js/app.js
  2. +1 −0 app/js/templates/lists/menuitem.html
  3. +29 −0 app/js/views/lists/menu.js
  4. +31 −0 app/js/views/lists/menuitem.js
@@ -2,18 +2,18 @@ define([
'gapi'
, 'views/app'
, 'views/auth'
, 'views/lists/menu'
, 'collections/tasklists'
],

function(ApiManager, AppView, AuthView, TaskLists) {
function(ApiManager, AppView, AuthView, ListMenuView, TaskLists) {
var App = function() {
this.views.app = new AppView();
this.views.app.render();

this.views.auth = new AuthView(this);
this.views.auth.render();

this.collections.lists = new TaskLists();
this.views.listMenu = new ListMenuView({ collection: this.collections.lists });

this.connectGapi();
};
@@ -26,9 +26,7 @@ function(ApiManager, AppView, AuthView, TaskLists) {
this.apiManager = new ApiManager(this);
this.apiManager.on('ready', function() {
self.collections.lists.fetch({ data: { userId: '@me' }, success: function(res) {
_.each(res.models, function(model) {
console.log(model.get('title'));
});
self.views.listMenu.render();
}});
});
}
@@ -0,0 +1 @@
<a href="#" class="list-title" data-list-id="{{id}}">{{title}}</a>
@@ -0,0 +1,29 @@
define(['views/lists/menuitem'], function(ListMenuItemView) {
var ListMenuView = Backbone.View.extend({
el: '.left-nav',
tagName: 'ul',
className: 'nav nav-list lists-nav',

events: {
},

initialize: function() {
this.collection.on('add', this.render, this);
},

render: function() {
var $el = $(this.el)
, self = this;

this.collection.each(function(list) {
var item, sidebarItem;
item = new ListMenuItemView({ model: list });
$el.append(item.render().el);
});

return this;
}
});

return ListMenuView;
});
@@ -0,0 +1,31 @@
define(['text!templates/lists/menuitem.html'], function(template) {
var ListMenuItemView = Backbone.View.extend({
tagName: 'li',
className: 'list-menu-item',

template: _.template(template),

events: {
'click': 'open'
},

initialize: function() {
this.model.on('change', this.render, this);
this.model.on('destroy', this.remove, this);
},

render: function() {
var $el = $(this.el);
$el.data('listId', this.model.get('id'));
$el.html(this.template(this.model.toJSON()));
return this;
},

open: function() {
var self = this;
return false;
}
});

return ListMenuItemView;
});

0 comments on commit 82fe08e

Please sign in to comment.
You can’t perform that action at this time.