mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-31 08:04:54 +00:00
(feat) can now create mails from address book module
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user