Accueil/js/getUncompletedTasks.php

60 lines
3.0 KiB
PHP
Raw Normal View History

2010-09-14 23:38:29 +02:00
<?header('Content-type: application/javascript');
$token = $_GET['token'];
$id = $_GET['id'];
?>
function cbfunc(o){
$('#results').append('<ul id="uncompletedList"><ul>');
for(var i in o)
{
$('#uncompletedList').append('<li id="'+o[i].id+'">'+o[i].content+' - '+o[i].date_string+' <img src="images/delete.png" class="deleteTask" id="delete-'+o[i].id+'"/> <img src="images/complete.png" class="completeTask" id="complete-'+o[i].id+'"/> </li>');
}
}
function cbfunc2(o){
$('#uncompletedList').append('<li id="'+o.id+'">'+o.content+' - '+o.date_string+' <img src="images/delete.png" id="delete-'+o.id+'"/> <img src="images/complete.png" class="completeTask" id="complete-'+o.id+'"/> </li>');
2010-09-14 23:38:29 +02:00
}
$(document).ready(function(){
$('#todoList').append('<div id="results"></div><img src="images/add.png" id="showNewTask"/><fieldset id="newTaskFieldset" style="display:none; width:200px;"><input type="text" name="newtask" id="newtask"/> <select id="priority"><option id="1" value="1">1</option><option id="2" value="2">2</option><option id="3" value="3">3</option><option id="4" value="4">4</option></select> <br/><input type="text" name="date_string" id="date_string"/> <img src="images/add.png" id="addTask"/></fieldset>');
var token = "<?=$token?>";
var project_id = "<?=$id?>";
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://todoist.com/API/getUncompletedItems?project_id='+project_id+'&token='+token+'&format=json&callback=cbfunc';
document.getElementsByTagName('head')[0].appendChild(script);
$('#showNewTask').click(function(){
$('#newTaskFieldset').toggle();
});
$('#addTask').click(function(){
var content = $('#newtask').val();
var date_string = $('#date_string').val();
var priority = $('#priority').val();
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://todoist.com/API/addItem?project_id='+project_id+'&token='+token+'&content='+content+'&date_string='+date_string+'&priority='+priority+'&format=json&callback=cbfunc2';
document.getElementsByTagName('head')[0].appendChild(script);
});
$('.deleteTask').live('click', function(){
var id = $(this).attr('id');
arrayId = id.split('-');
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://todoist.com/API/deleteItems?ids=["'+arrayId[1]+'"]&token='+token;
document.getElementsByTagName('head')[0].appendChild(script);
$('#'+arrayId[1]).remove();
});
$('.completeTask').live('click', function(){
var id = $(this).attr('id');
arrayId = id.split('-');
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://todoist.com/API/completeItems?ids=["'+arrayId[1]+'"]&token='+token;
document.getElementsByTagName('head')[0].appendChild(script);
$('#'+arrayId[1]).remove();
});
});