diff --git a/src/js/app-router.js b/src/js/app-router.js index ddd23b8..6fb5e6b 100644 --- a/src/js/app-router.js +++ b/src/js/app-router.js @@ -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(); diff --git a/src/js/view/compose-view.js b/src/js/view/compose-view.js index d1056cd..0f616c7 100644 --- a/src/js/view/compose-view.js +++ b/src/js/view/compose-view.js @@ -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'; + } + } }); }()); \ No newline at end of file diff --git a/src/js/window-loader.js b/src/js/window-loader.js index 5d8fc73..564e43a 100644 --- a/src/js/window-loader.js +++ b/src/js/window-loader.js @@ -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); + } + }()); \ No newline at end of file diff --git a/src/tpl/folderlist.html b/src/tpl/folderlist.html index 543d9a2..9e89c69 100644 --- a/src/tpl/folderlist.html +++ b/src/tpl/folderlist.html @@ -35,5 +35,5 @@

- +
\ No newline at end of file diff --git a/src/tpl/messagelist.html b/src/tpl/messagelist.html index 4f9f40a..91cb6e5 100644 --- a/src/tpl/messagelist.html +++ b/src/tpl/messagelist.html @@ -10,5 +10,5 @@

- +
\ No newline at end of file