2022-04-04 21:26:49 +03:00
|
|
|
import AdminRoute from 'ghost-admin/routes/admin';
|
2022-04-27 12:36:43 +03:00
|
|
|
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;
|
2022-04-12 16:01:27 +03:00
|
|
|
@service settings;
|
2022-04-04 21:26:49 +03:00
|
|
|
@service store;
|
2022-05-11 13:07:13 +03:00
|
|
|
@service limit;
|
2022-04-04 21:26:49 +03:00
|
|
|
|
|
|
|
newsletterModal = null;
|
|
|
|
|
2022-05-11 13:07:13 +03:00
|
|
|
/**
|
|
|
|
* 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() {
|
2022-04-15 11:43:10 +03:00
|
|
|
return this.store.createRecord('newsletter');
|
2022-04-04 21:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
setupController(controller, model) {
|
|
|
|
this.newsletterModal?.close();
|
|
|
|
|
2022-04-27 12:36:43 +03:00
|
|
|
this.newsletterModal = this.modals.open(NewNewsletterModal, {
|
2022-04-04 21:26:49 +03:00
|
|
|
newsletter: model,
|
|
|
|
afterSave: this.afterSave
|
|
|
|
}, {
|
|
|
|
beforeClose: this.beforeModalClose
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-12 23:32:11 +03:00
|
|
|
@action
|
|
|
|
afterSave() {
|
2022-05-05 14:36:16 +03:00
|
|
|
this.router.transitionTo('settings.newsletters');
|
2022-04-12 23:32:11 +03:00
|
|
|
}
|
|
|
|
|
2022-04-04 21:26:49 +03:00
|
|
|
deactivate() {
|
|
|
|
this.isLeaving = true;
|
|
|
|
this.newsletterModal?.close();
|
|
|
|
this.isLeaving = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2022-04-12 23:32:11 +03:00
|
|
|
async beforeModalClose() {
|
2022-04-27 12:36:43 +03:00
|
|
|
if (!this.isLeaving) {
|
2022-05-05 14:36:16 +03:00
|
|
|
this.router.transitionTo('settings.newsletters');
|
2022-04-04 21:26:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|