(feat) can now create mails from address book module

pull/105/head
Ludovic Marcotte 2015-08-27 11:01:23 -04:00
parent d9d59c6b52
commit d878c69c15
7 changed files with 104 additions and 16 deletions

View File

@ -9,7 +9,7 @@
className="UIxPageFrame"
title="title"
const:userDefaultsKeys="SOGoContactsCategories"
const:jsFiles="Common.js, Preferences.services.js, Contacts.js, Contacts.services.js, vendor/angular-file-upload.min.js">
const:jsFiles="vendor/ckeditor/ckeditor.js, vendor/ckeditor/ck.js, Common.js, Preferences.services.js, Mailer.services.js, Contacts.js, Contacts.services.js, vendor/angular-file-upload.min.js">
<script type="text/javascript">
var contactFolders = <var:string value="contactFolders" const:escapeHTML="NO" />;
</script>
@ -311,7 +311,7 @@
</md-button>
<md-menu-content width="2">
<md-menu-item>
<md-button disabled="disabled">
<md-button ng-click="addressbook.newMessageWithSelectedCards($event)">
<var:string label:value="Write"/>
</md-button>
</md-menu-item>

View File

@ -118,7 +118,8 @@
</div>
<div class="pseudo-input-field">
<a href="mailto:{{email.value}}">{{email.value}}</a>
<a href="#" ng-bind="email.value"
ng-click="addressbook.newMessageWithRecipient($event, email.value, editor.card.$fullname())"><!-- recipient --></a>
</div>
</div>

View File

@ -6,8 +6,8 @@ module.exports = function(grunt) {
'js/Scheduler.js': ['js/Scheduler/Scheduler.app.js', 'js/Scheduler/*Controller.js', 'js/Scheduler/*.directive.js'],
'js/Contacts.services.js': ['js/Contacts/*.service.js'],
'js/Contacts.js': ['js/Contacts/Contacts.app.js', 'js/Contacts/*Controller.js', 'js/Contacts/*.directive.js'],
'js/Mailer.services.js': ['js/Mailer/*.service.js'],
'js/Mailer.js': ['js/Mailer/Mailer.app.js', 'js/Mailer/*Controller.js', 'js/Mailer/*.directive.js'],
'js/Mailer.services.js': ['js/Mailer/*.service.js', 'js/Mailer/*Controller.js'],
'js/Mailer.js': ['js/Mailer/Mailer.app.js', 'js/Mailer/*.directive.js'],
'js/Preferences.services.js': ['js/Preferences/*.service.js'],
'js/Preferences.js': ['js/Preferences/Preferences.app.js', 'js/Preferences/*Controller.js']
};

View File

