2015-06-08 18:14:25 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import GlobalNotificationStore from '../stores/global_notification_store';
|
|
|
|
import GlobalNotificationActions from '../actions/global_notification_actions';
|
|
|
|
|
|
|
|
import Row from 'react-bootstrap/lib/Row';
|
|
|
|
import Col from 'react-bootstrap/lib/Col';
|
|
|
|
|
|
|
|
let GlobalNotification = React.createClass({
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
GlobalNotificationStore.listen(this.onChange);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2015-06-09 12:08:14 +02:00
|
|
|
GlobalNotificationStore.unlisten(this.onChange);
|
2015-06-08 18:14:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getInititalState() {
|
2015-06-09 12:08:14 +02:00
|
|
|
return this.extractFirstElem(GlobalNotificationStore.getState().notificationQue);
|
2015-06-08 18:14:25 +02:00
|
|
|
},
|
|
|
|
|
2015-06-09 12:08:14 +02:00
|
|
|
extractFirstElem(l) {
|
|
|
|
return l.length > 0 ? l[0] : null;
|
2015-06-08 18:14:25 +02:00
|
|
|
},
|
|
|
|
|
2015-06-09 12:08:14 +02:00
|
|
|
onChange(state) {
|
|
|
|
let notification = this.extractFirstElem(state.notificationQue);
|
|
|
|
|
|
|
|
if(notification) {
|
|
|
|
this.setState(notification);
|
|
|
|
} else {
|
|
|
|
this.replaceState(null);
|
2015-06-08 18:14:25 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let className = 'ascribe-global-notification ';
|
2015-06-09 12:08:14 +02:00
|
|
|
let message = this.state && this.state.message ? this.state.message : null;
|
|
|
|
|
|
|
|
className += message ? 'ascribe-global-notification-on' : 'ascribe-global-notification-off';
|
2015-06-08 18:14:25 +02:00
|
|
|
|
2015-06-09 12:08:14 +02:00
|
|
|
return (
|
|
|
|
<Row>
|
2015-06-08 18:14:25 +02:00
|
|
|
<Col>
|
|
|
|
<div className={className}>
|
2015-06-09 12:08:14 +02:00
|
|
|
<div>{message ? message : null}</div>
|
2015-06-08 18:14:25 +02:00
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default GlobalNotification;
|