diff --git a/ghost/admin/app/routes/settings/design.js b/ghost/admin/app/routes/settings/design.js index ba364a4b91..b921f87965 100644 --- a/ghost/admin/app/routes/settings/design.js +++ b/ghost/admin/app/routes/settings/design.js @@ -1,17 +1,12 @@ import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; -import {action} from '@ember/object'; import {inject as service} from '@ember/service'; export default class SettingsDesignRoute extends AuthenticatedRoute { - @service customThemeSettings; @service feature; @service modals; @service settings; @service ui; - confirmModal = null; - hasConfirmed = false; - beforeModel() { super.beforeModel(...arguments); @@ -32,27 +27,8 @@ export default class SettingsDesignRoute extends AuthenticatedRoute { this.ui.contextualNavMenu = 'design'; } - @action - willTransition(transition) { - if (this.hasConfirmed) { - return true; - } - - // always abort when not confirmed because Ember's router doesn't automatically wait on promises - transition.abort(); - - this.confirmUnsavedChanges().then((shouldLeave) => { - if (shouldLeave) { - this.hasConfirmed = true; - return transition.retry(); - } - }); - } - deactivate() { this.ui.contextualNavMenu = null; - this.confirmModal = null; - this.hasConfirmed = false; } buildRouteInfoMetadata() { @@ -60,25 +36,3 @@ export default class SettingsDesignRoute extends AuthenticatedRoute { mainClasses: ['gh-main-fullwidth'] }; } - - confirmUnsavedChanges() { - if (!this.settings.get('hasDirtyAttributes') && !this.customThemeSettings.isDirty) { - return Promise.resolve(true); - } - - if (!this.confirmModal) { - this.confirmModal = this.modals.open('modals/confirm-unsaved-changes') - .then((discardChanges) => { - if (discardChanges === true) { - this.settings.rollbackAttributes(); - this.customThemeSettings.rollback(); - } - return discardChanges; - }).finally(() => { - this.confirmModal = null; - }); - } - - return this.confirmModal; - } -} diff --git a/ghost/admin/app/routes/settings/design/index.js b/ghost/admin/app/routes/settings/design/index.js new file mode 100644 index 0000000000..8fc507e5b8 --- /dev/null +++ b/ghost/admin/app/routes/settings/design/index.js @@ -0,0 +1,55 @@ +import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; +import {action} from '@ember/object'; +import {inject as service} from '@ember/service'; + +export default class SettingsDesignRoute extends AuthenticatedRoute { + @service customThemeSettings; + @service modals; + @service settings; + + confirmModal = null; + hasConfirmed = false; + + @action + willTransition(transition) { + if (this.hasConfirmed) { + return true; + } + + // always abort when not confirmed because Ember's router doesn't automatically wait on promises + transition.abort(); + + this.confirmUnsavedChanges().then((shouldLeave) => { + if (shouldLeave) { + this.hasConfirmed = true; + return transition.retry(); + } + }); + } + + deactivate() { + this.confirmModal = null; + this.hasConfirmed = false; + } + + confirmUnsavedChanges() { + if (!this.settings.get('hasDirtyAttributes') && !this.customThemeSettings.isDirty) { + return Promise.resolve(true); + } + + if (!this.confirmModal) { + this.confirmModal = this.modals.open('modals/confirm-unsaved-changes') + .then((discardChanges) => { + if (discardChanges === true) { + this.settings.rollbackAttributes(); + this.customThemeSettings.rollback(); + } + return discardChanges; + }).finally(() => { + this.confirmModal = null; + }); + } + + return this.confirmModal; + } +} diff --git a/ghost/admin/app/services/custom-theme-settings.js b/ghost/admin/app/services/custom-theme-settings.js index 7f22488858..d7f3b04acc 100644 --- a/ghost/admin/app/services/custom-theme-settings.js +++ b/ghost/admin/app/services/custom-theme-settings.js @@ -79,10 +79,7 @@ export default class CustomThemeSettingsServices extends Service { } rollback() { - run(() => this.store.unloadAll('custom-theme-setting')); - - this.settings = []; - this.settingGroups = []; + this.settings.forEach(setting => setting.rollbackAttributes()); } _buildSettingGroups(settings) {