Created
August 30, 2013 08:21
-
-
Save alonextou/6387533 to your computer and use it in GitHub Desktop.
Ember.js Bootstrap 3 Alerts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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