From d878c69c15cc2f6ff2995558c5961538b799aecb Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Thu, 27 Aug 2015 11:01:23 -0400 Subject: [PATCH] (feat) can now create mails from address book module --- .../ContactsUI/UIxContactFoldersView.wox | 4 +- .../ContactsUI/UIxContactViewTemplate.wox | 3 +- UI/WebServerResources/Gruntfile.js | 4 +- .../js/Contacts/AddressBookController.js | 77 ++++++++++++++++++- .../js/Contacts/Card.service.js | 3 +- .../js/Contacts/Contacts.app.js | 2 +- .../js/Mailer/Account.service.js | 27 +++++-- 7 files changed, 104 insertions(+), 16 deletions(-) diff --git a/UI/Templates/ContactsUI/UIxContactFoldersView.wox b/UI/Templates/ContactsUI/UIxContactFoldersView.wox index 34370fb77..fcb487491 100644 --- a/UI/Templates/ContactsUI/UIxContactFoldersView.wox +++ b/UI/Templates/ContactsUI/UIxContactFoldersView.wox @@ -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"> @@ -311,7 +311,7 @@ - + diff --git a/UI/Templates/ContactsUI/UIxContactViewTemplate.wox b/UI/Templates/ContactsUI/UIxContactViewTemplate.wox index 99a65ce30..7bc8a95dd 100644 --- a/UI/Templates/ContactsUI/UIxContactViewTemplate.wox +++ b/UI/Templates/ContactsUI/UIxContactViewTemplate.wox @@ -118,7 +118,8 @@ diff --git a/UI/WebServerResources/Gruntfile.js b/UI/WebServerResources/Gruntfile.js index cd24d53d5..bee2efb39 100644 --- a/UI/WebServerResources/Gruntfile.js +++ b/UI/WebServerResources/Gruntfile.js @@ -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'] }; diff --git a/UI/WebServerResources/js/Contacts/AddressBookController.js b/UI/WebServerResources/js/Contacts/AddressBookController.js index cdc845dcf..c54ad8d8e 100644 --- a/UI/WebServerResources/js/Contacts/AddressBookController.js +++ b/UI/WebServerResources/js/Contacts/AddressBookController.js @@ -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 diff --git a/UI/WebServerResources/js/Contacts/Card.service.js b/UI/WebServerResources/js/Contacts/Card.service.js index 32c8cb60d..2254c9b87 100644 --- a/UI/WebServerResources/js/Contacts/Card.service.js +++ b/UI/WebServerResources/js/Contacts/Card.service.js @@ -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; }); }); }; diff --git a/UI/WebServerResources/js/Contacts/Contacts.app.js b/UI/WebServerResources/js/Contacts/Contacts.app.js index 16205a872..587fce95d 100644 --- a/UI/WebServerResources/js/Contacts/Contacts.app.js +++ b/UI/WebServerResources/js/Contacts/Contacts.app.js @@ -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); diff --git a/UI/WebServerResources/js/Mailer/Account.service.js b/UI/WebServerResources/js/Mailer/Account.service.js index 8923c4ece..1a4aba21e 100644 --- a/UI/WebServerResources/js/Mailer/Account.service.js +++ b/UI/WebServerResources/js/Mailer/Account.service.js @@ -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; };