(js) Fix hotkeys with an active dialog in Mailer

Fixes #3983
pull/232/head
Francis Lachapelle 2017-01-06 18:26:12 -05:00
parent 327ebf00a4
commit 3560f0486e
3 changed files with 45 additions and 22 deletions

1
NEWS
View File

@ -39,6 +39,7 @@ Bug fixes
- [web] fixed computation of week number (#3973, #3976)
- [web] fixed saving of inactive calendars (#3862, #3980)
- [web] fixed public URLs to Calendars (#3974)
- [web] fixed hotkeys in Mail module when a dialog is active (#3983)
- [eas] properly skip folders we don't want to synchronize (#3943)
- [eas] fixed 30 mins freebusy offset with S Planner
- [eas] now correctly handles reminders on tasks (#3964)

View File

@ -8,7 +8,7 @@
*/
MailboxController.$inject = ['$window', '$scope', '$timeout', '$q', '$state', '$mdDialog', '$mdToast', 'stateAccounts', 'stateAccount', 'stateMailbox', 'sgHotkeys', 'encodeUriFilter', 'sgFocus', 'Dialog', 'Account', 'Mailbox'];
function MailboxController($window, $scope, $timeout, $q, $state, $mdDialog, $mdToast, stateAccounts, stateAccount, stateMailbox, sgHotkeys, encodeUriFilter, focus, Dialog, Account, Mailbox) {
var vm = this, messageDialog = null,
var vm = this,
defaultWindowTitle = angular.element($window.document).find('title').attr('sg-default') || "SOGo",
hotkeys = [];
@ -20,6 +20,7 @@
vm.account = stateAccount;
vm.selectedFolder = stateMailbox;
vm.selectMessage = selectMessage;
vm.messageDialog = null; // also access from Message controller
vm.toggleMessageSelection = toggleMessageSelection;
vm.sort = sort;
vm.sortedBy = sortedBy;
@ -71,7 +72,10 @@
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_compose'),
description: l('Write a new message'),
callback: newMessage
callback: function($event) {
if (vm.messageDialog === null)
newMessage($event);
}
}));
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_junk'),
@ -155,9 +159,9 @@
function newMessage($event) {
var message;
if (messageDialog === null) {
if (vm.messageDialog === null) {
message = vm.account.$newMessage();
messageDialog = $mdDialog
vm.messageDialog = $mdDialog
.show({
parent: angular.element(document.body),
targetEvent: $event,
@ -173,7 +177,7 @@
}
})
.finally(function() {
messageDialog = null;
vm.messageDialog = null;
});
}
}
@ -344,8 +348,8 @@
function confirmDeleteSelectedMessages($event) {
var selectedMessages = vm.selectedFolder.$selectedMessages();
if (messageDialog === null && _.size(selectedMessages) > 0)
messageDialog = Dialog.confirm(l('Confirmation'),
if (vm.messageDialog === null && _.size(selectedMessages) > 0)
vm.messageDialog = Dialog.confirm(l('Confirmation'),
l('Are you sure you want to delete the selected messages?'),
{ ok: l('Delete') })
.then(function() {
@ -362,7 +366,7 @@
_unselectMessage(deleteSelectedMessage, index);
}
}, function(response) {
messageDialog = Dialog.confirm(l('Warning'),
vm.messageDialog = Dialog.confirm(l('Warning'),
l('The messages could not be moved to the trash folder. Would you like to delete them immediately?'),
{ ok: l('Delete') })
.then(function() {
@ -382,7 +386,7 @@
});
})
.finally(function() {
messageDialog = null;
vm.messageDialog = null;
});
$event.preventDefault();

View File

@ -8,7 +8,7 @@
*/
MessageController.$inject = ['$window', '$scope', '$state', '$mdMedia', '$mdDialog', 'sgConstant', 'stateAccounts', 'stateAccount', 'stateMailbox', 'stateMessage', 'sgHotkeys', 'encodeUriFilter', 'sgSettings', 'sgFocus', 'Dialog', 'Calendar', 'Component', 'Account', 'Mailbox', 'Message'];
function MessageController($window, $scope, $state, $mdMedia, $mdDialog, sgConstant, stateAccounts, stateAccount, stateMailbox, stateMessage, sgHotkeys, encodeUriFilter, sgSettings, focus, Dialog, Calendar, Component, Account, Mailbox, Message) {
var vm = this, messageDialog = null, popupWindow = null, hotkeys = [];
var vm = this, popupWindow = null, hotkeys = [];
// Expose controller
$window.$messageController = vm;
@ -39,7 +39,6 @@
vm.convertToEvent = convertToEvent;
vm.convertToTask = convertToTask;
_registerHotkeys(hotkeys);
// One-way refresh of the parent window when modifying the message from a popup window.
@ -104,34 +103,51 @@
});
/**
* To keep track of the currently active dialog, we share a common variable with the parent controller.
*/
function _messageDialog() {
if (arguments.length > 0)
$scope.mailbox.messageDialog = arguments[0];
return $scope.mailbox.messageDialog;
}
function _unlessInDialog(callback) {
return function() {
// Check if a dialog is opened either from the current controller or the parent controller
if (_messageDialog() === null)
return callback.apply(vm, arguments);
};
}
function _registerHotkeys(keys) {
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_reply'),
description: l('Reply to the message'),
callback: reply
callback: _unlessInDialog(reply)
}));
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_replyall'),
description: l('Reply to sender and all recipients'),
callback: replyAll
callback: _unlessInDialog(replyAll)
}));
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_forward'),
description: l('Forward selected message'),
callback: forward
callback: _unlessInDialog(forward)
}));
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_flag'),
description: l('Flagged'),
callback: angular.bind(stateMessage, stateMessage.toggleFlag)
callback: _unlessInDialog(angular.bind(stateMessage, stateMessage.toggleFlag))
}));
keys.push(sgHotkeys.createHotkey({
key: 'backspace',
callback: function($event) {
callback: _unlessInDialog(function($event) {
if (vm.mailbox.$selectedCount() === 0)
deleteMessage();
$event.preventDefault();
}
})
}));
// Register the hotkeys
@ -261,9 +277,10 @@
}
function showMailEditor($event, message) {
if (messageDialog === null) {
messageDialog = $mdDialog
.show({
if (_messageDialog() === null) {
_messageDialog(
$mdDialog
.show({
parent: angular.element(document.body),
targetEvent: $event,
clickOutsideToClose: false,
@ -277,9 +294,10 @@
}
})
.finally(function() {
messageDialog = null;
_messageDialog(null);
closePopup();
});
})
);
}
}