Skip to content
Browse files

implemented a good deal of the mail sorting

  • Loading branch information...
1 parent 4106e16 commit ed63cf56b66077f3845a053d8c6e407fa99bd1c5 @boazsender boazsender committed Mar 20, 2012
View
83 www/app/main.js
@@ -22,8 +22,11 @@ function(epp, jQuery, Backbone, Email) {
index: function() {
var emails = new Email.Collection();
+ var unreadEmails = new Email.Collection();
window.emails = emails;
-
+ window.Email = Email;
+ Email.collections = {};
+
emails.fetch().success(function(){
var main = new Backbone.LayoutManager({
template: 'main',
@@ -40,61 +43,100 @@ function(epp, jQuery, Backbone, Email) {
// Organize a new collection of emails according to sender
var senders = new Email.SenderCollection();
window.senders = senders;
+
+
// Iterate over all the emails
emails.each(function( email ){
// If we haven't put this sender in the senders collection, do it
if( !senders.get(email.get('fromemail')) ){
senders.add({
id: email.get('fromemail'),
name: email.get('fromname'),
+ allMail: new Email.Collection(),
read: new Email.Collection(),
unread: new Email.Collection()
});
// if the current email is unread, create a new unread collection for it
if( !email.get('read') ){
senders.get( email.get('fromemail') ).get( 'unread' ).add( email );
+ senders.get( email.get('fromemail') ).get( 'allMail' ).add( email );
+ unreadEmails.add( email );
// otherwise, create a new read collection for it
} else {
senders.get( email.get('fromemail') ).get( 'read' ).add( email );
+ senders.get( email.get('fromemail') ).get( 'allMail' ).add( email );
}
// if we have already pyt this sender in the senders collection
} else {
// if the email is unread add it to the unread collection
if( !email.get('read') ){
senders.get( email.get('fromemail') ).get('unread').add( email );
+ senders.get( email.get('fromemail') ).get( 'allMail' ).add( email );
+ unreadEmails.add( email );
// if the email is unread add it to the read collection
} else {
senders.get( email.get('fromemail') ).get('read').add( email );
+ senders.get( email.get('fromemail') ).get( 'allMail' ).add( email );
}
}
+
+ Email.collections['senders'] = senders;
+ Email.collections['emails'] = emails;
+ Email.collections['unreadEmails'] = unreadEmails;
+
});
- var sendersList = new Email.Views.SidebarList({ collection: senders });
- sendersList.modelTemplate = 'email/sidebaritem-sender';
- sendersList.clickEvent = 'showsendermail';
- main.views['#sidebar'].view( "#sidebarlist", sendersList );
+ app.bind('sortbysender', function( senders ){
+ var sendersList = new Email.Views.SidebarList({ collection: senders.collection });
+ sendersList.modelTemplate = 'email/sidebaritem-sender';
+ sendersList.clickEvent = 'showsendermail';
+ var layoutSendersList = main.views['#sidebar'].view( "#sidebarlist", sendersList);
+ if( senders.render ){
+ layoutSendersList.render();
+ }
+ $('nav.btn-group')
+ .children().removeClass('active')
+ .end()
+ .children('.sender').addClass('active')
+ });
+
app.bind('showsendermail', function( sender ){
- var emailListUnread = new Email.Views.SidebarList({ collection: sender.get('unread') });
- emailListUnread.modelTemplate = 'email/sidebaritem';
- emailListUnread.clickEvent = 'showbody';
-
- main.views['#sidebar'].views['#sidebarlist'].view( '#' + sender.cid, emailListUnread ).render();
+ var emailListUnread = new Email.Views.SidebarList({ collection: sender.get('allMail') });
+ var as1 = main.views['#sidebar'].views['#sidebarlist'].view( '#' + sender.cid, emailListUnread).render();
- var emailListRead = new Email.Views.SidebarList({ collection: sender.get('read') });
- emailListRead.modelTemplate = 'email/sidebaritem';
- emailListRead.clickEvent = 'showbody';
-
- main.views['#sidebar'].views['#sidebarlist'].view( '#' + sender.cid, emailListRead ).render();
+ });
+ app.bind('sortbyunread', function( emails ){
+
+ var emailList = new Email.Views.SidebarList({ collection: emails.collection });
+ emailList.className = 'btn';
+ main.views['#sidebar'].view( '#sidebarlist', emailList ).render();
+
+ $('nav.btn-group')
+ .children().removeClass('active')
+ .end()
+ .children('.unread').addClass('active')
});
app.bind('sortbydate', function( emails ){
- emails.each(function( email ){
- main.views['#sidebar'].view("#sidebarlist", new Email.Views.SidebarItemDate({ model: email}), true);
- });
+ var emailList = new Email.Views.SidebarList({ collection: emails.collection });
+ emailList.className = 'btn';
+ main.views['#sidebar'].view( '#sidebarlist', emailList ).render();
+
+ $('nav.btn-group')
+ .children().removeClass('active')
+ .end()
+ .children('.date').addClass('active')
+ });
+
+ app.bind('sortbysent', function( emails ){
+ $('nav.btn-group')
+ .children().removeClass('active')
+ .end()
+ .children('.sent').addClass('active')
});
app.bind('showbody', function( model){
@@ -107,9 +149,14 @@ function(epp, jQuery, Backbone, Email) {
writer.render();
});
+ // Render the main emails layout manager
main.render(function( el ){
$('#main').html( el );
});
+
+ // Render the Senders list by default
+ app.trigger('sortbysender', { collection: senders, render: false });
+
});
},
View
24 www/app/modules/email.js
@@ -20,8 +20,12 @@ function(epp, Backbone) {
Email.Model = Backbone.Model.extend({});
Email.Collection = Backbone.Collection.extend({
url: '/assets/data/email.json',
- comparator: function(chapter) {
- return chapter.get("date");
+ comparator: function( email ) {
+ if( email.get('read') ) {
+ return 1
+ } else {
+ return -email.get("date");
+ }
}
});
@@ -41,9 +45,11 @@ function(epp, Backbone) {
render: function( manage ){
var view = manage(this);
var that = this;
-
this.collection.each(function( model ) {
- var itemView = new Email.Views.SidebarItem({ model: model });
+ var itemView = new Email.Views.SidebarItem({
+ className: that.className || '',
+ model: model
+ });
itemView.template = that.modelTemplate || 'email/sidebaritem';
itemView.clickEvent = that.clickEvent || 'showbody';
view.insert( '.list', itemView, true );
@@ -54,7 +60,7 @@ function(epp, Backbone) {
});
Email.Views.SidebarItem = Backbone.View.extend({
- tagName: 'span',
+ tagName: 'li',
template: 'email/sidebaritem',
events: {
"click": function(){
@@ -70,16 +76,16 @@ function(epp, Backbone) {
template: 'email/sidebar',
events: {
"click .sender": function(){
- app.trigger('sortbysender', this.model);
+ app.trigger('sortbysender', { collection: Email.collections.senders, render: true });
},
"click .unread": function(){
- app.trigger('sortbyunread', this.model);
+ app.trigger('sortbyunread', { collection: Email.collections.unreadEmails, render: true });
},
"click .date": function(){
- app.trigger('sortbydate', this.model);
+ app.trigger('sortbydate', { collection: Email.collections.emails, render: true });
},
"click .sent": function(){
- app.trigger('sortbysent', this.model);
+ app.trigger('sortbysent', { collection: Email.collections.sentEmails, render: true });
},
serialize: function() {
return { emails: this.model };
View
2 www/app/templates/email/sidebar.html
@@ -1,6 +1,6 @@
<label>Sort by:</label>
<nav class="btn-group">
- <a class="btn unread active sender">Sender</a>
+ <a class="btn sender active">Sender</a>
<a class="btn unread">Unread</a>
<a class="btn date">Date</a>
<a class="btn sent">Sent mail</a>
View
6 www/app/templates/email/sidebaritem.html
@@ -1,2 +1,4 @@
-<%= new Date( model.get('date') ).toUTCString().substr(4, 7) %>
-"<%= model.get('body').substr(0, 35) %> ..."
+<span class="<%= model.get('read') ? 'read' : 'unread' %>">
+ <em><%= new Date( model.get('date') ).toUTCString().substr(4, 7) %></em> &rarr;
+ "<%= model.get('body').substr(0, 25) %> ..."
+</span>
View
18 www/assets/css/epp.css
@@ -25,9 +25,10 @@
}
#sidebar label {
font-weight: bold;
- margin: 15px 5px;
- display: inline;
- vertical-align: top;
+ margin: -44px 5px 0 5px;
+ display: inline-block;
+ line-height: 1;
+ vertical-align: middle;
}
#sidebar input {
display: inline;
@@ -42,17 +43,20 @@
#sidebar li {
text-align: left;
}
-#sidebar .sublist span {
+#sidebar .sublist li {
display: block;
margin: 0px 10px;
padding: 5px 0;
width: 100%;
cursor: pointer;
border-bottom: 1px solid #888;
}
-#sidebar .sublist span:last-child {
+#sidebar .sublist li:last-child {
border-bottom: none;
}
+#sidebar {
+ margin: 0 26px 0 6px
+}
#reader {
position: absolute;
left: 360px;
@@ -114,4 +118,8 @@ input, textarea, select, .uneditable-input {
.right {
float: right
+}
+
+.unread {
+ font-weight: bold;
}
View
10 www/assets/data/email.json
@@ -14,23 +14,23 @@
{
"fromname": "Eric O'conner",
"fromemail": "eric@awesome.com",
- "date": 1332112640409,
- "read": 0,
+ "date": 1330102440409,
+ "read": 1,
"subject": "Another email from Eric",
"body": "You should really read this dude!"
},
{
"fromname": "Eric O'conner",
"fromemail": "eric@awesome.com",
- "date": 1332114724789,
+ "date": 1332314724789,
"read": 0,
"subject": "I'm getting sick of this!",
"body": "DUDE! Why do I have to email you so many times"
},
{
"fromname": "Boaz Sender",
"fromemail": "boaz@bocoup.com",
- "date": 1332112640409,
+ "date": 1332142240009,
"read": 0,
"cc": [
"eirc@bocoup,com",
@@ -42,7 +42,7 @@
{
"fromname": "Rick Waldron",
"fromemail": "rick@bocoup.com",
- "date": 1332114734789,
+ "date": 1332374734789,
"read": 0,
"subject": "UNIT TESTS BRO",
"body": "You need to write more unit tests for Email++"
View
BIN www/assets/js/libs/.DS_Store
Binary file not shown.

0 comments on commit ed63cf5

Please sign in to comment.
Something went wrong with that request. Please try again.