Reputation: 253
I have the following use case. On server side error I would like to show to the user something went wrong (possibly allowing them to retry). I could either use a popup or status bar. At the same time I want to keep the current view open i.e. the user should remain where the error happened.
I guess (please correct me if I am wrong) I should not use transitionTo(...) since this will replace my current view. My intention is rather to have a generic functionality in the application view (outer most template/view) which dynamically adds/removes the notification.
Design ideas how to construct and modify UI are very welcome.
Thanks!
Upvotes: 0
Views: 83
Reputation: 1158
My solution to this exact use case is simple. I have defined an event handler in my ApplicationRoute
that gathers these exceptions and injects them into my custom ExceptionsController
and exceptions
is rendered somewhere into main application template.
App.ApplicationRoute = Ember.Route.extend({
events: {
exceptionHandler: function (exception) {
this.controllerFor('exceptions').addObject(exception);
}
}
});
ExceptionsController
is just extension of ArrayController
.
App.ExceptionsController = Ember.ArrayController.extend();
Finally somewhere in my main application template I just use:
{{render 'exceptions'}}
I will leave the template to your imagination.
EDIT
Then if you want to raise an exception just use send
to fire an action anywhere in your controller or route.
this.send('exceptionHandler', exception);
Where exception is your custom model.
Advantage of this solution is that you can override the handler in any other route below the application route or in any controller.
Upvotes: 1