@ -6,8 +6,8 @@
/**
* @ngInject
*/
AddressBookController.$inject = ['$scope', '$state', '$timeout', '$mdDialog', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'stateAddressbooks', 'stateAddressbook'];
function AddressBookController($scope, $state, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) {
AddressBookController.$inject = ['$scope', '$q', '$state', '$timeout', '$mdDialog', 'sgFocus', 'Account', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'stateAddressbooks', 'stateAddressbook'];
function AddressBookController($scope, $q, $state, $timeout, $mdDialog, focus, Account, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) {
var vm = this;
AddressBook.selectedFolder = stateAddressbook;
@ -24,6 +24,9 @@
vm.sort = sort;
vm.sortedBy = sortedBy;
vm.cancelSearch = cancelSearch;
vm.newMessage = newMessage;
vm.newMessageWithSelectedCards = newMessageWithSelectedCards;
vm.newMessageWithRecipient = newMessageWithRecipient;
vm.mode = { search: false };
function selectCard(card) {
@ -122,6 +125,76 @@
vm.mode.search = false;
vm.selectedFolder.$filter('');
}
function newMessage($event, recipients) {
Account.$findAll().then(function(accounts) {
var account = _.filter(accounts, function(o) {
if (o.id === 0)
return o;
})[0];
// 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) {
$mdDialog.show({
parent: angular.element(document.body),
targetEvent: $event,
clickOutsideToClose: false,
escapeToClose: false,
templateUrl: '../Mail/UIxMailEditor',
controller: 'MessageEditorController',
controllerAs: 'editor',
locals: {
stateAccounts: accounts,
stateMessage: message,
stateRecipients: recipients
}
});
});
});
});
}
function newMessageWithRecipient($event, recipient, fn) {
var recipients = [{full: fn + ' <' + recipient + '>'}];
vm.newMessage($event, recipients);
}
function newMessageWithSelectedCards($event) {
var selectedCards = _.filter(vm.selectedFolder.cards, function(card) { return card.selected; });
var promises = [], recipients = [];
_.each(selectedCards, function(card) {
if (card.c_component == 'vcard' && card.c_mail.length) {
recipients.push({full: card.c_cn + ' <' + card.c_mail + '>'});
}
else if (card.c_component == 'vlist') {
// If the list's members were already fetch, use them
if (angular.isDefined(card.refs) && card.refs.length) {
_.each(card.refs, function(ref) {
if (ref.email.length)
recipients.push({full: ref.c_cn + ' <' + ref.email + '>'});
});
}
else {
promises.push(vm.selectedFolder.$getCard(card.id).then(function(card) {
return card.$futureCardData.then(function(data) {
_.each(data.refs, function(ref) {
if (ref.email.length)
recipients.push({full: ref.c_cn + ' <' + ref.email + '>'});
});
});
}));
}
}
});
$q.all(promises).then(function() {
if (recipients.length)
vm.newMessage($event, recipients);
});
}
}
angular

View File

@ -452,7 +452,7 @@
// Resolve the promise
this.$futureCardData.then(function(data) {
// Calling $timeout will force Angular to refresh the view
Card.$timeout(function() {
return Card.$timeout(function() {
_this.init(data);
// Instanciate Card objects for list members
angular.forEach(_this.refs, function(o, i) {
@ -465,6 +465,7 @@
}
// Make a copy of the data for an eventual reset
_this.$shadowData = _this.$omit(true);
return _this;
});
});
};

View File

@ -4,7 +4,7 @@
(function() {
'use strict';
angular.module('SOGo.ContactsUI', ['ngSanitize', 'ui.router', 'angularFileUpload', 'SOGo.Common', 'SOGo.PreferencesUI'])
angular.module('SOGo.ContactsUI', ['ngSanitize', 'ui.router', 'angularFileUpload', 'ck', 'SOGo.Common', 'SOGo.PreferencesUI', 'SOGo.MailerUI'])
.config(configure)
.run(runBlock);

View File

@ -36,7 +36,7 @@
$q: $q,
$timeout: $timeout,
$log: $log,
$$resource: new Resource(Settings.baseURL(), Settings.activeUser()),
$$resource: new Resource(Settings.activeUser('folderURL') + 'Mail', Settings.activeUser()),
$Mailbox: Mailbox,
$Message: Message
});
@ -64,14 +64,27 @@
* @returns the list of accounts
*/
Account.$findAll = function(data) {
var collection = [];
if (data) {
// Each entry is spun up as an Account instance
angular.forEach(data, function(o, i) {
o.id = i;
collection[i] = new Account(o);
if (!data) {
return Account.$$resource.fetch('', 'mailAccounts').then(function(o) {
return Account.$unwrapCollection(o);
});
}
return Account.$unwrapCollection(data);
};
/**
* @memberof Account
* @desc Unwrap to a collection of Account instances.
* @param {object} data - the accounts information
* @returns a collection of Account objects
*/
Account.$unwrapCollection = function(data) {
var collection = [];
angular.forEach(data, function(o, i) {
o.id = i;
collection[i] = new Account(o);
});
return collection;
};