1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-29 20:32:15 -05:00

downloading parsed attachment in ui works

This commit is contained in:
Tankred Hase 2013-08-22 20:04:28 +02:00
parent 8d25527341
commit 5ad681e58d
4 changed files with 29 additions and 5 deletions

View File

@ -188,10 +188,6 @@ define(function(require) {
}
function attachmentReady(err, gottenAttachment) {
// parse uint8array to base to make it serializable for postMessage
gottenAttachment.base64 = btoa(gottenAttachment.uint8Array);
delete gottenAttachment.uint8Array;
attachments.push(gottenAttachment);
itemCounter++;
check();

View File

@ -34,9 +34,33 @@ define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Bac
$(this.el).html(this.template(params));
this.renderBody();
// set download link for attachment button
this.parseAttachments();
return this;
},
parseAttachments: function() {
var attachments = this.model.attachments;
if (!attachments) {
// remove link if no attachments are present
$(this.el).find('#attachmentItem').remove();
return;
}
var attmt = attachments[0];
var blob = new Blob([attmt.uint8Array], {
type: attmt.contentType
});
var url = window.URL.createObjectURL(blob);
// set download link
$(this.el).find('#attachmentBtn').attr({
href: url,
download: attmt.fileName
}).text(attmt.fileName);
},
renderBody: function(tryHtml) {
var page = $(this.el),
emailBody = this.model.body;

View File

@ -28,6 +28,6 @@
},
"sandbox": {
"pages": ["sandbox.html", "mail-content.html"],
"content_security_policy": "sandbox allow-scripts; default-src 'self'; object-src 'none'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src *"
"content_security_policy": "sandbox allow-scripts; default-src 'self'; object-src 'none'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src *; frame-src *"
}
}

View File

@ -27,5 +27,9 @@
</div>
</li>
<li id="attachmentItem">
<a id="attachmentBtn" data-role="button">Download Attachment</a>
</li>
</ul>
</div><!-- /content -->