Use a modal dialog to create tasks

This fixes the issue where focus and input would be lost from the input
field when the story would reload its tasks.

This also makes it a little more uniform with the other forms.
This commit is contained in:
Tom Willemse 2013-08-11 14:21:39 +02:00
parent 781befeb23
commit d3eaa60b63

View file

@ -123,38 +123,44 @@ var StoryTaskForm = React.createClass({
handleSubmit: React.autoBind(function() { handleSubmit: React.autoBind(function() {
var text = this.refs.text.getDOMNode().value.trim(); var text = this.refs.text.getDOMNode().value.trim();
this.props.onTaskSubmit({description: text}); this.props.onTaskSubmit({description: text,
storyId: this.state.storyId});
$(".taskModal").modal('hide');
this.refs.text.getDOMNode().value = ''; this.refs.text.getDOMNode().value = '';
return false; return false;
}), }),
getInitialState: function() {
return {storyId: null};
},
setStoryId: React.autoBind(function(id) {
this.setState({storyId: id});
}),
render: function() { render: function() {
return ( return (
<form onSubmit={this.handleSubmit}> <div class="taskModal modal fade hide">
<fieldset> <div class="modal-header">
<legend>New task</legend> <button type="button" class="close" data-dismiss="modal">
<div class="input-append"> &times;
<input type="text" ref="text" class="input-medium" /> </button>
<button type="submit" class="btn btn-primary"> <h3 id="taskModalLabel">New task</h3>
Send </div>
</button> <div class="modal-body">
</div> <input type="text" ref="text" class="input-medium" />
</fieldset> </div>
</form> <div class="modal-footer">
<button type="button" class="btn btn-primary"
onClick={this.handleSubmit}>
Send
</button>
</div>
</div>
); );
} }
}); });
var StoryData = React.createClass({ var StoryData = React.createClass({
handleTaskSubmit: React.autoBind(function (task) {
task.storyId = this.state.data.id;
$.post(baseUrl + "stories/tasks/new", task)
.done(function(data) {
if (data.status == "ok")
this.loadStoryFromServer();
}.bind(this));
}),
loadStoryFromServer: function() { loadStoryFromServer: function() {
$.get(baseUrl + "stories/" + this.state.data.id) $.get(baseUrl + "stories/" + this.state.data.id)
.done(this.setData.bind(this)); .done(this.setData.bind(this));
@ -178,14 +184,19 @@ var StoryData = React.createClass({
render: function() { render: function() {
if (this.state.data) { if (this.state.data) {
return (<div> return (<div>
<h1>{this.state.data.title}</h1> <h1>
<button data-target=".taskModal" role="button"
data-toggle="modal" class="nothing">
<i class="icon-plus-sign icon-2x"></i>
</button>
{this.state.data.title}
</h1>
<div class="well normalText"> <div class="well normalText">
{this.state.data.content} {this.state.data.content}
</div> </div>
<StoryTaskTable tasks={this.state.data.tasks || []} <StoryTaskTable tasks={this.state.data.tasks || []}
onTaskMoved={this.handleTaskMoved} onTaskMoved={this.handleTaskMoved}
onAssigneeClicked={this.props.onAssigneeClicked} /> onAssigneeClicked={this.props.onAssigneeClicked} />
<StoryTaskForm onTaskSubmit={this.handleTaskSubmit} />
</div>); </div>);
} }
@ -299,11 +310,11 @@ var AssignmentForm = React.createClass({
render: function() { render: function() {
return ( return (
<div class="assignModal modal fade hide"> <div class="assignModal modal fade hide">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" <button type="button" class="close"
data-dismiss="modal"> data-dismiss="modal">
&times; &times;
</button> </button>
<h3 id="assignModalLabel">Assign</h3> <h3 id="assignModalLabel">Assign</h3>
</div> </div>
<div class="modal-body"> <div class="modal-body">
@ -429,6 +440,7 @@ var StoryPage = React.createClass({
$.get(baseUrl + 'stories/' + storyId) $.get(baseUrl + 'stories/' + storyId)
.done(function (data, textStatus, jqXHR) { .done(function (data, textStatus, jqXHR) {
this.refs.data.setData(data); this.refs.data.setData(data);
this.refs.taskForm.setStoryId(data.id);
}.bind(this), 'json'); }.bind(this), 'json');
}), }),
handleAssigneeClicked: React.autoBind(function (info) { handleAssigneeClicked: React.autoBind(function (info) {
@ -438,6 +450,13 @@ var StoryPage = React.createClass({
$(".assignModal").modal(); $(".assignModal").modal();
}), }),
handleTaskSubmit: React.autoBind(function (task) {
$.post(baseUrl + "stories/tasks/new", task)
.done(function(data) {
if (data.status == "ok")
this.refs.data.loadStoryFromServer();
}.bind(this));
}),
render: function() { render: function() {
return ( return (
<div class="row"> <div class="row">
@ -453,6 +472,8 @@ var StoryPage = React.createClass({
<StoryData ref="data" <StoryData ref="data"
pollInterval={this.props.pollInterval} pollInterval={this.props.pollInterval}
onAssigneeClicked={this.handleAssigneeClicked} /> onAssigneeClicked={this.handleAssigneeClicked} />
<StoryTaskForm onTaskSubmit={this.handleTaskSubmit}
ref="taskForm"/>
</div> </div>
</div> </div>
); );