(js) Compose mail from attendee's email addresses

This commit is contained in:
Francis Lachapelle
2016-05-31 21:56:10 -04:00
parent b71fb2e525
commit 5ab405efcc
4 changed files with 66 additions and 7 deletions
@@ -6,8 +6,8 @@
/**
* @ngInject
*/
ComponentController.$inject = ['$rootScope', '$mdDialog', 'Calendar', 'Component', 'AddressBook', 'Alarm', 'stateComponent'];
function ComponentController($rootScope, $mdDialog, Calendar, Component, AddressBook, Alarm, stateComponent) {
ComponentController.$inject = ['$rootScope', '$mdDialog', 'Calendar', 'Component', 'AddressBook', 'Alarm', 'Account', 'stateComponent'];
function ComponentController($rootScope, $mdDialog, Calendar, Component, AddressBook, Alarm, Account, stateComponent) {
var vm = this, component;
vm.calendarService = Calendar;
@@ -15,6 +15,8 @@
vm.component = stateComponent;
vm.close = close;
vm.cardFilter = cardFilter;
vm.newMessageWithAllRecipients = newMessageWithAllRecipients;
vm.newMessageWithRecipient = newMessageWithRecipient;
vm.edit = edit;
vm.editAllOccurrences = editAllOccurrences;
vm.reply = reply;
@@ -44,6 +46,50 @@
return AddressBook.$cards;
}
function newMessageWithAllRecipients($event) {
var recipients = _.map(vm.component.attendees, function(attendee) {
return attendee.name + " <" + attendee.email + ">";
});
_newMessage($event, recipients);
}
function newMessageWithRecipient($event, name, email) {
_newMessage($event, [name + " <" + email + ">"]);
}
function _newMessage($event, recipients) {
Account.$findAll().then(function(accounts) {
var account = _.find(accounts, function(o) {
if (o.id === 0)
return o;
});
// We must initialize the Account with its mailbox
// list before proceeding with message's creation
account.$getMailboxes().then(function(mailboxes) {
account.$newMessage().then(function(message) {
angular.extend(message.editable, { to: recipients, subject: vm.component.summary });
$mdDialog.show({
parent: angular.element(document.body),
targetEvent: $event,
clickOutsideToClose: false,
escapeToClose: false,
templateUrl: '../Mail/UIxMailEditor',
controller: 'MessageEditorController',
controllerAs: 'editor',
locals: {
stateAccount: account,
stateMessage: message
}
});
});
});
});
$event.preventDefault();
$event.stopPropagation();
}
function edit() {
var type = (vm.component.component == 'vevent')? 'Appointment':'Task';
$mdDialog.hide().then(function() {