Ghost/ghost/admin/app/routes/settings/newsletters/new-newsletter.js

67 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-04-04 21:26:49 +03:00
import AdminRoute from 'ghost-admin/routes/admin';
import NewNewsletterModal from '../../../components/modals/newsletters/new';
2022-04-04 21:26:49 +03:00
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
export default class NewNewsletterRoute extends AdminRoute {
@service modals;
@service router;
@service settings;
2022-04-04 21:26:49 +03:00
@service store;
@service limit;
2022-04-04 21:26:49 +03:00
newsletterModal = null;
/**
* Before we allow the creation of a new newsletter, we should check the limits and return to the newsletters page if required.
*/
async beforeModel() {
try {
await this.limit.limiter.errorIfWouldGoOverLimit('newsletters');
} catch (error) {
if (error.errorType === 'HostLimitError') {
// Not allowed: we reached the limit here
this.modals.open('modals/limits/multiple-newsletters', {
message: error.message
});
return this.replaceWith('settings.newsletters');
}
throw error;
}
}
2022-04-04 21:26:49 +03:00
model() {
return this.store.createRecord('newsletter');
2022-04-04 21:26:49 +03:00
}
setupController(controller, model) {
this.newsletterModal?.close();
this.newsletterModal = this.modals.open(NewNewsletterModal, {
2022-04-04 21:26:49 +03:00
newsletter: model,
afterSave: this.afterSave
}, {
beforeClose: this.beforeModalClose
});
}
@action
afterSave() {
this.router.transitionTo('settings.newsletters');
}
2022-04-04 21:26:49 +03:00
deactivate() {
this.isLeaving = true;
this.newsletterModal?.close();
this.isLeaving = false;
}
@action
async beforeModalClose() {
if (!this.isLeaving) {
this.router.transitionTo('settings.newsletters');
2022-04-04 21:26:49 +03:00
}
}
}