From 16324fd2a4bbedf8254b12c77c8eaf1d099c1ef2 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 17 Feb 2021 15:48:23 +0000 Subject: [PATCH] Fixed brand settings not resetting when cancelling no issue - trigger modal close once save task has finished - reset unsaved changes when closing the modal (eg, cancel button clicked) - removed unused code that had been copied over from an old controller --- ghost/admin/app/components/modal-branding.js | 47 +++----------------- 1 file changed, 5 insertions(+), 42 deletions(-) diff --git a/ghost/admin/app/components/modal-branding.js b/ghost/admin/app/components/modal-branding.js index f4feb53094..7722051199 100644 --- a/ghost/admin/app/components/modal-branding.js +++ b/ghost/admin/app/components/modal-branding.js @@ -76,6 +76,8 @@ export default ModalComponent.extend({ willDestroyElement() { window.removeEventListener('message', this._previewListener); + // reset any unsaved changes when closing + this.settings.rollbackAttributes(); }, actions: { @@ -83,47 +85,6 @@ export default ModalComponent.extend({ this.save.perform(); }, - toggleLeaveSettingsModal(transition) { - let leaveTransition = this.leaveSettingsTransition; - - if (!transition && this.showLeaveSettingsModal) { - this.set('leaveSettingsTransition', null); - this.set('showLeaveSettingsModal', false); - return; - } - - if (!leaveTransition || transition.targetName === leaveTransition.targetName) { - this.set('leaveSettingsTransition', transition); - - // if a save is running, wait for it to finish then transition - if (this.save.isRunning) { - return this.save.last.then(() => { - transition.retry(); - }); - } - - // we genuinely have unsaved data, show the modal - this.set('showLeaveSettingsModal', true); - } - }, - - leaveSettings() { - let transition = this.leaveSettingsTransition; - let settings = this.settings; - - if (!transition) { - this.notifications.showAlert('Sorry, there was an error in the application. Please let the Ghost team know what happened.', {type: 'error'}); - return; - } - - // roll back changes on settings props - settings.rollbackAttributes(); - - return transition.retry(); - }, - - reset() {}, - async removeImage(image) { // setting `null` here will error as the server treats it as "null" this.settings.set(image, ''); @@ -213,7 +174,9 @@ export default ModalComponent.extend({ try { yield RSVP.all(validationPromises); - return yield this.settings.save(); + yield this.settings.save(); + this.closeModal(); + return true; } catch (error) { if (error) { notifications.showAPIError(error);