2016-11-14 14:16:51 +01:00
|
|
|
/* eslint-disable camelcase */
|
2016-05-24 14:06:59 +02:00
|
|
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
2019-08-27 15:51:31 +02:00
|
|
|
import CurrentUserSettings from 'ghost-admin/mixins/current-user-settings';
|
|
|
|
import {inject as service} from '@ember/service';
|
2015-10-15 14:03:26 +02:00
|
|
|
|
2019-08-27 15:51:31 +02:00
|
|
|
export default AuthenticatedRoute.extend(CurrentUserSettings, {
|
|
|
|
router: service(),
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.router.on('routeWillChange', (transition) => {
|
|
|
|
this.showUnsavedChangesModal(transition);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeModel() {
|
|
|
|
this._super(...arguments);
|
|
|
|
return this.get('session.user')
|
|
|
|
.then(this.transitionAuthor());
|
|
|
|
},
|
2015-10-15 14:03:26 +02:00
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
model(params) {
|
2015-10-23 19:18:39 +02:00
|
|
|
return this.store.queryRecord('tag', {slug: params.tag_slug});
|
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
serialize(model) {
|
2015-10-23 19:18:39 +02:00
|
|
|
return {tag_slug: model.get('slug')};
|
2015-10-23 19:18:39 +02:00
|
|
|
},
|
|
|
|
|
2019-08-27 15:51:31 +02:00
|
|
|
setupController() {
|
2017-07-06 12:04:28 +02:00
|
|
|
this._super(...arguments);
|
|
|
|
},
|
|
|
|
|
2015-10-23 19:18:39 +02:00
|
|
|
// reset the model so that mobile screens react to an empty selectedTag
|
2015-10-28 12:36:45 +01:00
|
|
|
deactivate() {
|
2015-11-15 12:06:49 +01:00
|
|
|
this._super(...arguments);
|
2019-08-27 15:51:31 +02:00
|
|
|
let {controller} = this;
|
|
|
|
controller.model.rollbackAttributes();
|
2015-10-23 19:18:39 +02:00
|
|
|
this.set('controller.model', null);
|
2019-08-27 15:51:31 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
save() {
|
|
|
|
this.controller.send('save');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
showUnsavedChangesModal(transition) {
|
|
|
|
if (transition.from && transition.from.name.match(/^tags\.tag/) && transition.targetName) {
|
|
|
|
let {controller} = this;
|
|
|
|
|
|
|
|
if (!controller.tag.isDeleted && controller.tag.hasDirtyAttributes) {
|
|
|
|
transition.abort();
|
|
|
|
controller.send('toggleUnsavedChangesModal', transition);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-10-15 14:03:26 +02:00
|
|
|
}
|
2019-08-27 15:51:31 +02:00
|
|
|
|
2015-10-15 14:03:26 +02:00
|
|
|
});
|