composing and sending email works

This commit is contained in:
Tankred Hase 2013-06-05 02:33:49 +02:00
parent f2a14ad65b
commit da3dc17cb4
5 changed files with 59 additions and 27 deletions

View File

@ -5,7 +5,8 @@
routes: {
'': 'login',
'compose': 'compose',
'compose/:userId': 'compose',
'compose/:userId/folders/:folder': 'compose',
'accounts/:userId/folders': 'folders',
'accounts/:userId/folders/:folder': 'messagelist',
'accounts/:userId/folders/:folder/read/:messageId': 'read',
@ -21,8 +22,9 @@
compose: function(userId, folder, messageId) {
var composeView = new app.view.ComposeView({
account: userId,
folder: folder,
messageId: decodeURIComponent(messageId)
messageId: (messageId) ? decodeURIComponent(messageId) : null
});
this.changePage(composeView);
},
@ -60,12 +62,6 @@
page.render();
$('body').append(pageEl);
// handle back click
pageEl.on('vmousedown', '#backBtn', function(e) {
e.preventDefault();
window.history.back();
});
// change page for link buttons on vmousedown instead of waiting on vmouseup
pageEl.on('vmousedown', 'a[data-role="button"]', function(e) {
e.preventDefault();

View File

@ -5,14 +5,16 @@
initialize: function(args) {
this.template = _.template(app.util.tpl.get('compose'));
this.dao = args.dao;
this.account = args.account;
this.folder = args.folder;
if (args.folder && args.messageId) {
// fetch reply-to email model
this.replyTo = args.dao.getItem(args.folder, args.messageId);
}
},
render: function(eventName) {
render: function() {
var self = this,
page = $(this.el);
@ -23,6 +25,12 @@
self.fillFields();
}
// handle back button
page.find('#backBtn').on('vmousedown', function(e) {
e.preventDefault();
self.goBackToLastPage();
});
// handle send button
page.find('#sendBtn').on('vmousedown', function() {
self.sendEmail();
});
@ -79,23 +87,39 @@
var signature = '\n\nSent with whiteout mail - get your free mailbox for end-2-end encrypted messaging!\nhttps://mail.whiteout.io';
var email = new app.model.Email({
from: self.dao.account.get('emailAddress'),
from: self.account,
to: to,
subject: page.find('#subjectInput').val(),
body: page.find('#bodyTextarea').val() + signature
});
self.dao.sendEmail(email, function(err) {
// post message to main window
app.util.postMessage('sendEmail', {
email: email.toJSON()
}, function(resArgs) {
var err = resArgs.err;
$.mobile.loading('hide');
if (err) {
window.alert(JSON.stringify(err));
return;
}
window.history.back();
self.goBackToLastPage();
});
}
},
/**
* Go back to the last activity
* depending from where to compose dialog was opened
*/
goBackToLastPage: function() {
if (this.folder) {
window.location = '#accounts/' + this.account + '/folders/' + this.folder;
} else {
window.location = '#accounts/' + this.account + '/folders';
}
}
});
}());

View File

@ -54,6 +54,16 @@
}
});
function initDAO() {
var util = new cryptoLib.Util(window, uuid);
var crypto = new app.crypto.Crypto(window, util);
var cloudstorage = new app.dao.CloudStorage(window, $);
var jsonDao = new app.dao.LawnchairDAO(Lawnchair);
var devicestorage = new app.dao.DeviceStorage(util, crypto, jsonDao, null);
var keychain = new app.dao.KeychainDAO(jsonDao, cloudstorage);
emailDao = new app.dao.EmailDAO(jsonDao, crypto, devicestorage, cloudstorage, util, keychain);
}
function startApp() {
// init email dao and dependencies
initDAO();
@ -107,6 +117,14 @@
});
});
} else if (cmd === 'sendEmail') {
// list emails from folder
sendEmail(args.email, function(err) {
callback({
err: err
});
});
} else {
// error: invalid message from sandbox
callback({
@ -117,16 +135,6 @@
}
}
function initDAO() {
var util = new cryptoLib.Util(window, uuid);
var crypto = new app.crypto.Crypto(window, util);
var cloudstorage = new app.dao.CloudStorage(window, $);
var jsonDao = new app.dao.LawnchairDAO(Lawnchair);
var devicestorage = new app.dao.DeviceStorage(util, crypto, jsonDao, null);
var keychain = new app.dao.KeychainDAO(jsonDao, cloudstorage);
emailDao = new app.dao.EmailDAO(jsonDao, crypto, devicestorage, cloudstorage, util, keychain);
}
function login(userId, password, callback) {
var account = new app.model.Account({
emailAddress: userId,
@ -134,8 +142,12 @@
symIvSize: app.config.symIvSize,
asymKeySize: app.config.asymKeySize
});
emailDao.init(account, password, callback);
}
function sendEmail(email, callback) {
var em = new app.model.Email(email);
emailDao.sendEmail(em, callback);
}
}());

View File

@ -35,5 +35,5 @@
<div data-role="footer" data-position="fixed">
<h4></h4>
<a href="#compose" data-role="button" data-icon="plus" data-iconpos="notext" class="ui-btn-right"></a>
<a href="#compose/<%- account %>" data-role="button" data-icon="plus" data-iconpos="notext" class="ui-btn-right"></a>
</div><!-- /footer -->

View File

@ -10,5 +10,5 @@
<div data-role="footer" data-position="fixed">
<input type="button" data-icon="refresh" id="refreshBtn" data-iconpos="notext" class="ui-btn-left">
<h4></h4>
<a href="#compose" data-role="button" data-icon="plus" data-iconpos="notext" class="ui-btn-right"></a>
<a href="#compose/<%- account %>/folders/<%- folder %>" data-role="button" data-icon="plus" data-iconpos="notext" class="ui-btn-right"></a>
</div><!-- /footer -->