2014-06-19 14:44:44 -05:00
|
|
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
2014-06-24 01:19:20 -05:00
|
|
|
import mobileUtils from 'ghost/utils/mobile-utils';
|
2014-06-19 14:44:44 -05:00
|
|
|
|
2014-06-30 07:58:10 -05:00
|
|
|
var ApplicationRoute = Ember.Route.extend(Ember.SimpleAuth.ApplicationRouteMixin, ShortcutsRoute, {
|
|
|
|
|
2014-06-19 14:44:44 -05:00
|
|
|
shortcuts: {
|
|
|
|
'esc': 'closePopups'
|
|
|
|
},
|
2014-06-30 07:58:10 -05:00
|
|
|
beforeModel: function () {
|
|
|
|
var self = this;
|
|
|
|
if (this.get('session').isAuthenticated) {
|
|
|
|
this.store.find('user', 'me').then(function (user) {
|
|
|
|
// Update the user on all routes and controllers
|
|
|
|
self.container.unregister('user:current');
|
|
|
|
self.container.register('user:current', user, { instantiate: false });
|
|
|
|
|
|
|
|
self.container.injection('route', 'user', 'user:current');
|
|
|
|
self.container.injection('controller', 'user', 'user:current');
|
2014-06-24 01:19:20 -05:00
|
|
|
|
2014-06-30 07:58:10 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2014-06-24 01:19:20 -05:00
|
|
|
mobileInteractions: function () {
|
|
|
|
var responsiveAction = mobileUtils.responsiveAction;
|
|
|
|
|
|
|
|
Ember.run.scheduleOnce('afterRender', document, function () {
|
|
|
|
// ### Toggle the sidebar menu
|
|
|
|
$('[data-off-canvas]').on('click', function (event) {
|
|
|
|
responsiveAction(event, '(max-width: 650px)', function () {
|
|
|
|
$('body').toggleClass('off-canvas');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}.on('init'),
|
|
|
|
|
2014-03-30 23:07:05 -05:00
|
|
|
actions: {
|
2014-06-19 14:44:44 -05:00
|
|
|
closePopups: function () {
|
|
|
|
this.get('popover').closePopovers();
|
|
|
|
this.get('notifications').closeAll();
|
2014-06-23 21:52:38 -05:00
|
|
|
|
|
|
|
this.send('closeModal');
|
2014-06-19 14:44:44 -05:00
|
|
|
},
|
2014-06-23 21:52:38 -05:00
|
|
|
|
2014-05-14 18:36:13 -05:00
|
|
|
signedIn: function (user) {
|
2014-05-09 00:00:10 -05:00
|
|
|
// Update the user on all routes and controllers
|
|
|
|
this.container.unregister('user:current');
|
|
|
|
this.container.register('user:current', user, { instantiate: false });
|
|
|
|
|
|
|
|
this.container.injection('route', 'user', 'user:current');
|
|
|
|
this.container.injection('controller', 'user', 'user:current');
|
|
|
|
|
|
|
|
this.set('user', user);
|
|
|
|
this.set('controller.user', user);
|
2014-05-14 18:36:13 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
signedOut: function () {
|
2014-05-09 00:00:10 -05:00
|
|
|
// Nullify the user on all routes and controllers
|
|
|
|
this.container.unregister('user:current');
|
|
|
|
this.container.register('user:current', null, { instantiate: false });
|
|
|
|
|
|
|
|
this.container.injection('route', 'user', 'user:current');
|
|
|
|
this.container.injection('controller', 'user', 'user:current');
|
|
|
|
|
|
|
|
this.set('user', null);
|
|
|
|
this.set('controller.user', null);
|
2014-05-14 18:36:13 -05:00
|
|
|
},
|
|
|
|
|
2014-06-06 09:44:09 -05:00
|
|
|
openModal: function (modalName, model, type) {
|
2014-03-30 23:07:05 -05:00
|
|
|
modalName = 'modals/' + modalName;
|
|
|
|
// We don't always require a modal to have a controller
|
|
|
|
// so we're skipping asserting if one exists
|
|
|
|
if (this.controllerFor(modalName, true)) {
|
|
|
|
this.controllerFor(modalName).set('model', model);
|
2014-06-19 13:31:56 -05:00
|
|
|
|
|
|
|
if (type) {
|
|
|
|
this.controllerFor(modalName).set('imageType', type);
|
|
|
|
this.controllerFor(modalName).set('src', model.get(type));
|
|
|
|
}
|
2014-03-30 23:07:05 -05:00
|
|
|
}
|
|
|
|
return this.render(modalName, {
|
|
|
|
into: 'application',
|
|
|
|
outlet: 'modal'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
closeModal: function () {
|
|
|
|
return this.disconnectOutlet({
|
|
|
|
outlet: 'modal',
|
|
|
|
parentView: 'application'
|
|
|
|
});
|
2014-03-22 07:08:15 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
handleErrors: function (errors) {
|
2014-05-31 13:32:22 -05:00
|
|
|
var self = this;
|
2014-03-22 07:08:15 -05:00
|
|
|
this.notifications.clear();
|
|
|
|
errors.forEach(function (errorObj) {
|
2014-05-31 13:32:22 -05:00
|
|
|
self.notifications.showError(errorObj.message || errorObj);
|
2014-03-22 07:08:15 -05:00
|
|
|
|
|
|
|
if (errorObj.hasOwnProperty('el')) {
|
|
|
|
errorObj.el.addClass('input-error');
|
|
|
|
}
|
|
|
|
});
|
2014-03-30 23:07:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-06 09:44:09 -05:00
|
|
|
export default ApplicationRoute;
|