changed the way how to add a new team

This commit is contained in:
Carmine D'Amico
2016-05-25 20:31:57 +02:00
parent aa92ee26e7
commit 7f52e0caec

View File

@@ -28,6 +28,11 @@ var SettingsPage = React.createClass({
} catch (e) { } catch (e) {
config = settings.loadDefault(); config = settings.loadDefault();
} }
this.setState({
showAddTeamForm: false
});
return config; return config;
}, },
handleTeamsChange: function(teams) { handleTeamsChange: function(teams) {
@@ -75,12 +80,28 @@ var SettingsPage = React.createClass({
trayIconTheme: this.refs.trayIconTheme.getValue() trayIconTheme: this.refs.trayIconTheme.getValue()
}); });
}, },
handleShowTeamForm: function() {
if (!this.state.showAddTeamForm) {
this.setState({
showAddTeamForm: true
});
} else {
this.setState({
showAddTeamForm: false
});
}
},
render: function() { render: function() {
var teams_row = ( var teams_row = (
<Row> <Row>
<Col md={ 12 }> <Col md={ 12 }>
<h2>Teams</h2> <h2>
<TeamList teams={ this.state.teams } onTeamsChange={ this.handleTeamsChange } /> Teams
<Button className="pull-right" bsSize="small" onClick={ this.handleShowTeamForm }>
<Glyphicon glyph="plus" />
</Button>
</h2>
<TeamList teams={ this.state.teams } showAddTeamForm={ this.state.showAddTeamForm } onTeamsChange={ this.handleTeamsChange } />
</Col> </Col>
</Row> </Row>
); );
@@ -128,6 +149,11 @@ var SettingsPage = React.createClass({
}); });
var TeamList = React.createClass({ var TeamList = React.createClass({
getInitialState: function() {
return {
showTeamListItemNew: false
};
},
handleTeamRemove: function(index) { handleTeamRemove: function(index) {
console.log(index); console.log(index);
var teams = this.props.teams; var teams = this.props.teams;
@@ -149,10 +175,18 @@ var TeamList = React.createClass({
<TeamListItem index={ i } key={ "teamListItem" + i } name={ team.name } url={ team.url } onTeamRemove={ handleTeamRemove } /> <TeamListItem index={ i } key={ "teamListItem" + i } name={ team.name } url={ team.url } onTeamRemove={ handleTeamRemove } />
); );
}); });
var addTeamForm;
if (this.props.showAddTeamForm) {
addTeamForm = <TeamListItemNew onTeamAdd={ this.handleTeamAdd } />;
} else {
addTeamForm = '';
}
return ( return (
<ListGroup class="teamList"> <ListGroup class="teamList">
{ teamNodes } { teamNodes }
<TeamListItemNew onTeamAdd={ this.handleTeamAdd } /> { addTeamForm }
</ListGroup> </ListGroup>
); );
} }