Created
August 12, 2015 17:03
-
-
Save Papillard/7e6c32b50e574c604c35 to your computer and use it in GitHub Desktop.
Playing with Trello API in ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
text-align: center; | |
padding: 50px; | |
font-size: 20px; | |
} | |
ul { | |
list-style: none; | |
} | |
ul li { | |
cursor: pointer; | |
padding: 10px; | |
border-bottom: 1px solid #E6E6E6; | |
} | |
.fa { | |
margin-right: 10px; | |
} | |
.fa-check { | |
color: green; | |
} | |
.fa-times { | |
color: red; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on("ready", function(){ | |
var getInfos = function(boardId){ | |
var url = trelloApiUrl + "boards/" + boardId + "/lists?key=" + apiKey; | |
$.ajax({ | |
type: "GET", | |
url: url, | |
success: function(data) { | |
getCards(data[0].id); | |
getCards(data[1].id); | |
}, | |
error: function(data) { | |
console.log('Lists not found'); | |
} | |
}); | |
} | |
var getCards = function(listId) { | |
var getCardsUrl = trelloApiUrl + "lists/" + listId + "/cards?key=" + apiKey; | |
$.ajax({ | |
type: "GET", | |
async: false, | |
url: getCardsUrl, | |
success: function(data) { | |
fillList(data); | |
}, | |
error: function(data) { | |
console.log('Cards not found'); | |
} | |
}); | |
} | |
var fillList = function(cards) { | |
for (var i = 0; i < cards.length; i++ ){ | |
if (cards[i].idList == "55cb655f1d54329e41f44f46") { | |
var $task = $("<li><i class='fa fa-times'></i>" + cards[i].name + "</li>"); | |
} else { | |
console.log(cards[i].name + " a été fait"); | |
var $task = $("<li><i class='fa fa-check'></i>" + cards[i].name + "</li>"); | |
} | |
$(".todo").append($task); | |
} | |
} | |
var trelloApiUrl = "https://api.trello.com/1/"; | |
// Insert your board id + api key below | |
var apiKey = "ab.......827"; | |
var boardId = "jr.....hH"; | |
getInfos(boardId); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css"> | |
<title>Todo list Trello</title> | |
<link rel="stylesheet" href="app.css"> | |
</head> | |
<body> | |
<h1 class="board-name">Todo list</h1> | |
<ul class="todo"> | |
</ul> | |
<!-- jQuery --> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | |
<script src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment