2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-08-02 19:25:38 +02:00
|
|
|
MailboxController.$inject = ['$state', '$timeout', '$mdDialog', 'stateAccounts', 'stateAccount', 'stateMailbox', 'encodeUriFilter', 'sgFocus', 'Dialog', 'Account', 'Mailbox'];
|
|
|
|
function MailboxController($state, $timeout, $mdDialog, stateAccounts, stateAccount, stateMailbox, encodeUriFilter, focus, Dialog, Account, Mailbox) {
|
2015-08-27 03:22:39 +02:00
|
|
|
var vm = this, messageDialog = null;
|
2015-07-13 21:22:58 +02:00
|
|
|
|
|
|
|
Mailbox.selectedFolder = stateMailbox;
|
|
|
|
|
2015-07-22 17:28:08 +02:00
|
|
|
vm.service = Mailbox;
|
2015-07-13 21:22:58 +02:00
|
|
|
vm.accounts = stateAccounts;
|
|
|
|
vm.account = stateAccount;
|
|
|
|
vm.selectedFolder = stateMailbox;
|
|
|
|
vm.selectMessage = selectMessage;
|
2015-09-09 21:18:00 +02:00
|
|
|
vm.toggleMessageSelection = toggleMessageSelection;
|
2015-07-13 21:22:58 +02:00
|
|
|
vm.unselectMessages = unselectMessages;
|
|
|
|
vm.confirmDeleteSelectedMessages = confirmDeleteSelectedMessages;
|
|
|
|
vm.copySelectedMessages = copySelectedMessages;
|
|
|
|
// vm.moveSelectedMessages = moveSelectedMessages;
|
2015-08-05 20:39:58 +02:00
|
|
|
vm.saveSelectedMessages = saveSelectedMessages;
|
2015-08-10 19:10:45 +02:00
|
|
|
vm.markSelectedMessagesAsFlagged = markSelectedMessagesAsFlagged;
|
|
|
|
vm.markSelectedMessagesAsUnread = markSelectedMessagesAsUnread;
|
2015-07-23 16:54:46 +02:00
|
|
|
vm.selectAll = selectAll;
|
2015-07-20 22:44:26 +02:00
|
|
|
vm.sort = sort;
|
|
|
|
vm.sortedBy = sortedBy;
|
|
|
|
vm.cancelSearch = cancelSearch;
|
2015-08-02 19:25:38 +02:00
|
|
|
vm.newMessage = newMessage;
|
2015-07-20 22:44:26 +02:00
|
|
|
vm.mode = { search: false };
|
2015-07-15 19:44:17 +02:00
|
|
|
|
2015-07-13 21:22:58 +02:00
|
|
|
function selectMessage(message) {
|
2015-05-08 18:06:52 +02:00
|
|
|
$state.go('mail.account.mailbox.message', {accountId: stateAccount.id, mailboxId: encodeUriFilter(stateMailbox.path), messageId: message.uid});
|
2015-07-13 21:22:58 +02:00
|
|
|
}
|
|
|
|
|
2015-09-09 21:18:00 +02:00
|
|
|
function toggleMessageSelection($event, message) {
|
|
|
|
message.selected = !message.selected;
|
|
|
|
$event.preventDefault();
|
|
|
|
$event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2015-07-13 21:22:58 +02:00
|
|
|
function unselectMessages() {
|
|
|
|
_.each(vm.selectedFolder.$messages, function(message) { message.selected = false; });
|
|
|
|
}
|
|
|
|
|
|
|
|
function confirmDeleteSelectedMessages() {
|
|
|
|
Dialog.confirm(l('Warning'),
|
|
|
|
l('Are you sure you want to delete the selected messages?'))
|
|
|
|
.then(function() {
|
|
|
|
// User confirmed the deletion
|
2015-07-24 22:14:53 +02:00
|
|
|
var selectedMessages = _.filter(vm.selectedFolder.$messages, function(message) { return message.selected; });
|
2015-07-13 21:22:58 +02:00
|
|
|
var selectedUIDs = _.pluck(selectedMessages, 'uid');
|
|
|
|
vm.selectedFolder.$deleteMessages(selectedUIDs).then(function() {
|
2015-08-11 21:05:31 +02:00
|
|
|
// Decrement the unseenCount accordingly
|
|
|
|
var unseenCount = _.filter(selectedMessages, function(message) { return !message.isread; });
|
2015-07-13 21:22:58 +02:00
|
|
|
vm.selectedFolder.$messages = _.difference(vm.selectedFolder.$messages, selectedMessages);
|
2015-08-11 21:05:31 +02:00
|
|
|
vm.selectedFolder.unseenCount =- unseenCount;
|
2015-08-05 20:39:58 +02:00
|
|
|
}, function(error) {
|
|
|
|
Dialog.alert(l('Error'), error);
|
2015-07-13 21:22:58 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function copySelectedMessages(folder) {
|
2015-07-24 22:14:53 +02:00
|
|
|
var selectedMessages = _.filter(vm.selectedFolder.$messages, function(message) { return message.selected; });
|
2015-07-13 21:22:58 +02:00
|
|
|
var selectedUIDs = _.pluck(selectedMessages, 'uid');
|
|
|
|
vm.selectedFolder.$copyMessages(selectedUIDs, '/' + folder).then(function() {
|
|
|
|
// TODO: refresh target mailbox?
|
|
|
|
}, function(error) {
|
2015-08-05 20:39:58 +02:00
|
|
|
Dialog.alert(l('Error'), error);
|
2015-07-13 21:22:58 +02:00
|
|
|
});
|
|
|
|
}
|
2015-05-09 20:37:40 +02:00
|
|
|
|
2015-07-13 21:22:58 +02:00
|
|
|
// function moveSelectedMessages(folder) {
|
|
|
|
// var selectedMessages = _.filter(vm.selectedFolder.$messages, function(message) { return message.selected });
|
|
|
|
// var selectedUIDs = _.pluck(selectedMessages, 'uid');
|
|
|
|
// vm.selectedFolder.$moveMessages(selectedUIDs, '/' + folder).then(function() {
|
|
|
|
// // TODO: refresh target mailbox?
|
|
|
|
// vm.selectedFolder.$messages = _.difference(vm.selectedFolder.$messages, selectedMessages);
|
|
|
|
// });
|
|
|
|
// }
|
2015-07-20 22:44:26 +02:00
|
|
|
|
2015-08-05 20:39:58 +02:00
|
|
|
function saveSelectedMessages() {
|
|
|
|
var selectedMessages = _.filter(vm.selectedFolder.$messages, function(message) { return message.selected; });
|
|
|
|
var selectedUIDs = _.pluck(selectedMessages, 'uid');
|
|
|
|
window.location.href = ApplicationBaseURL + '/' + vm.selectedFolder.id + '/saveMessages?uid=' + selectedUIDs.join(",");
|
|
|
|
}
|
|
|
|
|
2015-07-23 16:54:46 +02:00
|
|
|
function selectAll() {
|
|
|
|
_.each(vm.selectedFolder.$messages, function(message) {
|
|
|
|
message.selected = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-08-10 19:10:45 +02:00
|
|
|
function markSelectedMessagesAsFlagged() {
|
|
|
|
var selectedMessages = _.filter(vm.selectedFolder.$messages, function(message) { return message.selected; });
|
|
|
|
var selectedUIDs = _.pluck(selectedMessages, 'uid');
|
|
|
|
|
|
|
|
vm.selectedFolder.$flagMessages(selectedUIDs, '\\Flagged', 'add').then(function(d) {
|
|
|
|
// Success
|
|
|
|
_.forEach(selectedMessages, function(message) {
|
|
|
|
message.isflagged = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function markSelectedMessagesAsUnread() {
|
|
|
|
var selectedMessages = _.filter(vm.selectedFolder.$messages, function(message) { return message.selected; });
|
|
|
|
var selectedUIDs = _.pluck(selectedMessages, 'uid');
|
|
|
|
|
|
|
|
vm.selectedFolder.$flagMessages(selectedUIDs, 'seen', 'remove').then(function(d) {
|
|
|
|
// Success
|
|
|
|
_.forEach(selectedMessages, function(message) {
|
|
|
|
message.isread = false;
|
|
|
|
vm.selectedFolder.unseenCount++;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-07-20 22:44:26 +02:00
|
|
|
function sort(field) {
|
|
|
|
vm.selectedFolder.$filter({ sort: field });
|
|
|
|
}
|
|
|
|
|
|
|
|
function sortedBy(field) {
|
2015-07-22 17:28:08 +02:00
|
|
|
return Mailbox.$query.sort == field;
|
2015-07-20 22:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function cancelSearch() {
|
|
|
|
vm.mode.search = false;
|
|
|
|
vm.selectedFolder.$filter();
|
|
|
|
}
|
2015-07-30 19:06:28 +02:00
|
|
|
|
2015-08-02 19:25:38 +02:00
|
|
|
function newMessage($event) {
|
2015-08-27 03:22:39 +02:00
|
|
|
var message;
|
|
|
|
|
|
|
|
if (messageDialog === null) {
|
|
|
|
message = vm.account.$newMessage();
|
|
|
|
messageDialog = $mdDialog
|
|
|
|
.show({
|
|
|
|
parent: angular.element(document.body),
|
|
|
|
targetEvent: $event,
|
|
|
|
clickOutsideToClose: false,
|
|
|
|
escapeToClose: false,
|
|
|
|
templateUrl: 'UIxMailEditor',
|
|
|
|
controller: 'MessageEditorController',
|
|
|
|
controllerAs: 'editor',
|
|
|
|
locals: {
|
|
|
|
stateAccounts: vm.accounts,
|
|
|
|
stateMessage: message,
|
|
|
|
stateRecipients: []
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(function() {
|
|
|
|
messageDialog = null;
|
|
|
|
});
|
|
|
|
}
|
2015-08-02 19:25:38 +02:00
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
2015-09-09 21:18:00 +02:00
|
|
|
.module('SOGo.MailerUI')
|
|
|
|
.controller('MailboxController', MailboxController);
|
2015-05-06 04:06:13 +02:00
|
|
|
})();
|
|
|
|
|