Version avec modules séparés !
This commit is contained in:
116
modules/todo/Todo.php
Normal file
116
modules/todo/Todo.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
class todo extends Module {
|
||||
|
||||
|
||||
protected static $paramsList = array(
|
||||
'visibility',
|
||||
'x',
|
||||
'y'
|
||||
);
|
||||
|
||||
public $params = array();
|
||||
const TODO_FILE = 'db/todoist.xml';
|
||||
private $token;
|
||||
private $project_name;
|
||||
private $project_id;
|
||||
|
||||
public function __construct($params){
|
||||
$this->moduleName = get_class();
|
||||
$this->pathToModule = 'modules/'.$this->moduleName.'/';
|
||||
$this->setParams($params);
|
||||
echo '<script type="text/javascript" src="'.$this->pathToModule.'js/'.$this->moduleName.'.js"></script>
|
||||
<link rel="stylesheet" href="'.$this->pathToModule.'css/'.$this->moduleName.'.css" type="text/css" />';
|
||||
if($xmla = simplexml_load_file($this->pathToModule.self::TODO_FILE)){
|
||||
$this->setToken($xmla->token);
|
||||
$this->setProjectName($xmla->name);
|
||||
$this->setProjectId($xmla->id);
|
||||
echo '<div id="todo" style="top:'.$params['y'].'; left :'.$params['x'].';">';
|
||||
if($this->token == null || $this->project_id == null)
|
||||
echo 'Impossible de trouver votre configuration. <a href="'.$this->pathToModule.'includes/install-todoist.php">Cliquez ici</a> pour la mettre en place.</div>';
|
||||
else{
|
||||
$token = $xmla->token;
|
||||
$id = $xmla->id;
|
||||
echo '</div><script type="text/javascript" src="'.$this->pathToModule.'js/getUncompletedTasks.php?token='.$token.'&id='.$id.'"></script>';
|
||||
}
|
||||
echo '<script>
|
||||
$(document).ready(function(){
|
||||
$(\'#todo\').resizable();
|
||||
});</script>';
|
||||
}else{
|
||||
echo 'baaaaad persistance...';
|
||||
}
|
||||
}
|
||||
|
||||
private function setToken($token){
|
||||
if($token == '' || $token == null)
|
||||
$this->token = null;
|
||||
else
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
private function setProjectName($name){
|
||||
if($name == '' || $name == null)
|
||||
$this->project_name = null;
|
||||
else
|
||||
$this->project_name = $name;
|
||||
}
|
||||
|
||||
private function setProjectId($id){
|
||||
if($id == '' || $id == null)
|
||||
$this->project_id = null;
|
||||
else
|
||||
$this->project_id = $id;
|
||||
}
|
||||
|
||||
private function setParams($params){
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public static function start($params){
|
||||
$todo = new todo($params);
|
||||
}
|
||||
|
||||
public function setX($x){
|
||||
// Saving the position and z-index of the note:
|
||||
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
|
||||
|
||||
$path = $xmla->xpath("//item[@id='todo']");
|
||||
$path[0]->x = $x;
|
||||
|
||||
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
|
||||
|
||||
echo "ok";
|
||||
}
|
||||
|
||||
public function setY($y){
|
||||
// Saving the position and z-index of the note:
|
||||
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
|
||||
|
||||
$path = $xmla->xpath("//item[@id='todo']");
|
||||
$path[0]->y = $y;
|
||||
|
||||
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
|
||||
|
||||
echo "ok";
|
||||
}
|
||||
|
||||
public function setVisibility($visibility){
|
||||
// Saving the position and z-index of the note:
|
||||
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
|
||||
|
||||
$path = $xmla->xpath("//item[@id='todo']");
|
||||
$path[0]->visibility = $visibility;
|
||||
|
||||
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
|
||||
|
||||
echo "ok";
|
||||
}
|
||||
|
||||
public static function updateConfig($updated){
|
||||
foreach ($updated as $what=>$withWhat){
|
||||
if(in_array($what, self::$paramsList)){
|
||||
call_user_func(array(get_class(), "set".ucfirst($what)), $withWhat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
modules/todo/ajax/saveTodoist.php
Normal file
21
modules/todo/ajax/saveTodoist.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?
|
||||
|
||||
$xmla = simplexml_load_file('../db/todoist.xml');
|
||||
|
||||
if(isset($_POST['token'])){
|
||||
|
||||
$token = trim($_POST['token']);
|
||||
|
||||
|
||||
|
||||
$xmla->addChild("token", $token);
|
||||
|
||||
|
||||
|
||||
$xmla->asXML('../db/todoist.xml');
|
||||
|
||||
|
||||
|
||||
echo "ok";
|
||||
|
||||
}else if(isset($_POST['name']) && isset($_POST['id'])){
|
23
modules/todo/css/todo.css
Normal file
23
modules/todo/css/todo.css
Normal file
@@ -0,0 +1,23 @@
|
||||
#todo {padding:5px;width:350px;-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;border: 1px solid rgba(0,0,0,0.3);
|
||||
-webkit-box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.15);
|
||||
-moz-box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.15);
|
||||
overflow:hidden;}
|
||||
|
||||
#todo ul{list-style:none;}
|
||||
#todo ul li{white-space : nowrap; padding-left:16px;}
|
||||
#todo ul li div.puce{width: 16px; height: 16px; background:url(../../../images/interface/ui-icons_888888_256x240.png) -32px -48px no-repeat; display:inline-block;}
|
||||
|
||||
|
||||
|
||||
.ui-resizable { position: relative;}
|
||||
.ui-resizable-handle { position: absolute;font-size: 0.1px;z-index: 99999; display: block; background-position: -80px -224px;background-image: url(../../../images/interface/ui-icons_888888_256x240.png);}
|
||||
.ui-resizable-disabled .ui-resizable-handle, .ui-resizable-autohide .ui-resizable-handle { display: none; }
|
||||
.ui-resizable-n { cursor: n-resize; height: 7px; width: 100%; top: -5px; left: 0; }
|
||||
.ui-resizable-s { cursor: s-resize; height: 7px; width: 100%; bottom: -5px; left: 0; }
|
||||
.ui-resizable-e { cursor: e-resize; width: 7px; right: -5px; top: 0; height: 100%; }
|
||||
.ui-resizable-w { cursor: w-resize; width: 7px; left: -5px; top: 0; height: 100%; }
|
||||
.ui-resizable-se { cursor: se-resize; width: 12px; height: 12px; right: 1px; bottom: 1px; }
|
||||
.ui-resizable-sw { cursor: sw-resize; width: 9px; height: 9px; left: -5px; bottom: -5px; }
|
||||
.ui-resizable-nw { cursor: nw-resize; width: 9px; height: 9px; left: -5px; top: -5px; }
|
||||
.ui-resizable-ne { cursor: ne-resize; width: 9px; height: 9px; right: -5px; top: -5px;}
|
4
modules/todo/db/todoist.xml
Normal file
4
modules/todo/db/todoist.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<todo>
|
||||
|
||||
</todo>
|
18
modules/todo/includes/getProjectsList.php
Normal file
18
modules/todo/includes/getProjectsList.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?
|
||||
|
||||
$xmla = simplexml_load_file('../db/todoist.xml');
|
||||
|
||||
if($xmla->token== '' || $xmla->token == null)
|
||||
|
||||
header('Location: install-todoist.php');
|
||||
|
||||
if($xmla->name == '' || $xmla->name == null):?>
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
|
||||
<style>
|
||||
.selectableProject{text-decoration:underline; color:blue; cursor:pointer;}
|
||||
</style>
|
||||
<title>Todoist : getProjects</title>
|
12
modules/todo/includes/getUncompletedTasks.php
Normal file
12
modules/todo/includes/getUncompletedTasks.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?
|
||||
|
||||
$xmla = simplexml_load_file('../db/todoist.xml');
|
||||
|
||||
if($xmla->token== '' || $xmla->token == null)
|
||||
|
||||
header('Location: ./');
|
||||
|
||||
if($xmla->id != '' || $xmla->id != null):
|
||||
|
||||
$token = $xmla->token;
|
||||
|
25
modules/todo/includes/install-todoist.php
Normal file
25
modules/todo/includes/install-todoist.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?
|
||||
$xmla = simplexml_load_file('../db/todoist.xml');
|
||||
if($xmla->token == '' || $xmla->token == null):?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Todoist : Login</title>
|
||||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="../js/index.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<fieldset>
|
||||
<input type="text" name="email" id="email"/><br/>
|
||||
<input type="password" name="password" id="password"/>
|
||||
<span id="loginBtn">Cliquez ici pour vous identifier</span>
|
||||
<div id="error"></div>
|
||||
<span id="todoistRegister">ou <a href="http://todoist.com/Users/showRegister">Cliquez ici</a> pour vous créer un compte (ainsi qu'un projet ;))</span>
|
||||
</fieldset>
|
||||
</body>
|
||||
</html>
|
||||
<?
|
||||
else:
|
||||
header('Location: getProjectsList.php');
|
||||
endif;
|
||||
|
6
modules/todo/js/getProjectsList.php
Normal file
6
modules/todo/js/getProjectsList.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?header('Content-type: application/javascript');
|
||||
|
||||
$token = $_GET['token'];
|
||||
|
||||
?>
|
||||
|
56
modules/todo/js/getUncompletedTasks.php
Normal file
56
modules/todo/js/getUncompletedTasks.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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/interface/delete.png" class="deleteTask" id="delete-'+o[i].id+'"/> <img src="images/interface/complete.png" class="completeTask" id="complete-'+o[i].id+'"/> </li>');
|
||||
|
||||
}
|
||||
|
||||
$('#uncompletedList li').prepend('<div class="puce"></div>');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function cbfunc2(o){
|
||||
|
||||
$('#uncompletedList').append('<li id="'+o.id+'">'+o.content+' - '+o.date_string+' <img src="images/interface/delete.png" id="delete-'+o.id+'"/> <img src="images/interface/complete.png" class="completeTask" id="complete-'+o.id+'"/> </li>');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$(document).ready(function(){
|
||||
$('#todo').resizable();
|
||||
$('#todo').draggable();
|
||||
$('#todo').append('<div id="results"></div><img src="images/interface/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/interface/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();
|
||||
|
||||
});
|
||||
|
21
modules/todo/js/index.js
Normal file
21
modules/todo/js/index.js
Normal file
@@ -0,0 +1,21 @@
|
||||
function cbfunc(o){
|
||||
|
||||
var token = o.api_token;
|
||||
|
||||
if(token == undefined){
|
||||
|
||||
$('#error').html('Identification erronnée');
|
||||
|
||||
}else{
|
||||
|
||||
$.post('../ajax/saveTodoist.php', {token: token}, function(data){
|
||||
$('body').append('<a href="getProjectsList.php">Etape suivante</a>');
|
||||
if(data=="ok"){
|
||||
location.reload();
|
||||
}else{
|
||||
alert(data);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
0
modules/todo/js/todo.js
Normal file
0
modules/todo/js/todo.js
Normal file
Reference in New Issue
Block a user