2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* JavaScript for SOGo.MailerUI module */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2016-01-04 17:51:59 +01:00
|
|
|
angular.module('SOGo.MailerUI', ['ui.router', 'ck', 'angularFileUpload', 'SOGo.Common', 'SOGo.ContactsUI', 'ngAnimate', 'SOGo.PreferencesUI'])
|
2015-05-06 04:06:13 +02:00
|
|
|
.config(configure)
|
|
|
|
.run(runBlock);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
configure.$inject = ['$stateProvider', '$urlRouterProvider'];
|
|
|
|
function configure($stateProvider, $urlRouterProvider) {
|
|
|
|
$stateProvider
|
|
|
|
.state('mail', {
|
|
|
|
url: '/Mail',
|
|
|
|
views: {
|
|
|
|
mailboxes: {
|
|
|
|
templateUrl: 'UIxMailMainFrame', // UI/Templates/MailerUI/UIxMailMainFrame.wox
|
2015-07-13 21:22:58 +02:00
|
|
|
controller: 'MailboxesController',
|
|
|
|
controllerAs: 'app'
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
2015-05-06 18:12:27 +02:00
|
|
|
stateAccounts: stateAccounts
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('mail.account', {
|
|
|
|
url: '/:accountId',
|
|
|
|
abstract: true,
|
|
|
|
views: {
|
|
|
|
mailbox: {
|
2015-07-13 21:22:58 +02:00
|
|
|
template: '<ui-view/>'
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
2015-05-06 18:12:27 +02:00
|
|
|
stateAccount: stateAccount
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
})
|
2015-09-10 22:38:30 +02:00
|
|
|
.state('mail.account.virtualMailbox', {
|
|
|
|
url: '/virtual',
|
|
|
|
views: {
|
|
|
|
'mailbox@mail': {
|
|
|
|
templateUrl: 'UIxMailFolderTemplate', // UI/Templates/MailerUI/UIxMailFolderTemplate.wox
|
|
|
|
controller: 'MailboxController',
|
|
|
|
controllerAs: 'mailbox'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
2015-09-14 19:48:06 +02:00
|
|
|
stateMailbox: stateVirtualMailbox
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('mail.account.virtualMailbox.message', {
|
|
|
|
url: '/:mailboxId/:messageId',
|
|
|
|
views: {
|
|
|
|
message: {
|
|
|
|
templateUrl: 'UIxMailViewTemplate', // UI/Templates/MailerUI/UIxMailViewTemplate.wox
|
|
|
|
controller: 'MessageController',
|
|
|
|
controllerAs: 'viewer'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
2015-09-14 19:48:06 +02:00
|
|
|
stateMailbox: stateVirtualMailboxOfMessage,
|
2015-09-29 14:58:23 +02:00
|
|
|
stateMessages: stateMessages,
|
2015-09-10 22:38:30 +02:00
|
|
|
stateMessage: stateMessage
|
|
|
|
}
|
|
|
|
})
|
2015-05-06 04:06:13 +02:00
|
|
|
.state('mail.account.mailbox', {
|
|
|
|
url: '/:mailboxId',
|
|
|
|
views: {
|
|
|
|
'mailbox@mail': {
|
|
|
|
templateUrl: 'UIxMailFolderTemplate', // UI/Templates/MailerUI/UIxMailFolderTemplate.wox
|
2015-07-13 21:22:58 +02:00
|
|
|
controller: 'MailboxController',
|
|
|
|
controllerAs: 'mailbox'
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
2015-05-06 18:12:27 +02:00
|
|
|
stateMailbox: stateMailbox,
|
|
|
|
stateMessages: stateMessages
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
})
|
2015-08-02 19:25:38 +02:00
|
|
|
// .state('mail.account.mailbox.newMessage', {
|
|
|
|
// url: '/new',
|
|
|
|
// views: {
|
|
|
|
// 'mailbox@mail': {
|
|
|
|
// templateUrl: 'UIxMailEditor', // UI/Templates/MailerUI/UIxMailEditor.wox
|
|
|
|
// controller: 'MessageEditorController',
|
|
|
|
// controllerAs: 'editor'
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// resolve: {
|
|
|
|
// stateMessage: stateNewMessage
|
|
|
|
// }
|
|
|
|
// })
|
2015-05-06 04:06:13 +02:00
|
|
|
.state('mail.account.mailbox.message', {
|
|
|
|
url: '/:messageId',
|
|
|
|
views: {
|
|
|
|
message: {
|
|
|
|
templateUrl: 'UIxMailViewTemplate', // UI/Templates/MailerUI/UIxMailViewTemplate.wox
|
2015-07-13 21:22:58 +02:00
|
|
|
controller: 'MessageController',
|
|
|
|
controllerAs: 'viewer'
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
2015-05-06 18:12:27 +02:00
|
|
|
stateMessage: stateMessage
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
});
|
2015-08-02 19:25:38 +02:00
|
|
|
// .state('mail.account.mailbox.message.edit', {
|
|
|
|
// url: '/edit',
|
|
|
|
// views: {
|
|
|
|
// 'mailbox@mail': {
|
|
|
|
// 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: {
|
|
|
|
// 'mailbox@mail': {
|
|
|
|
// templateUrl: 'UIxMailEditor', // UI/Templates/MailerUI/UIxMailEditor.wox
|
|
|
|
// controller: 'MessageEditorController',
|
|
|
|
// controllerAs: 'editor'
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
2015-05-06 04:06:13 +02:00
|
|
|
|
|
|
|
// if none of the above states are matched, use this as the fallback
|
|
|
|
$urlRouterProvider.otherwise('/Mail');
|
|
|
|
|
|
|
|
// Set default configuration for tags input
|
|
|
|
// tagsInputConfigProvider.setDefaults('tagsInput', {
|
|
|
|
// addOnComma: false,
|
|
|
|
// replaceSpacesWithDashes: false,
|
|
|
|
// allowedTagsPattern: /([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
|
2015-05-06 18:12:27 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateAccounts.$inject = ['$q', 'Account'];
|
|
|
|
function stateAccounts($q, Account) {
|
2015-07-13 21:22:58 +02:00
|
|
|
var accounts = Account.$findAll(mailAccounts),
|
|
|
|
promises = [];
|
2015-05-06 18:12:27 +02:00
|
|
|
// Fetch list of mailboxes for each account
|
|
|
|
angular.forEach(accounts, function(account, i) {
|
|
|
|
var mailboxes = account.$getMailboxes();
|
|
|
|
promises.push(mailboxes.then(function(objects) {
|
|
|
|
return account;
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
return $q.all(promises);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateAccount.$inject = ['$stateParams', 'stateAccounts'];
|
|
|
|
function stateAccount($stateParams, stateAccounts) {
|
|
|
|
return _.find(stateAccounts, function(account) {
|
|
|
|
return account.id == $stateParams.accountId;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-12-10 17:21:29 +01:00
|
|
|
stateMailbox.$inject = ['$stateParams', 'stateAccount', 'decodeUriFilter'];
|
|
|
|
function stateMailbox($stateParams, stateAccount, decodeUriFilter) {
|
2015-07-13 21:22:58 +02:00
|
|
|
var mailboxId = decodeUriFilter($stateParams.mailboxId),
|
|
|
|
_find;
|
2015-09-14 19:48:06 +02:00
|
|
|
|
2015-05-06 18:12:27 +02:00
|
|
|
// Recursive find function
|
2015-07-13 21:22:58 +02:00
|
|
|
_find = function(mailboxes) {
|
2015-05-06 18:12:27 +02:00
|
|
|
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;
|
|
|
|
};
|
2015-09-10 22:38:30 +02:00
|
|
|
|
2015-05-06 18:12:27 +02:00
|
|
|
return _find(stateAccount.$mailboxes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-09-24 22:48:20 +02:00
|
|
|
stateMessages.$inject = ['Mailbox', 'stateMailbox'];
|
|
|
|
function stateMessages(Mailbox, stateMailbox) {
|
2015-09-10 22:38:30 +02:00
|
|
|
if (Mailbox.$virtualMode)
|
|
|
|
return [];
|
|
|
|
|
2015-05-06 18:12:27 +02:00
|
|
|
return stateMailbox.$filter();
|
|
|
|
}
|
|
|
|
|
2015-07-13 21:22:58 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-08-02 19:25:38 +02:00
|
|
|
// stateNewMessage.$inject = ['stateAccount'];
|
|
|
|
// function stateNewMessage(stateAccount) {
|
|
|
|
// return stateAccount.$newMessage();
|
|
|
|
// }
|
2015-07-13 21:22:58 +02:00
|
|
|
|
2015-09-14 19:48:06 +02:00
|
|
|
/**
|
|
|
|
* Return a VirtualMailbox instance
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateVirtualMailbox.$inject = ['$q', 'Mailbox'];
|
|
|
|
function stateVirtualMailbox($q, Mailbox) {
|
|
|
|
if (Mailbox.$virtualMode)
|
|
|
|
return Mailbox.selectedFolder;
|
|
|
|
else
|
|
|
|
return $q.reject("No virtual mailbox defined");
|
|
|
|
}
|
2015-09-10 22:38:30 +02:00
|
|
|
|
2015-09-14 19:48:06 +02:00
|
|
|
/**
|
|
|
|
* Return a Mailbox instance from a VirtualMailbox instance
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateVirtualMailboxOfMessage.$inject = ['$q', 'Mailbox', 'decodeUriFilter', '$stateParams'];
|
|
|
|
function stateVirtualMailboxOfMessage($q, Mailbox, decodeUriFilter, $stateParams) {
|
|
|
|
var mailboxId = decodeUriFilter($stateParams.mailboxId);
|
|
|
|
|
2015-09-24 22:48:20 +02:00
|
|
|
if (Mailbox.$virtualMode) {
|
|
|
|
Mailbox.selectedFolder.resetSelectedMessage();
|
2015-09-14 19:48:06 +02:00
|
|
|
return _.find(Mailbox.selectedFolder.$mailboxes, function(mailboxObject) {
|
|
|
|
return mailboxObject.path == mailboxId;
|
|
|
|
});
|
2015-09-24 22:48:20 +02:00
|
|
|
}
|
2015-09-14 19:48:06 +02:00
|
|
|
else
|
|
|
|
return $q.reject("No virtual mailbox defined for message");
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
|
|
|
|
2015-05-06 18:12:27 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-09-24 22:48:20 +02:00
|
|
|
stateMessage.$inject = ['Mailbox', 'encodeUriFilter', '$stateParams', '$state', 'stateMailbox', 'stateMessages'];
|
|
|
|
function stateMessage(Mailbox, encodeUriFilter, $stateParams, $state, stateMailbox, stateMessages) {
|
2015-09-10 22:38:30 +02:00
|
|
|
var message;
|
|
|
|
|
|
|
|
message = _.find(stateMailbox.$messages, function(messageObject) {
|
2015-05-06 18:12:27 +02:00
|
|
|
return messageObject.uid == $stateParams.messageId;
|
|
|
|
});
|
|
|
|
|
2015-07-15 19:44:17 +02:00
|
|
|
if (message) {
|
|
|
|
stateMailbox.selectedMessage = $stateParams.messageId;
|
2015-05-06 18:12:27 +02:00
|
|
|
return message.$reload();
|
2015-07-15 19:44:17 +02:00
|
|
|
}
|
|
|
|
else {
|
2015-05-06 18:12:27 +02:00
|
|
|
// Message not found
|
2015-07-13 21:22:58 +02:00
|
|
|
$state.go('mail.account.mailbox', { accountId: stateMailbox.$account.id, mailboxId: encodeUriFilter(stateMailbox.path) });
|
2015-07-15 19:44:17 +02:00
|
|
|
}
|
2015-05-06 18:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-08-02 19:25:38 +02:00
|
|
|
// stateContent.$inject = ['stateMessage'];
|
|
|
|
// function stateContent(stateMessage) {
|
|
|
|
// return stateMessage.$editableContent();
|
|
|
|
// }
|
2015-05-06 18:12:27 +02:00
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-09-14 19:48:06 +02:00
|
|
|
runBlock.$inject = ['$rootScope', '$log', '$state'];
|
|
|
|
function runBlock($rootScope, $log, $state) {
|
|
|
|
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {
|
|
|
|
$log.error(error);
|
|
|
|
$state.go('mail');
|
|
|
|
});
|
2015-05-06 04:06:13 +02:00
|
|
|
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) {
|
2015-09-14 19:48:06 +02:00
|
|
|
$log.error(event, current, previous, rejection);
|
2015-07-29 17:47:01 +02:00
|
|
|
});
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})();
|