From ebbb16866a84660c17523974fe463030c7138486 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Sat, 4 May 2013 15:08:54 +0200 Subject: [PATCH] prefill compose view for replying works --- src/js/app-router.js | 3 ++- src/js/view/compose-view.js | 36 ++++++++++++++++++++++++++++++++++-- src/js/view/read-view.js | 7 ++++++- src/tpl/read.html | 2 +- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/js/app-router.js b/src/js/app-router.js index d2e9fcc..db1e9d4 100644 --- a/src/js/app-router.js +++ b/src/js/app-router.js @@ -8,7 +8,8 @@ 'compose': 'compose', 'accounts/:userId/folders': 'folders', 'accounts/:userId/folders/:folder': 'messagelist', - 'accounts/:userId/folders/:folder/read/:messageId': 'read' + 'accounts/:userId/folders/:folder/read/:messageId': 'read', + 'accounts/:userId/folders/:folder/reply/:messageId': 'compose' }, initialize: function() {}, diff --git a/src/js/view/compose-view.js b/src/js/view/compose-view.js index 318a048..1bf47d4 100644 --- a/src/js/view/compose-view.js +++ b/src/js/view/compose-view.js @@ -18,6 +18,11 @@ page.html(this.template()); + // prefill fields for reply + if (this.replyTo) { + self.fillFields(); + } + page.find('#sendBtn').on('vmousedown', function() { self.sendEmail(); }); @@ -25,6 +30,33 @@ return this; }, + fillFields: function() { + var page = $(this.el), + re = this.replyTo, + from = re.get('from')[0], + subject = re.get('subject'); + + // fill recipient field + var replyToAddress = from.address; + page.find('#toInput').val(replyToAddress); + + // fill subject + subject = 'Re: ' + ((subject) ? subject.replace('Re: ', '') : ''); + page.find('#subjectInput').val(subject); + + // fill text body + var body = '\n\n' + re.get('sentDate') + ' ' + from.name + ' <' + from.address + '>\n'; + var bodyRows = re.get('body').split('\n'); + var isHtml = false; + _.each(bodyRows, function(row) { + if (row.indexOf('<') === 0) { + isHtml = true; + } + body += (!isHtml) ? '> ' + row + '\n' : ''; + }); + page.find('#bodyTextarea').text(body); + }, + /** * Send an email via the email dao */ @@ -44,7 +76,7 @@ return; } - var signature = '\n\nSent with whiteout.io - get your mailbox for end-2-end encrypted messaging!\nhttps://mail.whiteout.io'; + 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'), @@ -60,7 +92,7 @@ return; } - //window.history.back(); + window.history.back(); }); } diff --git a/src/js/view/read-view.js b/src/js/view/read-view.js index e9c7f53..4577824 100644 --- a/src/js/view/read-view.js +++ b/src/js/view/read-view.js @@ -9,7 +9,12 @@ }, render: function(eventName) { - $(this.el).html(this.template(this.model.toJSON())); + var params = this.model.toJSON(); + params.account = this.options.dao.account.get('emailAddress'); + params.folder = this.options.folder; + params.id = encodeURIComponent(params.id); + + $(this.el).html(this.template(params)); this.renderBody(); return this; diff --git a/src/tpl/read.html b/src/tpl/read.html index 46c75c9..e0abf1d 100644 --- a/src/tpl/read.html +++ b/src/tpl/read.html @@ -1,7 +1,7 @@

<%- subject %>

- Reply + Reply