2015-05-13 00:27:59 -05:00
|
|
|
import Ember from 'ember';
|
2015-11-04 15:20:11 +00:00
|
|
|
import AuthConfiguration from 'ember-simple-auth/configuration';
|
2015-10-18 13:17:02 -05:00
|
|
|
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
|
2014-06-19 13:44:44 -06:00
|
|
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
2014-11-25 23:34:55 +01:00
|
|
|
import ctrlOrCmd from 'ghost/utils/ctrl-or-cmd';
|
2015-11-04 15:20:11 +00:00
|
|
|
import windowProxy from 'ghost/utils/window-proxy';
|
2014-06-19 13:44:44 -06:00
|
|
|
|
2016-01-19 07:03:27 -06:00
|
|
|
const {
|
|
|
|
Route,
|
2016-01-12 19:23:01 +00:00
|
|
|
inject: {service},
|
|
|
|
run
|
2016-01-19 07:03:27 -06:00
|
|
|
} = Ember;
|
2015-10-28 11:36:45 +00:00
|
|
|
|
|
|
|
function K() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
let shortcuts = {};
|
2014-11-25 23:34:55 +01:00
|
|
|
|
2015-05-27 16:39:56 +02:00
|
|
|
shortcuts.esc = {action: 'closeMenus', scope: 'all'};
|
2015-10-28 11:36:45 +00:00
|
|
|
shortcuts[`${ctrlOrCmd}+s`] = {action: 'save', scope: 'all'};
|
2014-11-25 23:34:55 +01:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
export default Route.extend(ApplicationRouteMixin, ShortcutsRoute, {
|
|
|
|
shortcuts,
|
2014-06-30 14:58:10 +02:00
|
|
|
|
2016-01-19 07:03:27 -06:00
|
|
|
config: service(),
|
|
|
|
dropdown: service(),
|
|
|
|
notifications: service(),
|
2015-05-25 21:10:50 -05:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
afterModel(model, transition) {
|
2015-10-18 13:17:02 -05:00
|
|
|
if (this.get('session.isAuthenticated')) {
|
2014-08-06 05:01:00 +00:00
|
|
|
transition.send('loadServerNotifications');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
title(tokens) {
|
|
|
|
return `${tokens.join(' - ')} - ${this.get('config.blogTitle')}`;
|
2014-11-25 12:56:08 -08:00
|
|
|
},
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
sessionAuthenticated() {
|
2015-11-18 10:50:48 +00:00
|
|
|
if (this.get('session.skipAuthSuccessHandler')) {
|
2015-10-18 13:17:02 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._super(...arguments);
|
2015-10-28 11:36:45 +00:00
|
|
|
this.get('session.user').then((user) => {
|
|
|
|
this.send('signedIn', user);
|
2015-10-18 13:17:02 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
sessionInvalidated() {
|
2016-01-12 19:23:01 +00:00
|
|
|
run.scheduleOnce('routerTransitions', this, function () {
|
|
|
|
this.send('authorizationFailed');
|
|
|
|
});
|
2015-11-04 15:20:11 +00:00
|
|
|
},
|
|
|
|
|
2014-03-31 00:07:05 -04:00
|
|
|
actions: {
|
2015-10-28 11:36:45 +00:00
|
|
|
openMobileMenu() {
|
2015-05-27 16:39:56 +02:00
|
|
|
this.controller.set('showMobileMenu', true);
|
2014-09-01 17:45:06 +01:00
|
|
|
},
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
openSettingsMenu() {
|
2015-05-27 16:39:56 +02:00
|
|
|
this.controller.set('showSettingsMenu', true);
|
2014-09-14 18:40:24 -06:00
|
|
|
},
|
2014-07-31 21:15:55 +02:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
closeMenus() {
|
2014-09-28 16:39:25 +01:00
|
|
|
this.get('dropdown').closeDropdowns();
|
2015-05-27 16:39:56 +02:00
|
|
|
this.controller.setProperties({
|
|
|
|
showSettingsMenu: false,
|
|
|
|
showMobileMenu: false
|
|
|
|
});
|
2014-06-19 13:44:44 -06:00
|
|
|
},
|
2014-06-23 21:52:38 -05:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
didTransition() {
|
2015-08-20 15:44:52 +01:00
|
|
|
this.send('closeMenus');
|
|
|
|
},
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
signedIn() {
|
2015-10-07 15:44:23 +01:00
|
|
|
this.get('notifications').clearAll();
|
2014-06-29 23:45:03 +02:00
|
|
|
this.send('loadServerNotifications', true);
|
2014-05-14 18:36:13 -05:00
|
|
|
},
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
invalidateSession() {
|
|
|
|
this.get('session').invalidate().catch((error) => {
|
2015-10-18 13:17:02 -05:00
|
|
|
this.get('notifications').showAlert(error.message, {type: 'error', key: 'session.invalidate.failed'});
|
2014-07-29 20:49:26 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
authorizationFailed() {
|
2015-11-04 15:20:11 +00:00
|
|
|
windowProxy.replaceLocation(AuthConfiguration.baseURL);
|
|
|
|
},
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
loadServerNotifications(isDelayed) {
|
2015-10-18 13:17:02 -05:00
|
|
|
if (this.get('session.isAuthenticated')) {
|
2015-10-28 11:36:45 +00:00
|
|
|
this.get('session.user').then((user) => {
|
2015-04-14 16:04:16 +01:00
|
|
|
if (!user.get('isAuthor') && !user.get('isEditor')) {
|
2015-10-28 11:36:45 +00:00
|
|
|
this.store.findAll('notification', {reload: true}).then((serverNotifications) => {
|
|
|
|
serverNotifications.forEach((notification) => {
|
|
|
|
this.get('notifications').handleNotification(notification, isDelayed);
|
2015-04-14 16:04:16 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2014-06-29 23:45:03 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-18 10:50:48 +00:00
|
|
|
toggleMarkdownHelpModal() {
|
|
|
|
this.get('controller').toggleProperty('showMarkdownHelpModal');
|
|
|
|
},
|
|
|
|
|
2014-11-25 23:34:55 +01:00
|
|
|
// noop default for unhandled save (used from shortcuts)
|
2015-10-28 11:36:45 +00:00
|
|
|
save: K
|
2014-03-31 00:07:05 -04:00
|
|
|
}
|
|
|
|
});
|