Version avec modules séparés !
This commit is contained in:
51
modules/notes/Notes.php
Normal file
51
modules/notes/Notes.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
class notes extends Module {
|
||||
|
||||
protected $moduleName;
|
||||
protected $moduleTitle;
|
||||
protected $pathToModule;
|
||||
|
||||
protected static $paramsList = array(
|
||||
'visibility'
|
||||
);
|
||||
|
||||
public $params = array();
|
||||
|
||||
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" type="text/css" href="'.$this->pathToModule.'css/'.$this->moduleName.'.css">
|
||||
<a id="addButton" class="green-button" href="'.$this->pathToModule.'includes/add_note.html">Add a note</a>';
|
||||
include $this->pathToModule.'includes/notes_extract.php';
|
||||
}
|
||||
|
||||
private function setParams($params){
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public static function start($params){
|
||||
$notes = new notes($params);
|
||||
}
|
||||
|
||||
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='notes']");
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
modules/notes/ajax/update_position.php
Normal file
22
modules/notes/ajax/update_position.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// Error reporting
|
||||
error_reporting(E_ALL^E_NOTICE);
|
||||
|
||||
// Validating the input data:
|
||||
if(!is_numeric($_GET['id']) || !is_numeric($_GET['x']) || !is_numeric($_GET['y']) || !is_numeric($_GET['z']))
|
||||
die("0");
|
||||
|
||||
// Escaping:
|
||||
$id = (int)$_GET['id'];
|
||||
$x = (int)$_GET['x'];
|
||||
$y = (int)$_GET['y'];
|
||||
$z = (int)$_GET['z'];
|
||||
|
||||
|
||||
// Saving the position and z-index of the note:
|
||||
$xmla = simplexml_load_file('../db/notes.xml');
|
||||
|
||||
$target = -1;
|
||||
$i = 0;
|
||||
|
||||
foreach ($xmla->note as $s) {
|
118
modules/notes/css/notes.css
Normal file
118
modules/notes/css/notes.css
Normal file
@@ -0,0 +1,118 @@
|
||||
.note{
|
||||
height:150px;
|
||||
padding:10px;
|
||||
width:150px;
|
||||
position:absolute;
|
||||
overflow:hidden;
|
||||
cursor:move;
|
||||
|
||||
font-family:Trebuchet MS,Tahoma,Myriad Pro,Arial,Verdana,sans-serif;
|
||||
font-size:22px;
|
||||
|
||||
/* Adding a CSS3 shadow below the note, in the browsers which support it: */
|
||||
-moz-box-shadow:2px 2px 0 #DDDDDD;
|
||||
-webkit-box-shadow:2px 2px 0 #DDDDDD;
|
||||
box-shadow:2px 2px 0 #DDDDDD;
|
||||
}
|
||||
|
||||
#fancy_ajax .note{ cursor:default; }
|
||||
|
||||
/* Three styles for the notes: */
|
||||
|
||||
.yellow{
|
||||
background-color:#FDFB8C;
|
||||
border:1px solid #DEDC65;
|
||||
}
|
||||
|
||||
.blue{
|
||||
background-color:#A6E3FC;
|
||||
border:1px solid #75C5E7;
|
||||
}
|
||||
|
||||
.green{
|
||||
background-color:#A5F88B;
|
||||
border:1px solid #98E775;
|
||||
}
|
||||
|
||||
/* Each note has a data span, which holds its ID */
|
||||
span.data{ display:none; }
|
||||
|
||||
/* The "Add a note" button: */
|
||||
#addButton{
|
||||
position:absolute;
|
||||
top:10px;
|
||||
left:10;
|
||||
}
|
||||
|
||||
|
||||
.author{
|
||||
/* The author name on the note: */
|
||||
bottom:10px;
|
||||
color:#666666;
|
||||
font-family:Arial,Verdana,sans-serif;
|
||||
font-size:12px;
|
||||
position:absolute;
|
||||
right:10px;
|
||||
}
|
||||
|
||||
#main{
|
||||
/* Contains all the notes and limits their movement: */
|
||||
margin:0 auto;
|
||||
position:relative;
|
||||
width:980px;
|
||||
height:500px;
|
||||
z-index:10;
|
||||
/*background:url(../images/add_a_note_help.gif) no-repeat left top;*/
|
||||
}
|
||||
|
||||
h3.popupTitle{
|
||||
border-bottom:1px solid #DDDDDD;
|
||||
color:#666666;
|
||||
font-size:24px;
|
||||
font-weight:normal;
|
||||
padding:0 0 5px;
|
||||
}
|
||||
|
||||
#noteData{
|
||||
/* The input form in the pop-up: */
|
||||
height:200px;
|
||||
margin:30px 0 0 200px;
|
||||
width:350px;
|
||||
}
|
||||
|
||||
.note-form label{
|
||||
display:block;
|
||||
font-size:10px;
|
||||
font-weight:bold;
|
||||
letter-spacing:1px;
|
||||
text-transform:uppercase;
|
||||
padding-bottom:3px;
|
||||
}
|
||||
|
||||
.note-form textarea, .note-form input[type=text]{
|
||||
background-color:#FCFCFC;
|
||||
border:1px solid #AAAAAA;
|
||||
font-family:Arial,Verdana,sans-serif;
|
||||
font-size:16px;
|
||||
height:60px;
|
||||
padding:5px;
|
||||
width:300px;
|
||||
margin-bottom:10px;
|
||||
}
|
||||
|
||||
.note-form input[type=text]{ height:auto; }
|
||||
|
||||
.color{
|
||||
/* The color swatches in the form: */
|
||||
cursor:pointer;
|
||||
float:left;
|
||||
height:10px;
|
||||
margin:0 5px 0 0;
|
||||
width:10px;
|
||||
}
|
||||
|
||||
#note-submit{ margin:20px auto; }
|
||||
.delete {display:none; height:16px; width:16px; background:url(../../../images/interface/delete.png) top left no-repeat; position:absolute; top:5px; right:5px; z-index:9999;}
|
||||
.delete:hover{cursor:pointer !important;}
|
||||
|
||||
|
6
modules/notes/db/notes.xml
Normal file
6
modules/notes/db/notes.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Notes>
|
||||
|
||||
|
||||
|
||||
<note id="2"><text>Test de post-it.</text><color>green</color><zindex>1</zindex><top>153</top><left>53</left></note><note id="7"><text>/!\ C'est bien fait ? :)</text><color>yellow</color><zindex>1</zindex><top>85</top><left>1038</left></note><note id="10"><text>Des améliorations ?</text><color>yellow</color><zindex>1</zindex><top>264</top><left>1038</left></note><note id="11"><text>Application android pour les horaires et prix des trains à faire</text><color>blue</color><zindex>2</zindex><top>586</top><left>916</left></note></Notes>
|
26
modules/notes/includes/add_note.html
Normal file
26
modules/notes/includes/add_note.html
Normal file
@@ -0,0 +1,26 @@
|
||||
<h3 class="popupTitle">Add a new note</h3>
|
||||
|
||||
<!-- The preview: -->
|
||||
<div id="previewNote" class="note yellow" style="left:0;top:65px;z-index:1">
|
||||
<div class="delete"></div>
|
||||
<div class="body"></div>
|
||||
<div class="author"></div>
|
||||
<span class="data"></span>
|
||||
</div>
|
||||
|
||||
<div id="noteData"> <!-- Holds the form -->
|
||||
<form action="" method="post" class="note-form">
|
||||
|
||||
<label for="note-body">Texte de la note</label>
|
||||
<textarea name="note-body" id="note-body" class="pr-body" cols="30" rows="6"></textarea>
|
||||
|
||||
<label>Couleur</label> <!-- Clicking one of the divs changes the color of the preview -->
|
||||
<div class="color yellow"></div>
|
||||
<div class="color blue"></div>
|
||||
<div class="color green"></div>
|
||||
|
||||
<!-- The green submit button: -->
|
||||
<a id="note-submit" href="" class="green-button">Enregistrer</a>
|
||||
|
||||
</form>
|
||||
</div>
|
8
modules/notes/includes/notes_extract.php
Normal file
8
modules/notes/includes/notes_extract.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php $nb = 0;
|
||||
$notes = simplexml_load_file('modules/notes/db/notes.xml');
|
||||
foreach($notes as $test){$nb++;}
|
||||
for($i=0; $i<$nb; $i++){?>
|
||||
<div class="note <?echo $notes->note[$i]->color;?>" style="position:absolute; left:<? echo $notes->note[$i]->left;?>; top:<? echo $notes->note[$i]->top;?>;z-index:<? echo $notes->note[$i]->zindex;?>;"><div class="delete" id="r-<?echo $notes->note[$i]['id'];?>"></div><? echo $notes->note[$i]->text;?><br/><span class="data"><?echo $notes->note[$i]['id'];?></span></div>
|
||||
<?}?>
|
||||
|
||||
|
130
modules/notes/js/notes.js
Normal file
130
modules/notes/js/notes.js
Normal file
@@ -0,0 +1,130 @@
|
||||
$(document).ready(function(){
|
||||
$('.delete').css({"display":"none"});//initialisation des delete
|
||||
|
||||
//passage au dessus des notes
|
||||
$('.note').hover(function () {
|
||||
$(this).find('.delete').css({"display":"block"});
|
||||
},
|
||||
function () {
|
||||
$(this).find('.delete').css({"display":"none"});
|
||||
});
|
||||
|
||||
//click sur delete
|
||||
$('.delete').click(function(){
|
||||
var data2 = {'id' : $(this).attr("id")};
|
||||
$(this).replaceWith('<img src="images/interface/ajax_load.gif" style="display:block" />');
|
||||
/* Sending an AJAX POST request: */
|
||||
$.post('modules/notes/ajax/delete-notes.php',data2,function(msg2){
|
||||
if(parseInt(msg2))
|
||||
{
|
||||
msg2--;
|
||||
//alert(msg2);
|
||||
$(".note:eq("+msg2+")").fadeOut();
|
||||
}
|
||||
|
||||
//$(this).parent('.note').hide();
|
||||
});
|
||||
});
|
||||
|
||||
var tmp;
|
||||
|
||||
$('.note').each(function(){
|
||||
/* Finding the biggest z-index value of the notes */
|
||||
|
||||
tmp = $(this).css('z-index');
|
||||
if(tmp>zIndex) zIndex = tmp;
|
||||
})
|
||||
|
||||
/* A helper function for converting a set of elements to draggables: */
|
||||
make_draggable($('.note'));
|
||||
|
||||
/* Configuring the fancybox plugin for the "Add a note" button: */
|
||||
$("#addButton").fancybox({
|
||||
'zoomSpeedIn' : 600,
|
||||
'zoomSpeedOut' : 500,
|
||||
'easingIn' : 'easeOutBack',
|
||||
'easingOut' : 'easeInBack',
|
||||
'hideOnContentClick': false,
|
||||
'padding' : 15
|
||||
});
|
||||
|
||||
/* Listening for keyup events on fields of the "Add a note" form: */
|
||||
$('.pr-body,.pr-author').live('keyup',function(e){
|
||||
|
||||
if(!this.preview)
|
||||
this.preview=$('#previewNote');
|
||||
|
||||
/* Setting the text of the preview to the contents of the input field, and stripping all the HTML tags: */
|
||||
this.preview.find($(this).attr('class').replace('pr-','.')).html($(this).val().replace(/<[^>]+>/ig,''));
|
||||
});
|
||||
|
||||
/* Changing the color of the preview note: */
|
||||
$('.color').live('click',function(){
|
||||
|
||||
$('#previewNote').removeClass('yellow green blue').addClass($(this).attr('class').replace('color',''));
|
||||
});
|
||||
/* The submit button: */
|
||||
$('#note-submit').live('click',function(e){
|
||||
|
||||
if($('.pr-body').val().length<4)
|
||||
{
|
||||
alert("The note text is too short!")
|
||||
return false;
|
||||
}
|
||||
|
||||
/*if($('.pr-author').val().length<1)
|
||||
{
|
||||
alert("You haven't entered your name!")
|
||||
return false;
|
||||
}*/
|
||||
|
||||
$(this).replaceWith('<img src="images/interface/ajax_load.gif" style="margin:30px auto;display:block" />');
|
||||
|
||||
var data = {
|
||||
'zindex' : ++zIndex,
|
||||
'body' : $('.pr-body').val(),
|
||||
/*'author' : $('.pr-author').val(),*/
|
||||
'color' : $.trim($('#previewNote').attr('class').replace('note',''))
|
||||
};
|
||||
|
||||
/* Sending an AJAX POST request: */
|
||||
$.post('modules/notes/ajax/post-notes.php',data,function(msg){
|
||||
|
||||
if(parseInt(msg))
|
||||
{
|
||||
/* msg contains the ID of the note, assigned by MySQL's auto increment: */
|
||||
var tmp = $('#previewNote').clone();
|
||||
//tmp.find('.delete').attr('id',msg);
|
||||
tmp.find('span.data').text(msg).end().css({'z-index':zIndex,top:0,left:0});
|
||||
tmp.appendTo('body');
|
||||
|
||||
make_draggable(tmp)
|
||||
}
|
||||
|
||||
//$.fn.fancybox.close;
|
||||
$.fancybox.close();
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
var zIndex = 0;
|
||||
|
||||
function make_draggable(elements)
|
||||
{
|
||||
/* Elements is a jquery object: */
|
||||
elements.draggable({
|
||||
containment:'parent',
|
||||
start:function(e,ui){ ui.helper.css('z-index',++zIndex); },
|
||||
stop:function(e,ui){
|
||||
|
||||
/* Sending the z-index and positon of the note to update_position.php via AJAX GET: */
|
||||
$.get('modules/notes/ajax/update_position.php',{
|
||||
x : ui.position.left,
|
||||
y : ui.position.top,
|
||||
z : zIndex,
|
||||
id : parseInt(ui.helper.find('span.data').html())
|
||||
});
|
||||
}
|
||||
});}
|
||||
});
|
Reference in New Issue
Block a user