framework/ember/app/components/alert-message.js

45 lines
1009 B
JavaScript
Raw Normal View History

2014-12-20 14:26:46 +08:00
import Ember from 'ember';
2015-02-03 14:32:46 +08:00
import TaggedArray from '../utils/tagged-array';
import ActionButton from 'flarum/components/ui/controls/action-button';
export default Ember.Component.extend(Ember.Evented, {
message: '',
type: '',
dismissable: true,
layoutName: 'components/alert-message',
classNames: ['alert'],
classNameBindings: ['classForType'],
classForType: function() {
return 'alert-'+this.get('type');
}.property('type'),
didInsertElement: function() {
var controls = TaggedArray.create();
this.trigger('populateControls', controls);
this.set('controls', controls);
},
populateControls: function(controls) {
if (this.get('dismissable')) {
var component = this;
var dismiss = ActionButton.create({
icon: 'times',
className: 'btn btn-icon btn-link',
action: function() {
component.send('dismiss');
}
});
controls.pushObjectWithTag(dismiss, 'dismiss');
}
},
2014-12-20 14:26:46 +08:00
2015-02-03 14:32:46 +08:00
actions: {
dismiss: function() {
this.sendAction('dismiss', this);
}
2014-12-20 14:26:46 +08:00
}
});