Skip to content

Commit

Permalink
fixed message sorting, to/from columns
Browse files Browse the repository at this point in the history
  • Loading branch information
voloko committed Apr 6, 2010
1 parent 7d3d289 commit 6ef730b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion fill_dummy_data.rb
Expand Up @@ -13,7 +13,7 @@
:from => 'Vladimir Kolesnikov <voloko@gmail.com>',
:to => 'mail@ukijs.org',
:subject => 'Hello World!',
:recieved => 1258946194,
:recieved => 1270178691,
:attachments => 0
}
r.rpush 'mailbox:INBOX:messages', 1
Expand Down
12 changes: 3 additions & 9 deletions uki_mail_app/controller/main.js
Expand Up @@ -75,7 +75,7 @@ uki_mail_app.controller.main = function() {
title.html(mailbox.title() + ' &mdash; ' + MY_EMAIL + ' (' + mailbox.messages().length + ' messages)');
}
});

// handle folder list selection
var folders = uki('Folders', context);
folders.bind('selection', function() {
Expand All @@ -85,18 +85,11 @@ uki_mail_app.controller.main = function() {
if (mailbox) {
uki('ScrollPane', messageTable).attr('scrollTop', 0);
messageTable[0].mailbox(mailbox).selectedIndexes(mailbox.messages().length ? [0] : []).lastClickIndex(0).focus();

if (!mailbox['loaded.messages']) mailbox.loadMessages(function() {
if (mailbox == folders[0].selectedRow()) {
// we should store visual state (column widths, selection, column names) for the mailbox
// and restore it here. For test purposes change the label only
messageTable[0].header().columns()[3]
.label(mailbox.id() == 'SENT' ? 'Date Sent' : 'Date Recieved')
messageTable[0].header().columns()[1]
.label(mailbox.id() == 'SENT' ? 'To' : 'From')
.key(mailbox.id() == 'SENT' ? 'to' : 'from');
messageTable[0].header().redrawColumn(1);
messageTable[0].header().redrawColumn(3);

messageTable[0].mailbox(this).selectedIndexes(this.messages().length ? [0] : []).lastClickIndex(0).focus();
}
});
Expand Down Expand Up @@ -144,6 +137,7 @@ uki_mail_app.controller.main = function() {
// load up initial mailbox structure
function createMailbox (data) {
if (data.children) data.children = uki.map(data.children, createMailbox);
data.sortField = 'recieved';
return new uki_mail_app.model.Mailbox(data);
}

Expand Down
10 changes: 6 additions & 4 deletions uki_mail_app/model/mailbox.js
Expand Up @@ -9,7 +9,7 @@ uki_mail_app.model.Mailbox = uki.newClass(uki.data.Model, function(Base) {
Base.init.call(this, values);
};

uki.data.model.addFields(this, ['unread', 'id', 'title', 'messages', 'children']);
uki.data.model.addFields(this, ['unread', 'id', 'title', 'messages', 'children', 'sortField']);

var defaultIcons = {
INBOX: 'mb-inbox',
Expand Down Expand Up @@ -60,9 +60,9 @@ uki_mail_app.model.Mailbox = uki.newClass(uki.data.Model, function(Base) {

this.loadMessages = this.loadNewMessages;

this.sortByDate = function(fieldName) {
this._messages = this._messages.sort(function(a, b) {
return a.recieved()*1 - b.recieved()*1;
this._sortBy = function(fieldName) {
this._messages = this._messages.sort(function(b, a) {
return a[fieldName]()*1 - b[fieldName]()*1;
});
};

Expand All @@ -73,6 +73,7 @@ uki_mail_app.model.Mailbox = uki.newClass(uki.data.Model, function(Base) {
messages[i].mailbox(this);
messages[i].bind('change.unread', this._unreadChangeHandler);
};
if (this.sortField()) this._sortBy(this.sortField());
this.trigger('change.messages');
this._updateCounts(messages);
};
Expand All @@ -89,6 +90,7 @@ uki_mail_app.model.Mailbox = uki.newClass(uki.data.Model, function(Base) {
removed.push(m);
return false;
}, this);
if (this.sortField()) this._sortBy(this.sortField());
this.trigger('change.messages');
this._updateCounts();
return removed;
Expand Down
4 changes: 4 additions & 0 deletions uki_mail_app/model/message.js
Expand Up @@ -24,6 +24,10 @@ uki_mail_app.model.Message = uki.newClass(uki.data.Model, function(Base) {
return this.from().replace(/<[^>]+>/g, '').replace(/\s+/, ' ');
};

this.toName = function() {
return this.to().replace(/<[^>]+>/g, '').replace(/\s+/, ' ');
};

this.summary = function() {
return this.subject() + ' from ' + this.from();
};
Expand Down
9 changes: 9 additions & 0 deletions uki_mail_app/view/messageTable.js
Expand Up @@ -28,6 +28,15 @@ uki.view.declare('uki_mail_app.view.MessageTable', uki.view.Table, function(Base
this.mailbox = uki.newProp('_mailbox', function(m) {
if (this._mailbox) this._mailbox.unbind('change.messages', this._messagesChange);
this._mailbox = m;

this.header().columns()[3]
.label(m.id() == 'SENT' ? 'Date Sent' : 'Date Recieved')
this.header().columns()[1]
.label(m.id() == 'SENT' ? 'To' : 'From')
.key(m.id() == 'SENT' ? 'toName' : 'fromName');
this.header().redrawColumn(1);
this.header().redrawColumn(3);

this.data(m.messages());
m.bind('change.messages', uki.proxy(this._messagesChange, this));
this.trigger('change.messages');
Expand Down

0 comments on commit 6ef730b

Please sign in to comment.