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
import DS from 'ember-data;' | |
export default DS.Model.extend({ | |
name: DS.attr('string'), | |
score: DS.attr('number'), | |
team: DS.belongsTo('team', { async: true }), | |
players: DS.hasMany('player', { async: true }) | |
}); |
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
actions: { | |
successAction() { | |
Ember.get(this, 'flashes').success('Success!', 2000); | |
}, | |
warningAction() { | |
Ember.get(this, 'flashes').warning('This is a warning message'); // timeout is optional | |
}, | |
infoAction() { |
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
queue : Ember.A([]), | |
isEmpty : computed.equal('queue.length', 0), | |
defaultTimeout : 2000, |
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
success(message, timeout=get(this, 'defaultTimeout')) { | |
this._addToQueue(message, 'success', timeout); | |
}, | |
info(message, timeout=get(this, 'defaultTimeout')) { | |
this._addToQueue(message, 'info', timeout); | |
}, | |
warning(message, timeout=get(this, 'defaultTimeout')) { | |
this._addToQueue(message, 'warning', timeout); |
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
addMessage(message, type='info', timeout=get(this, 'defaultTimeout')) { | |
this._addToQueue(message, type, timeout); | |
}, | |
clearMessages() { | |
let flashes = get(this, 'queue'); | |
flashes.clear(); | |
}, |
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
_newFlashMessage(service, message, type='info', timeout=get(this, 'defaultTimeout')) { | |
Ember.assert('Must pass a valid flash service', service); | |
Ember.assert('Must pass a valid flash message', message); | |
return FlashMessage.create({ | |
type : type, | |
message : message, | |
timeout : timeout, | |
flashService : service | |
}); |
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
_addToQueue(message, type, timeout) { | |
let flashes = get(this, 'queue'); | |
let flash = this._newFlashMessage(this, message, type, timeout); | |
flashes.pushObject(flash); | |
}, |
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
isSuccess : computed.equal('type', 'success'), | |
isInfo : computed.equal('type', 'info'), | |
isWarning : computed.equal('type', 'warning'), | |
isDanger : computed.equal('type', 'danger'), | |
defaultTimeout : computed.alias('flashService.defaultTimeout'), | |
queue : computed.alias('flashService.queue'), |
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
destroyLater: function() { | |
let defaultTimeout = get(this, 'defaultTimeout'); | |
let timeout = getWithDefault(this, 'timeout', defaultTimeout); | |
run.later(this, '_destroyMessage', timeout); | |
}.on('init'), |
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
destroyMessage() { | |
this._destroyMessage(); | |
}, | |
// private | |
_destroyMessage() { | |
set(this, 'isDestroyed', true); | |
get(this, 'queue').removeObject(this); | |
} |