From c40c6b8f50835198fe9996a0e9d1281c3843d57b Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Thu, 16 Jan 2014 15:37:08 +0100 Subject: [PATCH] download attachment ui implemented (work in progress) --- src/js/controller/read.js | 37 ++++++++++++++++++++++++++++++++++++- src/js/dao/email-dao.js | 12 ++++++++++++ src/tpl/read.html | 14 +++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/js/controller/read.js b/src/js/controller/read.js index 90aaac8..e14ce25 100644 --- a/src/js/controller/read.js +++ b/src/js/controller/read.js @@ -2,14 +2,17 @@ define(function(require) { 'use strict'; var appController = require('js/app-controller'), + download = require('js/util/download'), angular = require('angular'), - crypto, keychain; + emailDao, crypto, keychain; // // Controller // var ReadCtrl = function($scope) { + + emailDao = appController._emailDao; crypto = appController._crypto; keychain = appController._keychain; @@ -74,6 +77,38 @@ define(function(require) { $scope.$apply(); }); } + + $scope.download = function(attachment) { + // download file to disk if content is available + if (attachment.content) { + saveToDisk(attachment); + return; + } + + var folder = $scope.state.nav.currentFolder; + var email = $scope.state.mailList.selected; + + emailDao.getAttachment({ + path: folder.path, + uid: email.uid, + attachment: attachment + }, function(err) { + if (err) { + $scope.onError(err); + return; + } + + saveToDisk(attachment); + }); + + function saveToDisk(attachment) { + download.createDownload({ + content: attachment.content, + filename: attachment.filename, + contentType: attachment.mimeType + }, $scope.onError); + } + }; }; // diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index fbf2198..6486b60 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -862,6 +862,18 @@ define(function(require) { }, callback); }; + EmailDAO.prototype.getAttachment = function(options, callback) { + if (!this._account.online) { + callback({ + errMsg: 'Client is currently offline!', + code: 42 + }); + return; + } + + this._imapClient.getAttachment(options, callback); + }; + EmailDAO.prototype.sendEncrypted = function(options, callback) { var self = this, email = options.email; diff --git a/src/tpl/read.html b/src/tpl/read.html index ca2dbf9..1b0f7ff 100644 --- a/src/tpl/read.html +++ b/src/tpl/read.html @@ -21,7 +21,19 @@ -
+
+
+
+ + + +
+
+
+
+
+
+