2015-09-04 23:31:16 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* JavaScript for SOGo.MailerUI module */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2016-05-05 14:24:26 +02:00
|
|
|
angular.module('SOGo.MailerUI', ['ngCookies', 'ui.router', 'ck', 'angularFileUpload', 'SOGo.Common', 'SOGo.ContactsUI', 'SOGo.SchedulerUI', 'ngAnimate', 'SOGo.PreferencesUI'])
|
2015-09-04 23:31:16 +02:00
|
|
|
.config(configure)
|
|
|
|
.run(runBlock)
|
|
|
|
.controller('MessageEditorControllerPopup', MessageEditorControllerPopup);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
configure.$inject = ['$stateProvider', '$urlRouterProvider'];
|
|
|
|
function configure($stateProvider, $urlRouterProvider) {
|
|
|
|
$stateProvider
|
|
|
|
.state('mail', {
|
|
|
|
url: '/Mail',
|
|
|
|
abstract: true,
|
|
|
|
views: {
|
|
|
|
message: {
|
|
|
|
template: '<ui-view/>'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
stateAccounts: stateAccounts
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('mail.account', {
|
|
|
|
url: '/:accountId',
|
|
|
|
abstract: true,
|
|
|
|
template: '<ui-view id="account"/>',
|
|
|
|
resolve: {
|
|
|
|
stateAccount: stateAccount
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('mail.account.mailbox', {
|
|
|
|
url: '/:mailboxId',
|
|
|
|
abstract: true,
|
|
|
|
template: '<ui-view id="mailbox"/>',
|
|
|
|
resolve: {
|
|
|
|
stateMailbox: stateMailbox
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('mail.account.mailbox.newMessage', {
|
|
|
|
url: '/new',
|
|
|
|
views: {
|
|
|
|
'message@': {
|
|
|
|
template: '<ui-view/>',
|
|
|
|
controller: 'MessageEditorControllerPopup'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
stateMessage: stateNewMessage
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('mail.account.mailbox.message', {
|
|
|
|
url: '/:messageId',
|
|
|
|
views: {
|
|
|
|
'message@': {
|
|
|
|
templateUrl: 'UIxMailViewTemplate', // UI/Templates/MailerUI/UIxMailViewTemplate.wox
|
|
|
|
controller: 'MessageController',
|
|
|
|
controllerAs: 'viewer'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
stateMessage: stateMessage
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('mail.account.mailbox.message.edit', {
|
|
|
|
url: '/edit',
|
|
|
|
views: {
|
|
|
|
'message@': {
|
|
|
|
templateUrl: 'UIxMailEditor', // UI/Templates/MailerUI/UIxMailEditor.wox
|
|
|
|
controller: 'MessageEditorController',
|
|
|
|
controllerAs: 'editor'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
stateContent: stateContent
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('mail.account.mailbox.message.action', {
|
|
|
|
url: '/{actionName:(?:reply|replyall|forward)}',
|
|
|
|
views: {
|
|
|
|
message: {
|
|
|
|
templateUrl: 'UIxMailEditor', // UI/Templates/MailerUI/UIxMailEditor.wox
|
|
|
|
controller: 'MessageEditorController',
|
|
|
|
controllerAs: 'editor'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// if none of the above states are matched, use this as the fallback
|
|
|
|
$urlRouterProvider.otherwise('/Mail/0/folderINBOX/new');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateAccounts.$inject = ['$q', 'Account'];
|
|
|
|
function stateAccounts($q, Account) {
|
2016-01-07 21:43:26 +01:00
|
|
|
var accounts, promises = [];
|
|
|
|
|
|
|
|
if (window &&
|
|
|
|
window.opener &&
|
|
|
|
window.opener.$mailboxController) {
|
|
|
|
// Mail accounts are available from the parent window
|
|
|
|
accounts = window.opener.$mailboxController.accounts;
|
|
|
|
return $q.when(accounts);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
accounts = Account.$findAll();
|
|
|
|
// Fetch list of mailboxes for each account
|
2015-09-04 23:31:16 +02:00
|
|
|
angular.forEach(accounts, function(account, i) {
|
|
|
|
var mailboxes = account.$getMailboxes();
|
|
|
|
promises.push(mailboxes.then(function(objects) {
|
|
|
|
return account;
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
return $q.all(promises);
|
2016-01-07 21:43:26 +01:00
|
|
|
}
|
2015-09-04 23:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateAccount.$inject = ['$stateParams', 'stateAccounts'];
|
|
|
|
function stateAccount($stateParams, stateAccounts) {
|
|
|
|
return _.find(stateAccounts, function(account) {
|
|
|
|
return account.id == $stateParams.accountId;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateMailbox.$inject = ['$stateParams', 'stateAccount', 'decodeUriFilter'];
|
|
|
|
function stateMailbox($stateParams, stateAccount, decodeUriFilter) {
|
|
|
|
var mailboxId = decodeUriFilter($stateParams.mailboxId),
|
|
|
|
_find;
|
|
|
|
// Recursive find function
|
|
|
|
_find = function(mailboxes) {
|
|
|
|
var mailbox = _.find(mailboxes, function(o) {
|
|
|
|
return o.path == mailboxId;
|
|
|
|
});
|
|
|
|
if (!mailbox) {
|
|
|
|
angular.forEach(mailboxes, function(o) {
|
|
|
|
if (!mailbox && o.children && o.children.length > 0) {
|
|
|
|
mailbox = _find(o.children);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return mailbox;
|
|
|
|
};
|
|
|
|
return _find(stateAccount.$mailboxes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateNewMessage.$inject = ['stateAccount'];
|
|
|
|
function stateNewMessage(stateAccount) {
|
|
|
|
return stateAccount.$newMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2016-01-07 21:43:26 +01:00
|
|
|
stateMessage.$inject = ['encodeUriFilter', '$q', '$stateParams', '$state', 'stateMailbox', 'Message'];
|
|
|
|
function stateMessage(encodeUriFilter, $q, $stateParams, $state, stateMailbox, Message) {
|
|
|
|
var data, message;
|
2015-09-04 23:31:16 +02:00
|
|
|
|
2016-01-07 21:43:26 +01:00
|
|
|
if (window &&
|
|
|
|
window.opener &&
|
|
|
|
window.opener.$messageController &&
|
|
|
|
window.opener.$messageController.message.uid == parseInt($stateParams.messageId)) {
|
|
|
|
// Message is available from the parent window
|
|
|
|
message = new Message(stateMailbox.$account.id,
|
|
|
|
stateMailbox,
|
2016-03-15 14:58:58 +01:00
|
|
|
window.opener.$messageController.message.$omit({privateAttributes: true}));
|
2016-01-07 21:43:26 +01:00
|
|
|
return $q.when(message);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Message is not available; load it from the server
|
|
|
|
data = { uid: $stateParams.messageId.toString() };
|
|
|
|
message = new Message(stateMailbox.$account.id, stateMailbox, data);
|
|
|
|
return message.$reload();
|
|
|
|
}
|
2015-09-04 23:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateContent.$inject = ['stateMessage'];
|
|
|
|
function stateContent(stateMessage) {
|
|
|
|
return stateMessage.$editableContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2016-01-07 21:43:26 +01:00
|
|
|
runBlock.$inject = ['$window', '$rootScope', '$log'];
|
|
|
|
function runBlock($window, $rootScope, $log) {
|
|
|
|
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {
|
|
|
|
$log.error(error);
|
|
|
|
$window.close();
|
|
|
|
});
|
2015-09-04 23:31:16 +02:00
|
|
|
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) {
|
2016-01-07 21:43:26 +01:00
|
|
|
$log.error(event, current, previous, rejection);
|
2015-09-04 23:31:16 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2017-01-19 18:23:55 +01:00
|
|
|
MessageEditorControllerPopup.$inject = ['$window', '$mdDialog', 'stateAccount', 'stateMessage'];
|
|
|
|
function MessageEditorControllerPopup($window, $mdDialog, stateAccount, stateMessage) {
|
2015-09-04 23:31:16 +02:00
|
|
|
$mdDialog
|
|
|
|
.show({
|
|
|
|
hasBackdrop: false,
|
|
|
|
disableParentScroll: false,
|
|
|
|
clickOutsideToClose: false,
|
|
|
|
escapeToClose: false,
|
|
|
|
templateUrl: 'UIxMailEditor',
|
|
|
|
controller: 'MessageEditorController',
|
|
|
|
controllerAs: 'editor',
|
|
|
|
locals: {
|
2017-01-19 18:23:55 +01:00
|
|
|
stateAccount: stateAccount,
|
|
|
|
stateMessage: stateMessage
|
2015-09-04 23:31:16 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(function() {
|
2016-01-07 21:43:26 +01:00
|
|
|
$window.close();
|
2015-09-04 23:31:16 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|