Cleanup JS
Use `$.post' instead of `$.ajax'. This makes everything cleaner.
This commit is contained in:
parent
acb5f812f6
commit
ab366a1cd8
1 changed files with 30 additions and 82 deletions
|
@ -10,38 +10,20 @@ var StateIcon = React.createClass({
|
||||||
|
|
||||||
var StoryTaskRow = React.createClass({
|
var StoryTaskRow = React.createClass({
|
||||||
changeState: React.autoBind(function(event) {
|
changeState: React.autoBind(function(event) {
|
||||||
$.ajax({
|
$.post("/tasks/state", {'id': this.props.task.id})
|
||||||
url: "/tasks/state",
|
.done(function (data, textStatus, jqXHR) {
|
||||||
type: "POST",
|
|
||||||
data: {'id': this.props.task.id},
|
|
||||||
dataType: 'json',
|
|
||||||
mimeType: 'textPlain',
|
|
||||||
success: function (data, textStatus, jqXHR) {
|
|
||||||
if (data.status == "ok")
|
if (data.status == "ok")
|
||||||
this.setState({state: data.state});
|
this.setState({state: data.state});
|
||||||
}.bind(this)
|
}.bind(this));
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
getInitialState: function () {
|
getInitialState: function () {
|
||||||
return {state: this.props.task.state};
|
return {state: this.props.task.state};
|
||||||
},
|
},
|
||||||
moveUp: React.autoBind(function(event) {
|
moveUp: React.autoBind(function(event) {
|
||||||
$.ajax({
|
$.post("/tasks/up", {'id': this.props.task.id});
|
||||||
url: "tasks/up",
|
|
||||||
type: "POST",
|
|
||||||
data: {'id': this.props.task.id},
|
|
||||||
dataType: 'json',
|
|
||||||
mimeType: 'textPlain'
|
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
moveDown: React.autoBind(function(event) {
|
moveDown: React.autoBind(function(event) {
|
||||||
$.ajax({
|
$.post("/tasks/down", {'id': this.props.task.id});
|
||||||
url: "tasks/down",
|
|
||||||
type: "POST",
|
|
||||||
data: {'id': this.props.task.id},
|
|
||||||
dataType: 'json',
|
|
||||||
mimeType: 'textPlain'
|
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
render: function() {
|
render: function() {
|
||||||
return (
|
return (
|
||||||
|
@ -109,14 +91,7 @@ var StoryTaskForm = React.createClass({
|
||||||
var StoryData = React.createClass({
|
var StoryData = React.createClass({
|
||||||
handleTaskSubmit: React.autoBind(function (task) {
|
handleTaskSubmit: React.autoBind(function (task) {
|
||||||
task.storyId = this.props.data.id;
|
task.storyId = this.props.data.id;
|
||||||
|
$.post("/stories/tasks/new", task);
|
||||||
$.ajax({
|
|
||||||
url: "/stories/tasks/new",
|
|
||||||
type: "POST",
|
|
||||||
data: task,
|
|
||||||
dataType: 'json',
|
|
||||||
mimeType: 'textPlain'
|
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
render: function() {
|
render: function() {
|
||||||
var taskTable = null;
|
var taskTable = null;
|
||||||
|
@ -177,50 +152,32 @@ var StoryRow = React.createClass({
|
||||||
this.setState({content: null});
|
this.setState({content: null});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var self = this;
|
|
||||||
|
|
||||||
$.get('/stories/' + this.props.story.id, null,
|
$.get('/stories/' + this.props.story.id)
|
||||||
function (data, textStatus, jqXHR) {
|
.done(function (data, textStatus, jqXHR) {
|
||||||
self.setState({content: data});
|
this.setState({content: data});
|
||||||
}, 'json');
|
}.bind(this), 'json');
|
||||||
}),
|
}),
|
||||||
changeState: React.autoBind(function(event) {
|
changeState: React.autoBind(function(event) {
|
||||||
$.ajax({
|
$.post("/stories/state", {'id': this.props.story.id})
|
||||||
url: "/stories/state",
|
.done(function(data, textStatus, jqXHR) {
|
||||||
type: "POST",
|
|
||||||
data: {'id': this.props.story.id},
|
|
||||||
dataType: 'json',
|
|
||||||
mimeType: 'textPlain',
|
|
||||||
success: function(data, textStatus, jqXHR) {
|
|
||||||
if (data.status == "ok")
|
if (data.status == "ok")
|
||||||
this.setState({state: data.state});
|
this.setState({state: data.state});
|
||||||
}.bind(this)
|
}.bind(this));
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
moveUp: React.autoBind(function(event) {
|
moveUp: React.autoBind(function(event) {
|
||||||
$.ajax({
|
$.post("/stories/up", {'id': this.props.story.id})
|
||||||
url: "/stories/up",
|
.done(function (data, textStatus, jqXHR) {
|
||||||
type: "POST",
|
|
||||||
data: {'id': this.props.story.id},
|
|
||||||
dataType: 'json',
|
|
||||||
mimeType: 'textPlain',
|
|
||||||
success: function (data, textStatus, jqXHR) {
|
|
||||||
if (data.status == "ok")
|
if (data.status == "ok")
|
||||||
this.props.onMoved(1);
|
this.props.onMoved(1);
|
||||||
}.bind(this)
|
}.bind(this));
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
moveDown: React.autoBind(function(event) {
|
moveDown: React.autoBind(function(event) {
|
||||||
$.ajax({
|
$.post("/stories/down", {'id': this.props.story.id})
|
||||||
url: "/stories/down",
|
.done(function (data) {
|
||||||
type: "POST",
|
if (data.status == "ok")
|
||||||
data: {'id': this.props.story.id},
|
|
||||||
dataType: 'json',
|
|
||||||
mimeType: 'textPlain',
|
|
||||||
success: function (data) {
|
|
||||||
this.props.onMoved(-1);
|
this.props.onMoved(-1);
|
||||||
}.bind(this)
|
}.bind(this));
|
||||||
});
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -288,13 +245,10 @@ var StoryForm = React.createClass({
|
||||||
|
|
||||||
var StoryPage = React.createClass({
|
var StoryPage = React.createClass({
|
||||||
loadStoriesFromServer: function() {
|
loadStoriesFromServer: function() {
|
||||||
$.ajax({
|
$.get(this.props.url)
|
||||||
url: this.props.url,
|
.done(function(data) {
|
||||||
mimeType: 'textPlain',
|
this.setState({data: data});
|
||||||
success: function(data) {
|
}.bind(this));
|
||||||
this.setState({data: eval(data)});
|
|
||||||
}.bind(this)
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {data: []};
|
return {data: []};
|
||||||
|
@ -310,20 +264,14 @@ var StoryPage = React.createClass({
|
||||||
this.loadStoriesFromServer();
|
this.loadStoriesFromServer();
|
||||||
}),
|
}),
|
||||||
handleStorySubmit: React.autoBind(function (story) {
|
handleStorySubmit: React.autoBind(function (story) {
|
||||||
$.ajax({
|
$.post("/stories/new", story)
|
||||||
url: "/stories/new",
|
.done(function (data, textStatus, jqXHR) {
|
||||||
type: "POST",
|
|
||||||
data: story,
|
|
||||||
dataType: 'json',
|
|
||||||
mimeType: 'textPlain',
|
|
||||||
success: function (data, textStatus, jqXHR) {
|
|
||||||
if (data.status == "ok")
|
if (data.status == "ok")
|
||||||
this.loadStoriesFromServer();
|
this.loadStoriesFromServer();
|
||||||
}.bind(this),
|
}.bind(this))
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
.fail(function (jqXHR, textStatus, errorThrown) {
|
||||||
alert("error: " + errorThrown);
|
alert("error: " + errorThrown);
|
||||||
}.bind(this)
|
}.bind(this));
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
render: function() {
|
render: function() {
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue