editing teams is possible now

This commit is contained in:
Carmine D'Amico
2016-05-25 22:18:48 +02:00
parent 7f52e0caec
commit 510f49a99b

View File

@@ -39,8 +39,10 @@ var SettingsPage = React.createClass({
this.setState({ this.setState({
teams: teams teams: teams
}); });
this.handleSave(false);
}, },
handleSave: function() { handleSave: function(backToIndex) {
var config = { var config = {
teams: this.state.teams, teams: this.state.teams,
hideMenuBar: this.state.hideMenuBar, hideMenuBar: this.state.hideMenuBar,
@@ -55,7 +57,10 @@ var SettingsPage = React.createClass({
currentWindow.setAutoHideMenuBar(config.hideMenuBar); currentWindow.setAutoHideMenuBar(config.hideMenuBar);
currentWindow.setMenuBarVisibility(!config.hideMenuBar); currentWindow.setMenuBarVisibility(!config.hideMenuBar);
} }
if (typeof backToIndex == 'undefined' || backToIndex) {
backToIndex(); backToIndex();
}
}, },
handleCancel: function() { handleCancel: function() {
backToIndex(); backToIndex();
@@ -151,7 +156,12 @@ var SettingsPage = React.createClass({
var TeamList = React.createClass({ var TeamList = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
showTeamListItemNew: false showTeamListItemNew: false,
team: {
url: '',
name: '',
index: false
}
}; };
}, },
handleTeamRemove: function(index) { handleTeamRemove: function(index) {
@@ -162,23 +172,50 @@ var TeamList = React.createClass({
}, },
handleTeamAdd: function(team) { handleTeamAdd: function(team) {
var teams = this.props.teams; var teams = this.props.teams;
// check if team already exists and then change existing team or add new one
if (!team.index && teams[team.index]) {
teams[team.index].name = team.name;
teams[team.index].url = team.url;
} else {
teams.push(team); teams.push(team);
}
this.setState({
showTeamListItemNew: false
});
this.props.onTeamsChange(teams); this.props.onTeamsChange(teams);
}, },
handleTeamEditing: function(teamName, teamUrl, teamIndex) {
this.setState({
showTeamListItemNew: true,
team: {
url: teamUrl,
name: teamName,
index: teamIndex
}
})
},
render: function() { render: function() {
var thisObj = this; var thisObj = this;
var teamNodes = this.props.teams.map(function(team, i) { var teamNodes = this.props.teams.map(function(team, i) {
var handleTeamRemove = function() { var handleTeamRemove = function() {
thisObj.handleTeamRemove(i); thisObj.handleTeamRemove(i);
}; };
var handleTeamEditing = function() {
thisObj.handleTeamEditing(team.name, team.url, i);
};
return ( return (
<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 } onTeamEditing={ handleTeamEditing } />
); );
}); });
var addTeamForm; var addTeamForm;
if (this.props.showAddTeamForm) { if (this.props.showAddTeamForm || this.state.showTeamListItemNew) {
addTeamForm = <TeamListItemNew onTeamAdd={ this.handleTeamAdd } />; addTeamForm = <TeamListItemNew onTeamAdd={ this.handleTeamAdd } teamIndex={ this.state.team.index } teamName={ this.state.team.name } teamUrl={ this.state.team.url } />;
} else { } else {
addTeamForm = ''; addTeamForm = '';
} }
@@ -196,6 +233,9 @@ var TeamListItem = React.createClass({
handleTeamRemove: function() { handleTeamRemove: function() {
this.props.onTeamRemove(); this.props.onTeamRemove();
}, },
handleTeamEditing: function() {
this.props.onTeamEditing();
},
render: function() { render: function() {
var style = { var style = {
left: { left: {
@@ -211,6 +251,10 @@ var TeamListItem = React.createClass({
</p> </p>
</div> </div>
<div className="pull-right"> <div className="pull-right">
<Button bsSize="xsmall" onClick={ this.handleTeamEditing }>
<Glyphicon glyph="pencil" />
</Button>
{ ' ' }
<Button bsSize="xsmall" onClick={ this.handleTeamRemove }> <Button bsSize="xsmall" onClick={ this.handleTeamRemove }>
<Glyphicon glyph="remove" /> <Glyphicon glyph="remove" />
</Button> </Button>
@@ -223,8 +267,9 @@ var TeamListItem = React.createClass({
var TeamListItemNew = React.createClass({ var TeamListItemNew = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
name: '', name: this.props.teamName,
url: '' url: this.props.teamUrl,
index: this.props.teamIndex
}; };
}, },
handleSubmit: function(e) { handleSubmit: function(e) {
@@ -232,7 +277,8 @@ var TeamListItemNew = React.createClass({
e.preventDefault(); e.preventDefault();
this.props.onTeamAdd({ this.props.onTeamAdd({
name: this.state.name.trim(), name: this.state.name.trim(),
url: this.state.url.trim() url: this.state.url.trim(),
index: this.state.index,
}); });
this.setState(this.getInitialState()); this.setState(this.getInitialState());
}, },
@@ -249,9 +295,22 @@ var TeamListItemNew = React.createClass({
}); });
}, },
shouldEnableAddButton: function() { shouldEnableAddButton: function() {
return (this.state.name.trim() !== '') && (this.state.url.trim() !== ''); return (this.state.name.trim() !== '' || this.props.teamName !== '') && (this.state.url.trim() !== '' || this.props.teamUrl !== '');
}, },
render: function() { render: function() {
var existingTeam = false;
if (this.state.name !== '' && this.state.url !== '') {
existingTeam = true;
}
var btnAddText;
if (existingTeam) {
btnAddText = 'Save';
} else {
btnAddText = 'Add';
}
return ( return (
<ListGroupItem> <ListGroupItem>
<form className="form-inline" onSubmit={ this.handleSubmit }> <form className="form-inline" onSubmit={ this.handleSubmit }>
@@ -267,7 +326,7 @@ var TeamListItemNew = React.createClass({
<input type="url" className="form-control" id="inputTeamURL" placeholder="https://example.com/team" value={ this.state.url } onChange={ this.handleURLChange } /> <input type="url" className="form-control" id="inputTeamURL" placeholder="https://example.com/team" value={ this.state.url } onChange={ this.handleURLChange } />
</div> </div>
{ ' ' } { ' ' }
<Button type="submit" disabled={ !this.shouldEnableAddButton() }>Add</Button> <Button type="submit" disabled={ !this.shouldEnableAddButton() }>{ btnAddText }</Button>
</form> </form>
</ListGroupItem> </ListGroupItem>
); );