Skip to content

Ep 19 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
handled mark task done api call
  • Loading branch information
chiraggshah committed Sep 14, 2015
commit fee1a8dc66a525c8a1ae63034522b460ca4eb678
14 changes: 13 additions & 1 deletion ep19-call-api-jquery/app/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ export default class App extends React.Component {

todo.done = !todo.done;

this.setState({ todos: _todos });
var processData = function(data) {
this.setState({todos: data.todos});
};

var markTaskDoneCallback = function(data){
if(data.success){
api.getTasks(processData.bind(this));
} else {
console.log("Failed to mark task as done/undone")
}
};

api.markTaskDone(markTaskDoneCallback.bind(this), todo);
}

handleDelete (idToBeDeleted) {
Expand Down
14 changes: 12 additions & 2 deletions ep19-call-api-jquery/app/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ var api = {
this.makeAjaxCall(url, 'GET', processData)
},

makeAjaxCall (url, type, processDataCallback) {
markTaskDone (processData, todo) {
var url = Constants.BASE_URL + 'todos/' + todo.id;
var params = {
id: todo.id,
done: todo.done
};
this.makeAjaxCall(url, 'PUT', processData, params)
},

makeAjaxCall (url, type, processDataCallback, params) {
$.ajax({
type: type,
url: url,
data: {
api_key: Constants.API_KEY
api_key: Constants.API_KEY,
todo: params
},
dataType: 'json',
success: function(data) {
Expand Down