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:
parent
fbbed90e62
commit
b3bc120c4d
@ -43,6 +43,40 @@ define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Bac
|
|||||||
self.fillFields();
|
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
|
// handle back button
|
||||||
page.find('#backBtn').on('vmousedown', function(e) {
|
page.find('#backBtn').on('vmousedown', function(e) {
|
||||||
e.preventDefault();
|
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
|
// post message to main window
|
||||||
app.util.postMessage('sendEmail', {
|
app.util.postMessage('sendEmail', {
|
||||||
email: email
|
email: email
|
||||||
|
@ -8,4 +8,5 @@
|
|||||||
<input type="email" name="to" id="toInput" placeholder="to:"/>
|
<input type="email" name="to" id="toInput" placeholder="to:"/>
|
||||||
<input type="text" name="subject" id="subjectInput" placeholder="subject:"/>
|
<input type="text" name="subject" id="subjectInput" placeholder="subject:"/>
|
||||||
<textarea name="textarea" class="message-input" id="bodyTextarea"></textarea>
|
<textarea name="textarea" class="message-input" id="bodyTextarea"></textarea>
|
||||||
|
<input type="file" id="files" name="files[]" multiple />
|
||||||
</div><!-- /content -->
|
</div><!-- /content -->
|
Loading…
Reference in New Issue
Block a user