Skip to content

Instantly share code, notes, and snippets.

@alonextou
Created September 4, 2013 16:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alonextou/6439291 to your computer and use it in GitHub Desktop.
Save alonextou/6439291 to your computer and use it in GitHub Desktop.
<div id="alert">
<div id="flash">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Warning!</strong>
<span></span>
</div>
</div>
App.AlertController = Ember.Controller.extend({
alert: false,
observeAlert: function() {
if(this.alert != false){
App.AlertCollectionView.content.pushObject();
$('#flash').addClass('alert alert-' + this.alert[0] + ' alert-dismissable');
$('#flash span').text(this.alert[1]);
$('#flash').fadeIn();
} else {
$('#flash').remove();
}
}.observes('alert')
});
App.AlertCollectionView = Ember.CollectionView.create({
content: [],
itemViewClass: Ember.View.extend({
templateName: 'alert'
})
});
{{view App.AlertCollectionView}}
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');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment