var UIMailInput = React.createClass ({
getInitialState: function() {
return {
email: "",
validMail: undefined
}
},
handleChange: function(event) {
this.setState({email: event.target.value,
validMail: validateEmail(event.target.value) ? true : undefined});
},
handleSubmit: function() {
if(validateEmail(this.state.email) == false) {
this.setState({validMail: false});
return;
}
var message = {
application: this.props.application,
mail: this.state.email
};
if(this.props.instance != undefined) {
message.instance = this.props.instance;
}
if(this.props.component != undefined) {
message.component = this.props.component;
}
nutella.net.publish("monitoring/alert/add", message);
alertsModel.fetchData();
console.log(message);
},
render: function() {
var error = "has-success";
var btn = "btn-success";
if(this.state.validMail == false) {
error = "has-error";
btn = "btn-danger";
}
if(this.state.validMail == undefined) {
error = "has-warning";
btn = "btn-warning";
}
return(
@
Subscribe
)
}
});
var UIAlerts = React.createClass ({
getInitialState: function() {
return {
application: undefined,
instance: undefined,
component: undefined,
emails: []
}
},
componentDidMount: function() {
var self = this;
notificationCenter.subscribe(Notifications.alerts.ALERT_CHANGE, function() {
self.setState({
application: alertsModel.application,
instance: alertsModel.instance,
component: alertsModel.component
});
});
notificationCenter.subscribe(Notifications.alerts.EMAILS_CHANGE, function() {
self.setState({
emails: alertsModel.emails
});
});
},
handleDelete: function(mail) {
var message = {
application: this.state.application,
mail: mail
};
if(this.state.instance != undefined) {
message.instance = this.state.instance;
}
if(this.state.component != undefined) {
message.component = this.state.component;
}
nutella.net.publish("monitoring/alert/remove", message);
alertsModel.fetchData();
},
render: function() {
var self = this;
//
{email}
//
X
var emails = this.state.emails.map(function(email, index) {
return (
Administrator
{email}
×
)
});
subscription = [];
if(this.state.application != undefined) {
subscription.push(application: {this.state.application} );
}
if(this.state.instance != undefined) {
subscription.push( instance: {this.state.instance} );
}
if(this.state.component != undefined) {
subscription.push( component: {this.state.component} );
}
return (
×
Subscription to {subscription}
Close
);
}
});
function validateEmail(email) {
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return re.test(email);
}