Permalink
Browse files

began adding sort by date

  • Loading branch information...
1 parent cb6af07 commit 57ceed73e852b28d14ffb36528e08a3b4dc72885 @boazsender boazsender committed Mar 19, 2012
View
@@ -21,16 +21,18 @@ function(epp, jQuery, Backbone, Email) {
},
index: function() {
- var emails = new Email.DateCollection();
+ var emails = new Email.Collection();
window.emails = emails;
emails.fetch().success(function(){
var main = new Backbone.LayoutManager({
template: 'main',
views: {
- '#sidebar': new Email.Views.Sidebar()
+ '#sidebar': new Email.Views.Sidebar({ model: emails })
}
});
+
+ window.main = main;
// Render the navigation
var nav = main.view('#mainnav', new Email.Views.Nav(), true);
@@ -45,8 +47,8 @@ function(epp, jQuery, Backbone, Email) {
senders.add({
id: email.get('fromemail'),
name: email.get('fromname'),
- read: new Email.DateCollection(),
- unread: new Email.DateCollection()
+ read: new Email.Collection(),
+ unread: new Email.Collection()
});
// if the current email is unread, create a new unread collection for it
@@ -67,20 +69,31 @@ function(epp, jQuery, Backbone, Email) {
}
}
});
-
+
senders.each(function( sender ){
main.views['#sidebar'].view("#sidebarlist", new Email.Views.SidebarItemSender({ model: sender}), true);
});
-
+
+ // not working:
+ app.bind('sortbydate', function( emails ){
+ emails.each(function( email ){
+ main.views['#sidebar'].view("#sidebarlist", new Email.Views.SidebarItemDate({ model: email}), true);
+ });
+ });
+
+
app.bind('showbody', function( model){
var reader = main.view('#reader', new Email.Views.Reader({ model: model }));
reader.render();
});
app.bind('showsendermail', function( model ){
model.get('unread').each(function( email ){
- var sidebarItem = main.view('#' + model.cid, new Email.Views.SidebarItem({ model: email }));
- sidebarItem.render();
+ main
+ .views['#sidebar']
+ .view('#sidebarlist #' + model.cid, new Email.Views.SidebarItem({ model: email }))
+ .render();
+
});
});
View
@@ -18,7 +18,7 @@ function(epp, Backbone) {
// Email extendings
Email.Model = Backbone.Model.extend({});
- Email.DateCollection = Backbone.Collection.extend({
+ Email.Collection = Backbone.Collection.extend({
url: '/assets/data/email.json',
comparator: function(chapter) {
return chapter.get("date");
@@ -36,8 +36,8 @@ function(epp, Backbone) {
}
});
- Email.Views.SidebarItems = Backbone.View.extend({
- tagName: 'li',
+ Email.Views.SidebarItem = Backbone.View.extend({
+ tagName: 'ul',
className: 'btn',
template: 'email/sidebaritem',
events: {
@@ -64,21 +64,58 @@ function(epp, Backbone) {
}
});
+ Email.Views.SidebarItemDate = Backbone.View.extend({
+ tagName: 'li',
+ className: 'btn',
+ template: 'email/sidebaritem',
+ events: {
+ "click": function(){
+ app.trigger('showbody', this.model);
+ }
+ },
+ serialize: function() {
+ return { email: this.model };
+ }
+ });
+
Email.Views.Sidebar = Backbone.View.extend({
- template: 'email/sidebar'
+ template: 'email/sidebar',
+ events: {
+ "click .sender": function(){
+ app.trigger('sortbysender', this.model);
+ },
+ "click .unread": function(){
+ app.trigger('sortbyunread', this.model);
+ },
+ "click .date": function(){
+ app.trigger('sortbydate', this.model);
+ },
+ "click .sent": function(){
+ app.trigger('sortbysent', this.model);
+ },
+ serialize: function() {
+ return { emails: this.model };
+ }
+
+ }
+ });
+
+ Email.Views.EmailList = Backbone.View.extend({
+ tagName: 'ul',
+ template: 'email/emaillist'
});
Email.Views.Reader = Backbone.View.extend({
template: 'email/reader',
events: {
"click .reply": function(){
- console.log( "reply" );
+ app.trigger('reply', this.model);
},
"click .replyall": function(){
- console.log( "replyall" );
+ app.trigger('replyall', this.model);
},
"click .fwd": function(){
- console.log( "fwd" );
+ app.trigger('fwd', this.model);
}
},
serialize: function() {
No changes.
@@ -4,7 +4,7 @@
<a class="btn replyall">reply all</a>
<a class="btn fwd">fwd</a>
</div>
- <h3>From: <%= email.get('from').name %></h3>
+ <h3>From: <%= email.get('fromname') %></h3>
<h4>CC: <%= email.get('cc') %></h4>
<p>Subject: <%= email.get('subject') %></p>
<p>
@@ -1,8 +1,8 @@
<label>Sort by:</label>
<nav class="btn-group">
- <a class="btn unread active">Sender</a>
+ <a class="btn unread active sender">Sender</a>
<a class="btn unread">Unread</a>
- <a class="btn unread">Date</a>
+ <a class="btn date">Date</a>
<a class="btn sent">Sent mail</a>
</nav>
<ul id="sidebarlist">

0 comments on commit 57ceed7

Please sign in to comment.