1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 19:02:20 -05:00

add file input and filereader logic to writer

This commit is contained in:
Tankred Hase 2014-02-04 21:04:48 +01:00
parent 1237fe684a
commit bb5b63558e
2 changed files with 33 additions and 0 deletions

View File

@ -56,6 +56,7 @@ define(function(require) {
$scope.subject = ''; $scope.subject = '';
$scope.body = ''; $scope.body = '';
$scope.ciphertextPreview = ''; $scope.ciphertextPreview = '';
$scope.attachments = [];
} }
function fillFields(re) { function fillFields(re) {
@ -239,6 +240,11 @@ define(function(require) {
}); });
} }
// add attachment to email object
if ($scope.attachments.length > 0) {
email.attachments = $scope.attachments;
}
// persist the email locally for later smtp transmission // persist the email locally for later smtp transmission
emailDao.store(email, function(err) { emailDao.store(email, function(err) {
if (err) { if (err) {
@ -440,5 +446,28 @@ define(function(require) {
}; };
}); });
ngModule.directive('attachment', function() {
return function(scope, elm) {
elm.bind('change', function(e) {
for (var i = 0; i < e.target.files.length; i++) {
addAttachment(e.target.files.item(i));
}
});
function addAttachment(file) {
var reader = new FileReader();
reader.onload = function(e) {
scope.attachments.push({
fileName: file.name,
contentType: file.type,
uint8Array: new Uint8Array(e.target.result)
});
scope.$apply();
};
reader.readAsArrayBuffer(file);
}
};
});
return WriteCtrl; return WriteCtrl;
}); });

View File

@ -30,6 +30,10 @@
</button> </button>
</div><!--/.subject-box--> </div><!--/.subject-box-->
<div class="attachments-box">
<input type="file" attachment multiple>
</div><!--/.attachments-box-->
<div class="body" focus-child> <div class="body" focus-child>
<p ng-model="body" contentEditable="true" spellcheck="false" ng-change="updatePreview()" tabindex="3" focus-me="state.writer.open && writerTitle === 'Reply'"></p> <p ng-model="body" contentEditable="true" spellcheck="false" ng-change="updatePreview()" tabindex="3" focus-me="state.writer.open && writerTitle === 'Reply'"></p>