From 6ef99a5ec4a655323ddbc9da8955239a432e5180 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 24 Nov 2021 17:07:02 -0500 Subject: [PATCH] fix(mail(js)): save draft after having removed an attachment Fixes #5432 --- .../js/Mailer/Message.service.js | 2 +- .../js/Mailer/MessageEditorController.js | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/UI/WebServerResources/js/Mailer/Message.service.js b/UI/WebServerResources/js/Mailer/Message.service.js index fc3dc1c24..c51a30858 100644 --- a/UI/WebServerResources/js/Mailer/Message.service.js +++ b/UI/WebServerResources/js/Mailer/Message.service.js @@ -592,7 +592,7 @@ Message.prototype.$deleteAttachment = function(filename) { var data = { 'filename': filename }; var _this = this; - Message.$$resource.fetch(this.$absolutePath({asDraft: true}), 'deleteAttachment', data).then(function(data) { + return Message.$$resource.fetch(this.$absolutePath({asDraft: true}), 'deleteAttachment', data).then(function() { Message.$timeout(function() { _this.editable.attachmentAttrs = _.filter(_this.editable.attachmentAttrs, function(attachment) { return attachment.filename != filename; diff --git a/UI/WebServerResources/js/Mailer/MessageEditorController.js b/UI/WebServerResources/js/Mailer/MessageEditorController.js index cb6d780ce..b48370e76 100644 --- a/UI/WebServerResources/js/Mailer/MessageEditorController.js +++ b/UI/WebServerResources/js/Mailer/MessageEditorController.js @@ -30,7 +30,6 @@ $mdConstant.KEY_CODE.COMMA, $mdConstant.KEY_CODE.SEMICOLON ]; - this.removeAttachment = removeAttachment; this.sendState = false; this.toggleFullscreen = toggleFullscreen; this.firstFocus = true; @@ -183,11 +182,14 @@ } } - function removeAttachment(item, id) { + this.removeAttachment = function (item, id) { + var _this = this; if (item.isUploading) vm.uploader.cancelItem(item); else { - vm.message.$deleteAttachment(item.file.name); + vm.message.$deleteAttachment(item.file.name).then(function() { + _this.save({toast: false}); + }); item.remove(); } // Hack to allow adding the same file again @@ -195,7 +197,7 @@ var element = $window.document.getElementById(id); if (element) angular.element(element).prop('value', null); - } + }; function cancel() { if (vm.autosave) @@ -204,12 +206,12 @@ if (vm.message.isNew && vm.message.attachmentAttrs) vm.message.$mailbox.$deleteMessages([vm.message]); - $mdDialog.cancel(); + $mdDialog.hide(); } - this.save = function () { + this.save = function (options) { var ctrls = $parentControllers(); - this.message.$save().then(function(data) { + this.message.$save().then(function() { vm.message.$rawSource = null; if (ctrls.draftMailboxCtrl) { // We're saving a draft from a popup window. @@ -221,11 +223,13 @@ } }); } - $mdToast.show( - $mdToast.simple() - .textContent(l('Your email has been saved')) - .position('top right') - .hideDelay(3000)); + if (!options || options.toast) { + $mdToast.show( + $mdToast.simple() + .textContent(l('Your email has been saved')) + .position('top right') + .hideDelay(3000)); + } }); };