diff --git a/ghost/admin/app/controllers/settings/members-payments.js b/ghost/admin/app/controllers/settings/members-payments.js index 45dd5a0561..f8fcad5fde 100644 --- a/ghost/admin/app/controllers/settings/members-payments.js +++ b/ghost/admin/app/controllers/settings/members-payments.js @@ -2,11 +2,14 @@ import Controller from '@ember/controller'; import {action} from '@ember/object'; import {inject as service} from '@ember/service'; -import {task} from 'ember-concurrency'; +import {task} from 'ember-concurrency-decorators'; +import {tracked} from '@glimmer/tracking'; export default class MembersPaymentsController extends Controller { @service settings; + @tracked showLeaveSettingsModal = false; + @action setDefaultContentVisibility(value) { this.settings.set('defaultContentVisibility', value); @@ -22,6 +25,27 @@ export default class MembersPaymentsController extends Controller { return yield this.settings.save(); } + leaveRoute(transition) { + if (this.settings.get('hasDirtyAttributes')) { + transition.abort(); + this.leaveSettingsTransition = transition; + this.showLeaveSettingsModal = true; + } + } + + @action + async confirmLeave() { + this.settings.rollbackAttributes(); + this.showLeaveSettingsModal = false; + this.leaveSettingsTransition.retry(); + } + + @action + cancelLeave() { + this.showLeaveSettingsModal = false; + this.leaveSettingsTransition = null; + } + reset() { // stripeConnectIntegrationToken is not a persisted value so we don't want // to keep it around across transitions diff --git a/ghost/admin/app/routes/settings/members-payments.js b/ghost/admin/app/routes/settings/members-payments.js index 777e471400..3f254e7a96 100644 --- a/ghost/admin/app/routes/settings/members-payments.js +++ b/ghost/admin/app/routes/settings/members-payments.js @@ -1,12 +1,13 @@ import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import {inject as service} from '@ember/service'; -export default AuthenticatedRoute.extend({ - session: service(), - settings: service(), +export default class MembersPaymentsRoute extends AuthenticatedRoute { + @service session; + @service settings; beforeModel() { - this._super(...arguments); + super.beforeModel(...arguments); + return this.session.get('user').then((user) => { if (!user.isOwner && user.isAdmin) { return this.transitionTo('settings'); @@ -14,21 +15,27 @@ export default AuthenticatedRoute.extend({ return this.transitionTo('home'); } }); - }, + } model() { return this.settings.reload(); - }, + } + + actions = { + willTransition(transition) { + return this.controller.leaveRoute(transition); + } + } resetController(controller, isExiting) { if (isExiting) { controller.reset(); } - }, + } buildRouteInfoMetadata() { return { titleToken: 'Settings - Members' }; } -}); +} diff --git a/ghost/admin/app/templates/settings/members-payments.hbs b/ghost/admin/app/templates/settings/members-payments.hbs index 632275bc45..caa55e76a0 100644 --- a/ghost/admin/app/templates/settings/members-payments.hbs +++ b/ghost/admin/app/templates/settings/members-payments.hbs @@ -24,4 +24,13 @@ /> + + {{#if this.showLeaveSettingsModal}} + + {{/if}} \ No newline at end of file