diff --git a/UI/WebServerResources/js/Mailer/MailboxesController.js b/UI/WebServerResources/js/Mailer/MailboxesController.js index 6bf15e79f..d1f92117e 100644 --- a/UI/WebServerResources/js/Mailer/MailboxesController.js +++ b/UI/WebServerResources/js/Mailer/MailboxesController.js @@ -52,8 +52,8 @@ key: 'backspace', description: l('Delete selected message or folder'), callback: function() { - if (Mailbox.selectedFolder && !Mailbox.selectedFolder.hasSelectedMessage()) - confirmDelete(Mailbox.selectedFolder); + if (Mailbox.selectedFolderController && Mailbox.selectedFolder && !Mailbox.selectedFolder.hasSelectedMessage()) + Mailbox.selectedFolderController.confirmDelete(Mailbox.selectedFolder); } })); diff --git a/UI/WebServerResources/js/Mailer/sgAccountSection.directive.js b/UI/WebServerResources/js/Mailer/sgAccountSection.directive.js index 0ba4eb271..102e4bf19 100644 --- a/UI/WebServerResources/js/Mailer/sgAccountSection.directive.js +++ b/UI/WebServerResources/js/Mailer/sgAccountSection.directive.js @@ -37,6 +37,7 @@ // Called from a sgMailboxListItem controller this.selectFolder = function (mailboxController) { + Mailbox.selectedFolderController = mailboxController; if (Mailbox.selectedFolder !== null) { var selectedMailboxCtrl = _.find(mailboxes, function(ctrl) { return ctrl.mailbox.id == Mailbox.selectedFolder.id; diff --git a/UI/WebServerResources/js/Mailer/sgMailboxListItem.directive.js b/UI/WebServerResources/js/Mailer/sgMailboxListItem.directive.js index 8e4d83d2d..303bb482d 100644 --- a/UI/WebServerResources/js/Mailer/sgMailboxListItem.directive.js +++ b/UI/WebServerResources/js/Mailer/sgMailboxListItem.directive.js @@ -74,7 +74,7 @@ // Check if router's state has selected a mailbox if (Mailbox.selectedFolder !== null && Mailbox.selectedFolder.id == this.mailbox.id) { - this.selectFolder(); + this.accountController.selectFolder(this); } }; @@ -145,6 +145,32 @@ }; + this.confirmDelete = function() { + Dialog.confirm(l('Warning'), + l('Do you really want to move this folder into the trash ?'), + { ok: l('Delete') }) + .then(function() { + $ctrl.mailbox.$delete() + .then(function() { + $state.go('mail.account.inbox'); + }, function(response) { + Dialog.confirm(l('Warning'), + l('The mailbox could not be moved to the trash folder. Would you like to delete it immediately?'), + { ok: l('Delete') }) + .then(function() { + $ctrl.mailbox.$delete({ withoutTrash: true }) + .then(function() { + $state.go('mail.account.inbox'); + }, function(response) { + Dialog.alert(l('An error occured while deleting the mailbox "%{0}".', $ctrl.mailbox.name), + l(response.error)); + }); + }); + }); + }); + }; + + this.showMenu = function($event) { var panelPosition = $mdPanel.newPanelPosition() .relativeTo(this.moreOptionsButton) @@ -162,7 +188,8 @@ attachTo: angular.element(document.body), locals: { itemCtrl: this, - folder: this.mailbox + folder: this.mailbox, + confirmDelete: this.confirmDelete }, bindToController: true, controller: MenuController, @@ -231,31 +258,6 @@ }); }; - this.confirmDelete = function() { - Dialog.confirm(l('Warning'), - l('Do you really want to move this folder into the trash ?'), - { ok: l('Delete') }) - .then(function() { - $menuCtrl.folder.$delete() - .then(function() { - $state.go('mail.account.inbox'); - }, function(response) { - Dialog.confirm(l('Warning'), - l('The mailbox could not be moved to the trash folder. Would you like to delete it immediately?'), - { ok: l('Delete') }) - .then(function() { - $menuCtrl.folder.$delete({ withoutTrash: true }) - .then(function() { - $state.go('mail.account.inbox'); - }, function(response) { - Dialog.alert(l('An error occured while deleting the mailbox "%{0}".', $menuCtrl.folder.name), - l(response.error)); - }); - }); - }); - }); - }; - this.showAdvancedSearch = function() { Mailbox.$virtualPath = this.folder.path; // Close sidenav on small devices