2016-09-23 23:17:25 +02:00
|
|
|
/* -*- Mode: js; indent-tabs-mode: nil; js-indent-level: 2; -*- */
|
2015-05-06 04:06:13 +02:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2016-09-27 21:19:24 +02:00
|
|
|
MailboxesController.$inject = ['$scope', '$state', '$timeout', '$window', '$mdDialog', '$mdToast', '$mdMedia', '$mdSidenav', 'sgConstant', 'sgFocus', 'encodeUriFilter', 'Dialog', 'sgSettings', 'sgHotkeys', 'Account', 'Mailbox', 'VirtualMailbox', 'User', 'Preferences', 'stateAccounts'];
|
|
|
|
function MailboxesController($scope, $state, $timeout, $window, $mdDialog, $mdToast, $mdMedia, $mdSidenav, sgConstant, focus, encodeUriFilter, Dialog, Settings, sgHotkeys, Account, Mailbox, VirtualMailbox, User, Preferences, stateAccounts) {
|
2015-07-13 21:22:58 +02:00
|
|
|
var vm = this,
|
|
|
|
account,
|
2016-09-27 21:19:24 +02:00
|
|
|
mailbox,
|
|
|
|
hotkeys = [];
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2015-07-13 21:22:58 +02:00
|
|
|
vm.service = Mailbox;
|
|
|
|
vm.accounts = stateAccounts;
|
2016-05-26 21:48:15 +02:00
|
|
|
vm.toggleAccountState = toggleAccountState;
|
2016-09-14 21:57:49 +02:00
|
|
|
vm.subscribe = subscribe;
|
2015-07-13 21:22:58 +02:00
|
|
|
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.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;
|
2016-08-04 23:34:29 +02:00
|
|
|
vm.isDroppableFolder = isDroppableFolder;
|
|
|
|
vm.dragSelectedMessages = dragSelectedMessages;
|
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;
|
2015-09-15 03:35:34 +02:00
|
|
|
vm.toggleAdvancedSearch = toggleAdvancedSearch;
|
2015-09-10 22:38:30 +02:00
|
|
|
vm.search = {
|
2016-10-21 16:55:59 +02:00
|
|
|
options: {'': '', // no placeholder when no criteria is active
|
2015-09-10 22:38:30 +02:00
|
|
|
subject: l('Enter Subject'),
|
2016-10-21 16:55:59 +02:00
|
|
|
from: l('Enter From'),
|
|
|
|
to: l('Enter To'),
|
|
|
|
cc: l('Enter Cc'),
|
|
|
|
body: l('Enter Body')
|
2015-09-10 22:38:30 +02:00
|
|
|
},
|
|
|
|
mailbox: 'INBOX',
|
|
|
|
subfolders: 1,
|
|
|
|
match: 'AND',
|
|
|
|
params: []
|
|
|
|
};
|
|
|
|
|
2016-09-27 21:19:24 +02:00
|
|
|
|
2016-09-14 21:57:49 +02:00
|
|
|
Preferences.ready().then(function() {
|
|
|
|
vm.showSubscribedOnly = Preferences.defaults.SOGoMailShowSubscribedFoldersOnly;
|
|
|
|
});
|
|
|
|
|
2016-08-04 23:34:29 +02:00
|
|
|
vm.refreshUnseenCount();
|
|
|
|
|
2016-09-27 21:19:24 +02:00
|
|
|
_registerHotkeys(hotkeys);
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function() {
|
|
|
|
// Deregister hotkeys
|
|
|
|
_.forEach(hotkeys, function(key) {
|
|
|
|
sgHotkeys.deregisterHotkey(key);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function _registerHotkeys(keys) {
|
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: 'backspace',
|
|
|
|
description: l('Delete selected message or folder'),
|
|
|
|
callback: function() {
|
|
|
|
if (Mailbox.selectedFolder && !Mailbox.selectedFolder.hasSelectedMessage())
|
|
|
|
confirmDelete(Mailbox.selectedFolder);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Register the hotkeys
|
|
|
|
_.forEach(keys, function(key) {
|
|
|
|
sgHotkeys.registerHotkey(key);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-09-10 22:38:30 +02:00
|
|
|
function showAdvancedSearch(path) {
|
|
|
|
vm.showingAdvancedSearch = true;
|
|
|
|
vm.search.mailbox = path;
|
2016-01-18 20:05:33 +01:00
|
|
|
// Close sidenav on small devices
|
2016-05-18 20:35:24 +02:00
|
|
|
if (!$mdMedia(sgConstant['gt-md']))
|
2016-01-18 20:05:33 +01:00
|
|
|
$mdSidenav('left').close();
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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) });
|
|
|
|
}
|
|
|
|
|
2015-09-15 03:35:34 +02:00
|
|
|
function toggleAdvancedSearch() {
|
|
|
|
if (Mailbox.selectedFolder.$isLoading) {
|
2015-10-02 21:43:02 +02:00
|
|
|
// Stop search
|
2015-09-15 03:35:34 +02:00
|
|
|
vm.virtualMailbox.stopSearch();
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
|
|
|
else {
|
2015-10-02 21:43:02 +02:00
|
|
|
// Start search
|
2015-09-15 03:35:34 +02:00
|
|
|
var root, mailboxes = [],
|
|
|
|
_visit = function(folders) {
|
2016-03-03 19:38:54 +01:00
|
|
|
_.forEach(folders, function(o) {
|
2015-09-15 03:35:34 +02:00
|
|
|
mailboxes.push(o);
|
|
|
|
if (o.children && o.children.length > 0) {
|
|
|
|
_visit(o.children);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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)
|
|
|
|
_visit(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 });
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addSearchParam(v) {
|
|
|
|
vm.currentSearchParam = v;
|
2015-09-15 03:35:34 +02:00
|
|
|
focus('advancedSearch');
|
2015-10-02 21:43:02 +02:00
|
|
|
return false;
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
|
|
|
|
2015-10-02 21:43:02 +02:00
|
|
|
function newSearchParam(pattern) {
|
|
|
|
if (pattern.length && vm.currentSearchParam.length) {
|
|
|
|
var n = 0, searchParam = vm.currentSearchParam;
|
|
|
|
if (pattern.startsWith("!")) {
|
2015-09-10 22:38:30 +02:00
|
|
|
n = 1;
|
2015-10-02 21:43:02 +02:00
|
|
|
pattern = pattern.substring(1).trim();
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
|
|
|
vm.currentSearchParam = '';
|
2015-10-02 21:43:02 +02:00
|
|
|
return { searchBy: searchParam, searchInput: pattern, negative: n };
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-26 21:48:15 +02:00
|
|
|
function toggleAccountState(account) {
|
|
|
|
account.$expanded = !account.$expanded;
|
|
|
|
account.$flattenMailboxes({ reload: true, saveState: true });
|
|
|
|
// Fire a window resize to recompute the virtual-repeater.
|
|
|
|
// This is a fix until the following issue is officially resolved:
|
|
|
|
// https://github.com/angular/material/issues/7309
|
|
|
|
$timeout(function() {
|
|
|
|
angular.element($window).triggerHandler('resize');
|
|
|
|
}, 150);
|
|
|
|
}
|
|
|
|
|
2016-09-14 21:57:49 +02:00
|
|
|
function subscribe(account) {
|
|
|
|
$mdDialog.show({
|
|
|
|
templateUrl: account.id + '/subscribe',
|
|
|
|
controller: SubscriptionsDialogController,
|
|
|
|
controllerAs: 'subscriptions',
|
|
|
|
clickOutsideToClose: true,
|
|
|
|
escapeToClose: true,
|
|
|
|
locals: {
|
2016-09-30 18:02:46 +02:00
|
|
|
metadataForFolder: metadataForFolder,
|
2016-09-14 21:57:49 +02:00
|
|
|
srcAccount: account
|
|
|
|
}
|
|
|
|
}).finally(function() {
|
|
|
|
account.$getMailboxes({reload: true});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2016-09-30 18:02:46 +02:00
|
|
|
SubscriptionsDialogController.$inject = ['$scope', '$mdDialog', 'metadataForFolder', 'srcAccount'];
|
|
|
|
function SubscriptionsDialogController($scope, $mdDialog, metadataForFolder, srcAccount) {
|
2016-09-14 21:57:49 +02:00
|
|
|
var vm = this;
|
|
|
|
|
2016-09-30 18:02:46 +02:00
|
|
|
vm.loading = true;
|
|
|
|
vm.filter = { name: '' };
|
|
|
|
vm.metadataForFolder = metadataForFolder;
|
|
|
|
vm.account = new Account({
|
|
|
|
id: srcAccount.id,
|
|
|
|
name: srcAccount.name
|
|
|
|
});
|
2016-09-14 21:57:49 +02:00
|
|
|
vm.close = close;
|
|
|
|
|
2016-09-30 18:02:46 +02:00
|
|
|
|
|
|
|
vm.account.$getMailboxes().then(function() {
|
|
|
|
vm.loading = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-09-14 21:57:49 +02:00
|
|
|
function close() {
|
|
|
|
$mdDialog.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 21:22:58 +02:00
|
|
|
function newFolder(parentFolder) {
|
2016-10-21 16:55:59 +02:00
|
|
|
Dialog.prompt(l('New Folder...'),
|
|
|
|
l('Enter the new name of your folder'))
|
2015-05-06 04:06:13 +02:00
|
|
|
.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;
|
|
|
|
}
|
|
|
|
|
2016-01-07 22:33:41 +01:00
|
|
|
function selectFolder($event, account, folder) {
|
2015-07-13 21:22:58 +02:00
|
|
|
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-12-22 03:16:20 +01:00
|
|
|
// Close sidenav on small devices
|
2016-05-18 20:35:24 +02:00
|
|
|
if (!$mdMedia(sgConstant['gt-md']))
|
2015-11-25 17:12:30 +01:00
|
|
|
$mdSidenav('left').close();
|
2015-05-06 04:06:13 +02:00
|
|
|
$state.go('mail.account.mailbox', { accountId: account.id, mailboxId: encodeUriFilter(folder.path) });
|
2016-01-07 22:33:41 +01:00
|
|
|
$event.stopPropagation();
|
|
|
|
$event.preventDefault();
|
2015-07-13 21:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveFolder(folder) {
|
2015-09-16 22:15:04 +02:00
|
|
|
folder.$rename()
|
|
|
|
.then(function(data) {
|
|
|
|
vm.editMode = false;
|
|
|
|
});
|
2015-07-13 21:22:58 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 15:28:54 +02:00
|
|
|
function compactFolder(folder) {
|
|
|
|
folder.$compact().then(function() {
|
2015-12-10 19:54:24 +01:00
|
|
|
$mdToast.show(
|
|
|
|
$mdToast.simple()
|
|
|
|
.content(l('Folder compacted'))
|
|
|
|
.position('top right')
|
|
|
|
.hideDelay(3000));
|
2015-07-21 15:28:54 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function emptyTrashFolder(folder) {
|
|
|
|
folder.$emptyTrash().then(function() {
|
2015-12-22 03:16:20 +01:00
|
|
|
$mdToast.show(
|
|
|
|
$mdToast.simple()
|
|
|
|
.content(l('Trash emptied'))
|
|
|
|
.position('top right')
|
|
|
|
.hideDelay(3000));
|
2015-07-21 15:28:54 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-07-13 21:22:58 +02:00
|
|
|
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() {
|
2016-01-15 21:09:13 +01:00
|
|
|
$state.go('mail.account.inbox');
|
2015-05-06 04:06:13 +02:00
|
|
|
}, 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')
|
2016-09-14 21:57:49 +02:00
|
|
|
return {name: folder.name, icon:'inbox', special: true};
|
2015-07-06 17:05:19 +02:00
|
|
|
else if (folder.type == 'draft')
|
2016-09-14 21:57:49 +02:00
|
|
|
return {name: l('DraftsFolderName'), icon: 'drafts', special: true};
|
2015-07-06 17:05:19 +02:00
|
|
|
else if (folder.type == 'sent')
|
2016-09-14 21:57:49 +02:00
|
|
|
return {name: l('SentFolderName'), icon: 'send', special: true};
|
2015-07-06 17:05:19 +02:00
|
|
|
else if (folder.type == 'trash')
|
2016-09-14 21:57:49 +02:00
|
|
|
return {name: l('TrashFolderName'), icon: 'delete', special: true};
|
2016-02-08 21:36:01 +01:00
|
|
|
else if (folder.type == 'junk')
|
2016-09-14 21:57:49 +02:00
|
|
|
return {name: l('JunkFolderName'), icon: 'thumb_down', special: true};
|
2015-07-24 16:21:33 +02:00
|
|
|
else if (folder.type == 'additional')
|
2016-09-14 21:57:49 +02:00
|
|
|
return {name: folder.name, icon: 'folder_shared', special: true};
|
2015-07-06 17:05:19 +02:00
|
|
|
|
2016-09-14 21:57:49 +02:00
|
|
|
return {name: folder.name, icon: 'folder_open', special: false};
|
2015-07-24 20:40:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setFolderAs(folder, type) {
|
|
|
|
folder.$setFolderAs(type).then(function() {
|
|
|
|
folder.$account.$getMailboxes({reload: true});
|
|
|
|
});
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
2015-07-31 19:32:14 +02:00
|
|
|
|
|
|
|
function refreshUnseenCount() {
|
2016-09-23 23:17:25 +02:00
|
|
|
var unseenCountFolders = $window.unseenCountFolders;
|
2015-07-31 19:32:14 +02:00
|
|
|
|
|
|
|
_.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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-08-04 23:34:29 +02:00
|
|
|
function isDroppableFolder(srcFolder, dstFolder) {
|
|
|
|
return (dstFolder.id != srcFolder.id) && !dstFolder.isNoSelect();
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragSelectedMessages(srcFolder, dstFolder, mode) {
|
|
|
|
var dstId, messages, uids, clearMessageView, promise, success;
|
|
|
|
|
|
|
|
dstId = '/' + dstFolder.id;
|
|
|
|
messages = srcFolder.$selectedMessages();
|
|
|
|
if (messages.length === 0)
|
|
|
|
messages = [srcFolder.$selectedMessage()];
|
|
|
|
uids = _.map(messages, 'uid');
|
|
|
|
clearMessageView = (srcFolder.selectedMessage && uids.indexOf(srcFolder.selectedMessage) >= 0);
|
|
|
|
|
|
|
|
if (mode == 'copy') {
|
|
|
|
promise = srcFolder.$copyMessages(messages, dstId);
|
|
|
|
success = l('%{0} message(s) copied', messages.length);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
promise = srcFolder.$moveMessages(messages, dstId);
|
|
|
|
success = l('%{0} message(s) moved', messages.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
promise.then(function() {
|
|
|
|
if (clearMessageView)
|
|
|
|
$state.go('mail.account.mailbox');
|
|
|
|
$mdToast.show(
|
|
|
|
$mdToast.simple()
|
|
|
|
.content(success)
|
|
|
|
.position('top right')
|
|
|
|
.hideDelay(2000));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
2016-08-04 23:34:29 +02:00
|
|
|
.module('SOGo.MailerUI')
|
|
|
|
.controller('MailboxesController', MailboxesController);
|
2015-05-06 04:06:13 +02:00
|
|
|
})();
|
|
|
|
|