mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
7c4381c812
- Every route can set a title token that is combined with the blog’s title, resulting in titles like ‘Content - Test Blog’. - Subroutes are supported (‘Settings - General - Test Blog’) - The blog’s name is applied to and taken from the `config` object to spare Ember a REST call via `store.find(‘settings’)`. - Tests have been changed to test for the new titles. - The initially proposed solution (https://github.com/paddle8/ember-document-title) doesn’t play nice with EAK, which is why I went with this solution (https://gist.github.com/machty/8413411) by Ember.JS core dev @Machty.
67 lines
2 KiB
JavaScript
67 lines
2 KiB
JavaScript
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
|
import styleBody from 'ghost/mixins/style-body';
|
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
|
import ctrlOrCmd from 'ghost/utils/ctrl-or-cmd';
|
|
|
|
var shortcuts = {},
|
|
SettingsUserRoute;
|
|
|
|
shortcuts[ctrlOrCmd + '+s'] = {action: 'save'};
|
|
|
|
SettingsUserRoute = AuthenticatedRoute.extend(styleBody, ShortcutsRoute, {
|
|
titleToken: 'User',
|
|
|
|
classNames: ['settings-view-user'],
|
|
|
|
model: function (params) {
|
|
var self = this;
|
|
// TODO: Make custom user adapter that uses /api/users/:slug endpoint
|
|
// return this.store.find('user', { slug: params.slug });
|
|
|
|
// Instead, get all the users and then find by slug
|
|
return this.store.find('user').then(function (result) {
|
|
var user = result.findBy('slug', params.slug);
|
|
|
|
if (!user) {
|
|
return self.transitionTo('error404', 'settings/users/' + params.slug);
|
|
}
|
|
|
|
return user;
|
|
});
|
|
},
|
|
|
|
afterModel: function (user) {
|
|
var self = this;
|
|
this.store.find('user', 'me').then(function (currentUser) {
|
|
var isOwnProfile = user.get('id') === currentUser.get('id'),
|
|
isAuthor = currentUser.get('isAuthor'),
|
|
isEditor = currentUser.get('isEditor');
|
|
if (isAuthor && !isOwnProfile) {
|
|
self.transitionTo('settings.users.user', currentUser);
|
|
} else if (isEditor && !isOwnProfile && !user.get('isAuthor')) {
|
|
self.transitionTo('settings.users');
|
|
}
|
|
});
|
|
},
|
|
|
|
deactivate: function () {
|
|
var model = this.modelFor('settings.users.user');
|
|
|
|
// we want to revert any unsaved changes on exit
|
|
if (model && model.get('isDirty')) {
|
|
model.rollback();
|
|
}
|
|
|
|
this._super();
|
|
},
|
|
|
|
shortcuts: shortcuts,
|
|
|
|
actions: {
|
|
save: function () {
|
|
this.get('controller').send('save');
|
|
}
|
|
}
|
|
});
|
|
|
|
export default SettingsUserRoute;
|