1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 10:52:17 -05:00

add filepicker support for sending attachments

This commit is contained in:
Tankred Hase 2013-08-26 16:25:13 +02:00
parent fbbed90e62
commit b3bc120c4d
2 changed files with 38 additions and 0 deletions

View File

@ -43,6 +43,40 @@ define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Bac
self.fillFields();
}
// handle file picker for attachments
page.find('#files').on('change', function(e) {
var files = e.target.files,
i, reader;
// check if files exist
if (!files || files.length < 1) {
return;
}
// init attachments array if non exists
if (!self._attachments) {
self._attachments = [];
}
function addAttachment(file) {
reader = new FileReader();
reader.onloadend = function(f) {
self._attachments.push({
fileName: file.name,
contentType: file.type,
uint8Array: new Uint8Array(f.target.result)
});
};
reader.readAsArrayBuffer(file);
}
for (i = 0; i < files.length; i++) {
addAttachment(files[i]);
}
});
// handle back button
page.find('#backBtn').on('vmousedown', function(e) {
e.preventDefault();
@ -120,6 +154,9 @@ define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Bac
});
});
// add attachments
email.attachments = self._attachments;
// post message to main window
app.util.postMessage('sendEmail', {
email: email

View File

@ -8,4 +8,5 @@
<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>
<input type="file" id="files" name="files[]" multiple />
</div><!-- /content -->