Skip to content

Instantly share code, notes, and snippets.

@alonextou
Created August 30, 2013 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alonextou/6387533 to your computer and use it in GitHub Desktop.
Save alonextou/6387533 to your computer and use it in GitHub Desktop.
Ember.js Bootstrap 3 Alerts
App.AlertController = Ember.Controller.extend({
alert: false,
observeAlert: function() {
if(this.alert != false){
$('#flash').addClass('alert alert-' + this.alert[0] + ' alert-dismissable');
$('#flash span').text(this.alert[1]);
$('#flash').fadeIn();
} else {
$('#flash').hide();
}
}.observes('alert')
});
<div id="flash">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Warning!</strong>
<span></span>
</div>
App.ApplicationRoute = Ember.Route.extend({
beforeModel: function() {
return this.checkLogin = this.checkLogin || this.controllerFor('auth').checkLogin();
},
events: {
willTransition: function() {
var alertController = this.controllerFor('alert');
alertController.set('alert', false);
}
}
});
App.AuthFilter = Ember.Route.extend({
beforeModel: function(transition) {
if(this.controllerFor('auth').get('isGuest')){
var alertController = this.controllerFor('alert');
alertController.set('alert', ['warning', 'You must be logged to view this page.']);
this.transitionTo('login');
}
}
});
App.ArticlesIndexRoute = App.AuthFilter.extend({
// ...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment