aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-07-13 02:05:46 +0200
committerGravatar Tom Willemse2013-07-13 02:30:25 +0200
commitab366a1cd8ea02e405e29606a491dceb05cdb456 (patch)
tree1c0bedd5a4c6203e24a20a65ef180e6a942bcdd1
parentacb5f812f604e66b737988d67a6ce075b5cd3016 (diff)
downloadscrumli-ab366a1cd8ea02e405e29606a491dceb05cdb456.tar.gz
scrumli-ab366a1cd8ea02e405e29606a491dceb05cdb456.zip
Cleanup JS
Use `$.post' instead of `$.ajax'. This makes everything cleaner.
-rw-r--r--static/js/main.js112
1 files changed, 30 insertions, 82 deletions
diff --git a/static/js/main.js b/static/js/main.js
index a2d8754..f19351c 100644
--- a/static/js/main.js
+++ b/static/js/main.js
@@ -10,38 +10,20 @@ var StateIcon = React.createClass({
var StoryTaskRow = React.createClass({
changeState: React.autoBind(function(event) {
- $.ajax({
- url: "/tasks/state",
- type: "POST",
- data: {'id': this.props.task.id},
- dataType: 'json',
- mimeType: 'textPlain',
- success: function (data, textStatus, jqXHR) {
+ $.post("/tasks/state", {'id': this.props.task.id})
+ .done(function (data, textStatus, jqXHR) {
if (data.status == "ok")
this.setState({state: data.state});
- }.bind(this)
- });
+ }.bind(this));
}),
getInitialState: function () {
return {state: this.props.task.state};
},
moveUp: React.autoBind(function(event) {
- $.ajax({
- url: "tasks/up",
- type: "POST",
- data: {'id': this.props.task.id},
- dataType: 'json',
- mimeType: 'textPlain'
- });
+ $.post("/tasks/up", {'id': this.props.task.id});
}),
moveDown: React.autoBind(function(event) {
- $.ajax({
- url: "tasks/down",
- type: "POST",
- data: {'id': this.props.task.id},
- dataType: 'json',
- mimeType: 'textPlain'
- });
+ $.post("/tasks/down", {'id': this.props.task.id});
}),
render: function() {
return (
@@ -109,14 +91,7 @@ var StoryTaskForm = React.createClass({
var StoryData = React.createClass({
handleTaskSubmit: React.autoBind(function (task) {
task.storyId = this.props.data.id;
-
- $.ajax({
- url: "/stories/tasks/new",
- type: "POST",
- data: task,
- dataType: 'json',
- mimeType: 'textPlain'
- });
+ $.post("/stories/tasks/new", task);
}),
render: function() {
var taskTable = null;
@@ -177,50 +152,32 @@ var StoryRow = React.createClass({
this.setState({content: null});
return;
}
- var self = this;
- $.get('/stories/' + this.props.story.id, null,
- function (data, textStatus, jqXHR) {
- self.setState({content: data});
- }, 'json');
+ $.get('/stories/' + this.props.story.id)
+ .done(function (data, textStatus, jqXHR) {
+ this.setState({content: data});
+ }.bind(this), 'json');
}),
changeState: React.autoBind(function(event) {
- $.ajax({
- url: "/stories/state",
- type: "POST",
- data: {'id': this.props.story.id},
- dataType: 'json',
- mimeType: 'textPlain',
- success: function(data, textStatus, jqXHR) {
+ $.post("/stories/state", {'id': this.props.story.id})
+ .done(function(data, textStatus, jqXHR) {
if (data.status == "ok")
this.setState({state: data.state});
- }.bind(this)
- });
+ }.bind(this));
}),
moveUp: React.autoBind(function(event) {
- $.ajax({
- url: "/stories/up",
- type: "POST",
- data: {'id': this.props.story.id},
- dataType: 'json',
- mimeType: 'textPlain',
- success: function (data, textStatus, jqXHR) {
+ $.post("/stories/up", {'id': this.props.story.id})
+ .done(function (data, textStatus, jqXHR) {
if (data.status == "ok")
this.props.onMoved(1);
- }.bind(this)
- });
+ }.bind(this));
}),
moveDown: React.autoBind(function(event) {
- $.ajax({
- url: "/stories/down",
- type: "POST",
- data: {'id': this.props.story.id},
- dataType: 'json',
- mimeType: 'textPlain',
- success: function (data) {
- this.props.onMoved(-1);
- }.bind(this)
- });
+ $.post("/stories/down", {'id': this.props.story.id})
+ .done(function (data) {
+ if (data.status == "ok")
+ this.props.onMoved(-1);
+ }.bind(this));
})
});
@@ -288,13 +245,10 @@ var StoryForm = React.createClass({
var StoryPage = React.createClass({
loadStoriesFromServer: function() {
- $.ajax({
- url: this.props.url,
- mimeType: 'textPlain',
- success: function(data) {
- this.setState({data: eval(data)});
- }.bind(this)
- });
+ $.get(this.props.url)
+ .done(function(data) {
+ this.setState({data: data});
+ }.bind(this));
},
getInitialState: function() {
return {data: []};
@@ -310,20 +264,14 @@ var StoryPage = React.createClass({
this.loadStoriesFromServer();
}),
handleStorySubmit: React.autoBind(function (story) {
- $.ajax({
- url: "/stories/new",
- type: "POST",
- data: story,
- dataType: 'json',
- mimeType: 'textPlain',
- success: function (data, textStatus, jqXHR) {
+ $.post("/stories/new", story)
+ .done(function (data, textStatus, jqXHR) {
if (data.status == "ok")
this.loadStoriesFromServer();
- }.bind(this),
- error: function (jqXHR, textStatus, errorThrown) {
+ }.bind(this))
+ .fail(function (jqXHR, textStatus, errorThrown) {
alert("error: " + errorThrown);
- }.bind(this)
- });
+ }.bind(this));
}),
render: function() {
return (