2015-04-25 20:58:39 +08:00
|
|
|
import Component from 'flarum/component';
|
|
|
|
|
|
|
|
export default class Alerts extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.components = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
view() {
|
|
|
|
return m('div.alerts', this.components.map((component) => {
|
|
|
|
component.props.ondismiss = this.dismiss.bind(this, component);
|
|
|
|
return m('div.alert-wrapper', component);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
show(component) {
|
|
|
|
this.components.push(component);
|
|
|
|
m.redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
dismiss(component) {
|
|
|
|
var index = this.components.indexOf(component);
|
|
|
|
if (index !== -1) {
|
|
|
|
this.components.splice(index, 1);
|
2015-05-18 16:43:16 +08:00
|
|
|
m.redraw();
|
2015-04-25 20:58:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
this.components = [];
|
|
|
|
m.redraw();
|
|
|
|
}
|
|
|
|
}
|