2014-03-31 08:07:05 +04:00
|
|
|
var ApplicationRoute = Ember.Route.extend({
|
|
|
|
actions: {
|
2014-05-15 03:36:13 +04:00
|
|
|
signedIn: function (user) {
|
2014-05-09 09:00:10 +04: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-15 03:36:13 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
signedOut: function () {
|
2014-05-09 09:00:10 +04: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-15 03:36:13 +04:00
|
|
|
},
|
|
|
|
|
2014-06-06 18:44:09 +04:00
|
|
|
openModal: function (modalName, model, type) {
|
2014-03-31 08:07:05 +04: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-06 18:44:09 +04:00
|
|
|
this.controllerFor(modalName).set('imageType', type);
|
|
|
|
this.controllerFor(modalName).set('src', model.get(type));
|
2014-03-31 08:07:05 +04:00
|
|
|
}
|
|
|
|
return this.render(modalName, {
|
|
|
|
into: 'application',
|
|
|
|
outlet: 'modal'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
closeModal: function () {
|
|
|
|
return this.disconnectOutlet({
|
|
|
|
outlet: 'modal',
|
|
|
|
parentView: 'application'
|
|
|
|
});
|
2014-03-22 16:08:15 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
handleErrors: function (errors) {
|
2014-05-31 22:32:22 +04:00
|
|
|
var self = this;
|
2014-03-22 16:08:15 +04:00
|
|
|
this.notifications.clear();
|
|
|
|
errors.forEach(function (errorObj) {
|
2014-05-31 22:32:22 +04:00
|
|
|
self.notifications.showError(errorObj.message || errorObj);
|
2014-03-22 16:08:15 +04:00
|
|
|
|
|
|
|
if (errorObj.hasOwnProperty('el')) {
|
|
|
|
errorObj.el.addClass('input-error');
|
|
|
|
}
|
|
|
|
});
|
2014-03-31 08:07:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-06 18:44:09 +04:00
|
|
|
export default ApplicationRoute;
|