Sending email from client works

This commit is contained in:
Tankred Hase 2013-05-03 16:09:13 +02:00
parent eda008258d
commit b1bc03b74b
4 changed files with 65 additions and 8 deletions

View File

@ -29,8 +29,13 @@
this.changePage(loginView);
},
compose: function() {
var composeView = new app.view.ComposeView();
compose: function(to, reSubject, reBody) {
var composeView = new app.view.ComposeView({
to: to,
reSubject: reSubject,
reBody: reBody,
dao: this.emailDao
});
this.changePage(composeView);
},

View File

@ -239,6 +239,9 @@ app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage, naclCrypto,
this.sendEmail = function(email, callback) {
var userId = this.account.get('emailAddress');
// generate a new UUID for the new email
email.set('id', util.UUID());
cloudstorage.putEncryptedItem(email, 'email', userId, 'outbox', function(err) {
callback(err);
});

View File

@ -3,14 +3,63 @@
app.view.ComposeView = Backbone.View.extend({
initialize: function() {
initialize: function(args) {
this.template = _.template(app.util.tpl.get('compose'));
this.dao = args.dao;
},
render: function(eventName) {
$(this.el).html(this.template());
var self = this,
page = $(this.el);
page.html(this.template());
page.find('#sendBtn').on('vmousedown', function() {
self.sendEmail();
});
return this;
},
/**
* Send an email via the email dao
*/
sendEmail: function() {
var self = this,
page = $(this.el);
$.mobile.loading('show', {
text: 'sending...',
textVisible: true
});
// validate recipients
var to = page.find('#toInput').val().replace(/\s/g, '').split(/[,;]/);
if (!to || to.length < 1) {
window.alert('Seperate recipients with a comma!');
return;
}
var signature = '\n\nSent with https://mail.whiteout.io - get your mailbox for end-2-end encrypted messaging!';
var email = new app.model.Email({
from: self.dao.account.get('emailAddress'),
to: to,
subject: page.find('#subjectInput').val(),
body: page.find('#bodyTextarea').val() + signature
});
self.dao.sendEmail(email, function(err) {
$.mobile.loading('hide');
if (err) {
window.alert(JSON.stringify(err));
return;
}
//window.history.back();
});
}
});
}());

View File

@ -1,11 +1,11 @@
<div data-role="header" data-position="fixed">
<input type="button" id="backBtn" data-icon="delete" value="Cancel" class="ui-btn-left">
<h1>New Mail</h1>
<input type="button" id="backBtn" data-icon="check" data-iconpos="right" value="Send" class="ui-btn-right">
<input type="button" id="sendBtn" data-icon="check" data-iconpos="right" value="Send" class="ui-btn-right">
</div><!-- /header -->
<div data-role="content">
<input type="email" name="to" id="to" placeholder="to:"/>
<input type="text" name="subject" id="subject" placeholder="subject:"/>
<textarea name="textarea" class="message-input" id="textarea-msg"></textarea>
<input type="email" name="to" id="toInput" placeholder="to:"/>
<input type="text" name="subject" id="subjectInput" placeholder="subject:"/>
<textarea name="textarea" class="message-input" id="bodyTextarea"></textarea>
</div><!-- /content -->