Last active
August 29, 2015 14:22
-
-
Save selvagsz/e5d9f15675e8cca188ca to your computer and use it in GitHub Desktop.
ember-notification (toastr style)
This file contains hidden or 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
.status-notification { | |
position: fixed; | |
top: 0; | |
right: 0; | |
width: 350px; | |
} | |
.notification-item { | |
padding: 10px; | |
margin: 7px 10px 0 0; | |
color: #fff; | |
&.error { | |
background-color: #F46558; | |
} | |
&.success { | |
background-color: #53B05A; | |
} | |
&:hover { | |
.box-shadow(0 0 12px #000); | |
} | |
} |
This file contains hidden or 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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
classNames: ['status-notification'], | |
notificationService: Ember.inject.service('notification'), | |
notifications: Ember.computed.alias('notificationService.notificationQueue'), | |
actions: { | |
removeNotification(notificationItem) { | |
var self = this; | |
notificationItem.$().fadeOut('slow', function() { | |
self.get('notifications').removeObject(notificationItem.get('notification')); | |
}); | |
} | |
} | |
}); |
This file contains hidden or 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
import Ember from 'ember'; | |
const MESSAGEICONS = { | |
success: 'icon-ok', | |
error: 'icon-attention', | |
warning: 'icon-attention' | |
}; | |
let messageIconLookup = function(depKey) { | |
return Ember.computed(depKey, function() { | |
return MESSAGEICONS[this.get(depKey)]; | |
}); | |
}; | |
export default Ember.Component.extend({ | |
classNameBindings: [':notification-item', 'notification.type'], | |
attributeBindings: ['style'], | |
style: 'display:none;', | |
notification: null, | |
'on-close': null, | |
showClose: true, | |
closeTimeOut: 4000, | |
_counter: 0, | |
_countDownInProgress: true, | |
messageIcon: messageIconLookup('notification.type'), | |
fadeIn: function() { | |
Ember.run.scheduleOnce('afterRender', this, function() { | |
this.$().fadeIn('slow'); | |
}); | |
}.on('didInsertElement'), | |
startCounter: function() { | |
if(this.get('_countDownInProgress')) { | |
if(this.get('_counter') <= this.get('closeTimeOut')) { | |
Ember.run.later(this, function() { | |
if(!this.get('isDestroyed')) { | |
this.incrementProperty('_counter', 1000); | |
this.startCounter(); | |
} | |
}, 1000); | |
} else { | |
this.sendAction('on-close', this); | |
} | |
} | |
}.on('didInsertElement'), | |
pauseCounter: function() { | |
this.set('_countDownInProgress', false); | |
}.on('mouseEnter'), | |
resumeCounter: function() { | |
this.set('_countDownInProgress', true); | |
this.startCounter(); | |
}.on('mouseLeave'), | |
actions: { | |
close() { | |
this.sendAction('on-close', this); | |
} | |
} | |
}); |
This file contains hidden or 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
//Currently uses bootstrap for css | |
//TODO: | |
// 1. Remove bootstrap dependency | |
// 2. Convert it into an ember addon | |
import Ember from 'ember'; | |
export default Ember.Service.extend({ | |
notificationQueue: [], | |
success(message) { | |
this.get('notificationQueue').pushObject({ | |
message: message, | |
type: 'success' | |
}); | |
}, | |
error(message) { | |
this.get('notificationQueue').pushObject({ | |
message: message, | |
type: 'error' | |
}); | |
}, | |
info(message) { | |
this.get('notificationQueue').pushObject({ | |
message: message, | |
type: 'info' | |
}); | |
}, | |
warning(message) { | |
this.get('notificationQueue').pushObject({ | |
message: message, | |
type: 'warning' | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment