2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-09-10 22:38:30 +02:00
|
|
|
MailboxesController.$inject = ['$state', '$timeout', '$mdDialog', 'sgFocus', 'encodeUriFilter', 'Dialog', 'sgSettings', 'Account', 'Mailbox', 'VirtualMailbox', 'User', 'Preferences', 'stateAccounts'];
|
|
|
|
function MailboxesController($state, $timeout, $mdDialog, focus, encodeUriFilter, Dialog, Settings, Account, Mailbox, VirtualMailbox, User, Preferences, stateAccounts) {
|
2015-07-13 21:22:58 +02:00
|
|
|
var vm = this,
|
|
|
|
account,
|
|
|
|
mailbox;
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2015-07-13 21:22:58 +02:00
|
|
|
vm.service = Mailbox;
|
|
|
|
vm.accounts = stateAccounts;
|
|
|
|
vm.newFolder = newFolder;
|
|
|
|
vm.delegate = delegate;
|
|
|
|
vm.editFolder = editFolder;
|
|
|
|
vm.revertEditing = revertEditing;
|
|
|
|
vm.selectFolder = selectFolder;
|
|
|
|
vm.saveFolder = saveFolder;
|
2015-07-21 15:28:54 +02:00
|
|
|
vm.compactFolder = compactFolder;
|
|
|
|
vm.emptyTrashFolder = emptyTrashFolder;
|
2015-07-13 21:22:58 +02:00
|
|
|
vm.exportMails = exportMails;
|
|
|
|
vm.confirmDelete = confirmDelete;
|
2015-07-21 15:28:54 +02:00
|
|
|
vm.markFolderRead = markFolderRead;
|
2015-07-13 21:22:58 +02:00
|
|
|
vm.share = share;
|
2015-07-24 20:40:07 +02:00
|
|
|
vm.metadataForFolder = metadataForFolder;
|
|
|
|
vm.setFolderAs = setFolderAs;
|
2015-07-31 19:32:14 +02:00
|
|
|
vm.refreshUnseenCount = refreshUnseenCount;
|
2015-07-13 21:22:58 +02:00
|
|
|
|
2015-09-10 22:38:30 +02:00
|
|
|
// Advanced search options
|
|
|
|
vm.showingAdvancedSearch = false;
|
|
|
|
vm.currentSearchParam = '';
|
|
|
|
vm.addSearchParam = addSearchParam;
|
|
|
|
vm.newSearchParam = newSearchParam;
|
|
|
|
vm.showAdvancedSearch = showAdvancedSearch;
|
|
|
|
vm.hideAdvancedSearch = hideAdvancedSearch;
|
|
|
|
vm.startAdvancedSearch = startAdvancedSearch;
|
|
|
|
vm.stopAdvancedSearch = stopAdvancedSearch;
|
|
|
|
vm.search = {
|
|
|
|
options: {'': l('Select a criteria'),
|
|
|
|
subject: l('Enter Subject'),
|
|
|
|
from: l('Enter From'),
|
|
|
|
to: l('Enter To'),
|
|
|
|
cc: l('Enter Cc'),
|
|
|
|
body: l('Enter Body')
|
|
|
|
},
|
|
|
|
mailbox: 'INBOX',
|
|
|
|
subfolders: 1,
|
|
|
|
match: 'AND',
|
|
|
|
params: []
|
|
|
|
};
|
|
|
|
|
|
|
|
function showAdvancedSearch(path) {
|
|
|
|
vm.showingAdvancedSearch = true;
|
|
|
|
vm.search.mailbox = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideAdvancedSearch() {
|
|
|
|
vm.showingAdvancedSearch = false;
|
|
|
|
vm.service.$virtualMode = false;
|
|
|
|
|
|
|
|
account = vm.accounts[0];
|
|
|
|
mailbox = vm.searchPreviousMailbox;
|
|
|
|
$state.go('mail.account.mailbox', { accountId: account.id, mailboxId: encodeUriFilter(mailbox.path) });
|
|
|
|
}
|
|
|
|
|
|
|
|
function startAdvancedSearch() {
|
|
|
|
var root, mailboxes = [];
|
|
|
|
|
|
|
|
vm.virtualMailbox = new VirtualMailbox(vm.accounts[0]);
|
|
|
|
|
|
|
|
// Don't set the previous selected mailbox if we're in virtual mode
|
|
|
|
// That allows users to do multiple advanced search but return
|
|
|
|
// correctly to the previously selected mailbox once done.
|
|
|
|
if (!Mailbox.$virtualMode)
|
|
|
|
vm.searchPreviousMailbox = Mailbox.selectedFolder;
|
|
|
|
|
|
|
|
Mailbox.selectedFolder = vm.virtualMailbox;
|
|
|
|
Mailbox.$virtualMode = true;
|
|
|
|
|
|
|
|
if (angular.isDefined(vm.search.mailbox)) {
|
|
|
|
root = vm.accounts[0].$getMailboxByPath(vm.search.mailbox);
|
|
|
|
mailboxes.push(root);
|
|
|
|
|
|
|
|
if (vm.search.subfolders && root.children.length)
|
|
|
|
mailboxes.push(root.children);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mailboxes = vm.accounts[0].$flattenMailboxes();
|
|
|
|
}
|
|
|
|
|
|
|
|
vm.virtualMailbox.setMailboxes(mailboxes);
|
|
|
|
vm.virtualMailbox.startSearch(vm.search.match, vm.search.params);
|
|
|
|
$state.go('mail.account.virtualMailbox', { accountId: vm.accounts[0].id });
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopAdvancedSearch() {
|
|
|
|
vm.virtualMailbox.stopSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
function addSearchParam(v) {
|
|
|
|
vm.currentSearchParam = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
function newSearchParam(v) {
|
|
|
|
if (v.length && vm.currentSearchParam.length) {
|
|
|
|
var n = 0;
|
|
|
|
if (v.startsWith("!")) {
|
|
|
|
n = 1;
|
|
|
|
v = v.substring(1).trim();
|
|
|
|
}
|
|
|
|
vm.search.params.push({searchBy:vm.currentSearchParam, searchInput: v, negative: n});
|
|
|
|
vm.currentSearchParam = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 21:22:58 +02:00
|
|
|
if ($state.current.name == 'mail' && vm.accounts.length > 0 && vm.accounts[0].$mailboxes.length > 0) {
|
|
|
|
// Redirect to first mailbox of first account if no mailbox is selected
|
|
|
|
account = vm.accounts[0];
|
|
|
|
mailbox = account.$mailboxes[0];
|
|
|
|
$state.go('mail.account.mailbox', { accountId: account.id, mailboxId: encodeUriFilter(mailbox.path) });
|
|
|
|
}
|
|
|
|
|
|
|
|
function newFolder(parentFolder) {
|
2015-05-06 04:06:13 +02:00
|
|
|
Dialog.prompt(l('New folder'),
|
|
|
|
l('Enter the new name of your folder :'))
|
|
|
|
.then(function(name) {
|
2015-07-02 22:11:11 +02:00
|
|
|
parentFolder.$newMailbox(parentFolder.id, name)
|
|
|
|
.then(function() {
|
|
|
|
// success
|
|
|
|
}, function(data, status) {
|
|
|
|
Dialog.alert(l('An error occured while creating the mailbox "%{0}".', name),
|
|
|
|
l(data.error));
|
|
|
|
});
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
2015-07-13 21:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function delegate(account) {
|
2015-07-04 02:40:06 +02:00
|
|
|
$mdDialog.show({
|
|
|
|
templateUrl: account.id + '/delegation', // UI/Templates/MailerUI/UIxMailUserDelegation.wox
|
|
|
|
controller: MailboxDelegationController,
|
|
|
|
controllerAs: 'delegate',
|
|
|
|
clickOutsideToClose: true,
|
|
|
|
escapeToClose: true,
|
|
|
|
locals: {
|
|
|
|
User: User,
|
2015-07-04 13:51:20 +02:00
|
|
|
account: account
|
2015-07-04 02:40:06 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-07-04 13:51:20 +02:00
|
|
|
MailboxDelegationController.$inject = ['$scope', '$mdDialog', 'User', 'account'];
|
|
|
|
function MailboxDelegationController($scope, $mdDialog, User, account) {
|
2015-07-04 02:40:06 +02:00
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
vm.users = account.delegates;
|
|
|
|
vm.account = account;
|
|
|
|
vm.userToAdd = '';
|
|
|
|
vm.searchText = '';
|
|
|
|
vm.userFilter = userFilter;
|
|
|
|
vm.closeModal = closeModal;
|
|
|
|
vm.removeUser = removeUser;
|
|
|
|
vm.addUser = addUser;
|
|
|
|
|
|
|
|
function userFilter($query) {
|
|
|
|
return User.$filter($query, account.delegates);
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeModal() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeUser(user) {
|
2015-08-03 20:40:18 +02:00
|
|
|
account.$removeDelegate(user.uid).catch(function(data, status) {
|
2015-07-13 21:22:58 +02:00
|
|
|
Dialog.alert(l('Warning'), l('An error occured please try again.'));
|
2015-07-04 02:40:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function addUser(data) {
|
|
|
|
if (data) {
|
|
|
|
account.$addDelegate(data).then(function() {
|
|
|
|
vm.userToAdd = '';
|
|
|
|
vm.searchText = '';
|
|
|
|
}, function(error) {
|
|
|
|
Dialog.alert(l('Warning'), error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-13 21:22:58 +02:00
|
|
|
} // delegate
|
|
|
|
|
|
|
|
function editFolder(folder) {
|
|
|
|
vm.editMode = folder.path;
|
2015-05-06 04:06:13 +02:00
|
|
|
focus('mailboxName_' + folder.path);
|
2015-07-13 21:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function revertEditing(folder) {
|
2015-05-06 04:06:13 +02:00
|
|
|
folder.$reset();
|
2015-07-13 21:22:58 +02:00
|
|
|
vm.editMode = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectFolder(account, folder) {
|
|
|
|
if (vm.editMode == folder.path)
|
2015-05-06 04:06:13 +02:00
|
|
|
return;
|
2015-07-13 21:22:58 +02:00
|
|
|
vm.editMode = false;
|
2015-09-10 22:38:30 +02:00
|
|
|
vm.showingAdvancedSearch = false;
|
|
|
|
vm.service.$virtualMode = false;
|
2015-05-06 04:06:13 +02:00
|
|
|
$state.go('mail.account.mailbox', { accountId: account.id, mailboxId: encodeUriFilter(folder.path) });
|
2015-07-13 21:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveFolder(folder) {
|
2015-05-06 04:06:13 +02:00
|
|
|
folder.$rename();
|
2015-07-13 21:22:58 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 15:28:54 +02:00
|
|
|
function compactFolder(folder) {
|
|
|
|
folder.$compact().then(function() {
|
|
|
|
// Success
|
|
|
|
}, function(error) {
|
|
|
|
Dialog.alert(l('Warning'), error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function emptyTrashFolder(folder) {
|
|
|
|
folder.$emptyTrash().then(function() {
|
2015-08-11 20:48:45 +02:00
|
|
|
// Success
|
2015-07-21 15:28:54 +02:00
|
|
|
}, function(error) {
|
|
|
|
Dialog.alert(l('Warning'), error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-07-13 21:22:58 +02:00
|
|
|
function exportMails(folder) {
|
|
|
|
window.location.href = ApplicationBaseURL + '/' + folder.id + '/exportFolder';
|
|
|
|
}
|
|
|
|
|
|
|
|
function confirmDelete(folder) {
|
2015-05-06 04:06:13 +02:00
|
|
|
Dialog.confirm(l('Confirmation'), l('Do you really want to move this folder into the trash ?'))
|
|
|
|
.then(function() {
|
|
|
|
folder.$delete()
|
|
|
|
.then(function() {
|
|
|
|
$state.go('mail');
|
|
|
|
}, function(data, status) {
|
|
|
|
Dialog.alert(l('An error occured while deleting the mailbox "%{0}".', folder.name),
|
|
|
|
l(data.error));
|
|
|
|
});
|
|
|
|
});
|
2015-07-13 21:22:58 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 15:28:54 +02:00
|
|
|
function markFolderRead(folder) {
|
|
|
|
folder.$markAsRead();
|
|
|
|
}
|
|
|
|
|
2015-07-13 21:22:58 +02:00
|
|
|
function share(folder) {
|
2015-06-26 19:13:25 +02:00
|
|
|
// Fetch list of ACL users
|
|
|
|
folder.$acl.$users().then(function() {
|
|
|
|
// Show ACL editor
|
|
|
|
$mdDialog.show({
|
|
|
|
templateUrl: folder.id + '/UIxAclEditor', // UI/Templates/UIxAclEditor.wox
|
2015-07-28 16:53:29 +02:00
|
|
|
controller: 'AclController', // from the ng module SOGo.Common
|
2015-06-26 19:13:25 +02:00
|
|
|
controllerAs: 'acl',
|
|
|
|
clickOutsideToClose: true,
|
|
|
|
escapeToClose: true,
|
|
|
|
locals: {
|
|
|
|
usersWithACL: folder.$acl.users,
|
|
|
|
User: User,
|
2015-07-04 03:44:28 +02:00
|
|
|
folder: folder
|
2015-06-26 19:13:25 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2015-07-13 21:22:58 +02:00
|
|
|
} // share
|
2015-07-06 17:05:19 +02:00
|
|
|
|
2015-07-24 20:40:07 +02:00
|
|
|
function metadataForFolder(folder) {
|
2015-07-06 17:05:19 +02:00
|
|
|
if (folder.type == 'inbox')
|
2015-07-24 20:40:07 +02:00
|
|
|
return {name: folder.name, icon:'inbox'};
|
2015-07-06 17:05:19 +02:00
|
|
|
else if (folder.type == 'draft')
|
2015-07-24 20:40:07 +02:00
|
|
|
return {name: l('DraftsFolderName'), icon: 'drafts'};
|
2015-07-06 17:05:19 +02:00
|
|
|
else if (folder.type == 'sent')
|
2015-07-24 20:40:07 +02:00
|
|
|
return {name: l('SentFolderName'), icon: 'send'};
|
2015-07-06 17:05:19 +02:00
|
|
|
else if (folder.type == 'trash')
|
2015-07-24 20:40:07 +02:00
|
|
|
return {name: l('TrashFolderName'), icon: 'delete'};
|
2015-07-24 16:21:33 +02:00
|
|
|
else if (folder.type == 'additional')
|
2015-07-24 20:40:07 +02:00
|
|
|
return {name: folder.name, icon: 'folder_shared'};
|
2015-07-06 17:05:19 +02:00
|
|
|
|
|
|
|
//if ($rootScope.currentFolder == folder)
|
|
|
|
// return 'folder_open';
|
|
|
|
|
2015-07-24 20:40:07 +02:00
|
|
|
return {name: folder.name, icon: 'folder'};
|
|
|
|
}
|
|
|
|
|
|
|
|
function setFolderAs(folder, type) {
|
|
|
|
folder.$setFolderAs(type).then(function() {
|
|
|
|
folder.$account.$getMailboxes({reload: true});
|
|
|
|
}, function(error) {
|
|
|
|
Dialog.alert(l('Warning'), error);
|
|
|
|
});
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
2015-07-31 19:32:14 +02:00
|
|
|
|
|
|
|
function refreshUnseenCount() {
|
|
|
|
var unseenCountFolders = window.unseenCountFolders;
|
|
|
|
|
|
|
|
_.forEach(vm.accounts, function(account) {
|
|
|
|
|
|
|
|
// Always include the INBOX
|
|
|
|
if (!_.includes(unseenCountFolders, account.id + '/folderINBOX'))
|
|
|
|
unseenCountFolders.push(account.id + '/folderINBOX');
|
|
|
|
|
2015-07-31 20:31:38 +02:00
|
|
|
_.forEach(account.$$flattenMailboxes, function(mailbox) {
|
2015-07-31 19:32:14 +02:00
|
|
|
if (angular.isDefined(mailbox.unseenCount) &&
|
|
|
|
!_.includes(unseenCountFolders, mailbox.id))
|
|
|
|
unseenCountFolders.push(mailbox.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Account.$$resource.post('', 'unseenCount', {mailboxes: unseenCountFolders}).then(function(data) {
|
|
|
|
_.forEach(vm.accounts, function(account) {
|
2015-07-31 20:31:38 +02:00
|
|
|
_.forEach(account.$$flattenMailboxes, function(mailbox) {
|
2015-07-31 19:32:14 +02:00
|
|
|
if (data[mailbox.id])
|
|
|
|
mailbox.unseenCount = data[mailbox.id];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Preferences.ready().then(function() {
|
|
|
|
var refreshViewCheck = Preferences.defaults.SOGoRefreshViewCheck;
|
|
|
|
if (refreshViewCheck && refreshViewCheck != 'manually')
|
|
|
|
$timeout(vm.refreshUnseenCount, refreshViewCheck.timeInterval()*1000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
vm.refreshUnseenCount();
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('SOGo.MailerUI')
|
|
|
|
.controller('MailboxesController', MailboxesController);
|
|
|
|
})();
|
|
|
|
|