2016-05-08 16:31:58 +00:00
|
|
|
|
/* [0] Constructeur -> définit le conteneur et le bouton d'ajout
|
|
|
|
|
=========================================================*/
|
|
|
|
|
function inputPhoneMatrice(container){
|
2016-05-18 13:28:02 +00:00
|
|
|
|
this.container = container;
|
2016-05-08 16:31:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* [1] Attributs
|
|
|
|
|
=========================================================*/
|
|
|
|
|
inputPhoneMatrice.prototype = {
|
2016-05-18 13:28:02 +00:00
|
|
|
|
container: this.container // Conteneur de la matrice
|
2016-05-08 16:31:58 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Gestion de l'enregistrement de la matrice
|
|
|
|
|
=========================================================*/
|
|
|
|
|
inputPhoneMatrice.prototype.fieldsToStorage = function(){
|
2016-05-18 13:28:02 +00:00
|
|
|
|
console.log('MATRICE: FIELDS TO STORAGE');
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// {1} On initialise notre deflater pour récupérer les valeurs //
|
|
|
|
|
var deflater = new FormDeflater(this.container, ['input'], ['data-name']);
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// {2} On extrait les données //
|
|
|
|
|
var deflated = deflater.deflate();
|
|
|
|
|
// On crée le hash
|
|
|
|
|
var deflatedHash = crc32(JSON.stringify(deflated));
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// console.log(deflated);
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
/* (3) On crée l'objet et on le remplit avec les relations */
|
|
|
|
|
var obj = {};
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
for( var i in deflated )
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// {1} Si c'est un tableau de sujets //
|
|
|
|
|
if( deflated[i] instanceof Array ){
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// Pour chacune des différentes relations, on ajoute si TRUE
|
|
|
|
|
for( var a in deflated[i] ){
|
|
|
|
|
if( obj[i] == null )
|
|
|
|
|
obj[i] = [];
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
obj[i].push( parseInt(deflated[i][a]) );
|
|
|
|
|
}
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// {2} Si il n'y a qu'un sujet //
|
|
|
|
|
}else if( deflated[i] !== null ){
|
|
|
|
|
if( obj[i] == null )
|
|
|
|
|
obj[i] = [];
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
obj[i].push( parseInt(deflated[i]) );
|
|
|
|
|
}
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
lsi.set( 'p_matrice', 0, obj );
|
|
|
|
|
// Objet de la forme
|
|
|
|
|
//
|
|
|
|
|
// idA: [idV, idW], # A connait V et W (et réciproquement)
|
|
|
|
|
// idB: [idX, idY], # B connait X et Y (et réciproquement)
|
|
|
|
|
// ...
|
|
|
|
|
//
|
2016-05-08 16:31:58 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] Gestion de l'affichage depuis le 'localStorage'
|
|
|
|
|
=========================================================*/
|
|
|
|
|
inputPhoneMatrice.prototype.storageToFields = function(){
|
2016-05-18 13:28:02 +00:00
|
|
|
|
console.log('MATRICE: STORAGE TO FIELDS');
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
/* (1) On récupère la liste des contacts à mettre dans la matrice */
|
|
|
|
|
// On récupère les fiches
|
|
|
|
|
var ficheData = lsi.export('p_fiches');
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// On récupère les données de la matrice
|
|
|
|
|
var matriceData = lsi.get('p_matrice', 0);
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// On récupère les contacts pour afficher les noms/prénoms
|
|
|
|
|
var contactData = lsi.export('p_contacts');
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// Contiendra les UID des contacts à mettre dans la matrice
|
|
|
|
|
var contacts = [];
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// Pour chaque fiche, on ajoute l'uid du contact s'il n'est pas déja ajouté
|
|
|
|
|
for( var f in ficheData )
|
|
|
|
|
if( contacts.indexOf( ficheData[f].contact ) == -1 )
|
|
|
|
|
contacts.push( ficheData[f].contact );
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
/* (2) On construit le HTML de la matrice */
|
|
|
|
|
// Contiendra le HTML
|
|
|
|
|
var matrice_html = "<table class='line'>";
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// {1} Pour chaque ligne //
|
|
|
|
|
for( var A = 0 ; A < contacts.length ; A++ ){
|
|
|
|
|
var conA = contactData[A];
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
matrice_html += '<tr>';
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
if( A > 0 ){ // Noms sur la première ligne (abscisses)
|
|
|
|
|
matrice_html += '<td style="text-align: right;">';
|
2016-05-19 13:14:10 +00:00
|
|
|
|
matrice_html += conA.username;
|
2016-05-18 13:28:02 +00:00
|
|
|
|
matrice_html += '</td>';
|
|
|
|
|
}else // Sinon,
|
|
|
|
|
matrice_html += '<td></td>';
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// {2} Pour chaque case //
|
|
|
|
|
for( var B = 0 ; B < contacts.length ; B++ ){ if( B < contacts.length-1 ){
|
|
|
|
|
var conB = contactData[B];
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// {3} Première colonne -> Intitulé des ordonnées //
|
|
|
|
|
if( A == 0 ){
|
|
|
|
|
matrice_html += '<td>';
|
|
|
|
|
matrice_html += '<span style="writing-mode: vertical-lr; text-align: right;">';
|
2016-05-19 13:14:10 +00:00
|
|
|
|
matrice_html += conB.username;
|
2016-05-18 13:28:02 +00:00
|
|
|
|
matrice_html += '</span>';
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// {4} Valeurs des relations (boutons) //
|
|
|
|
|
}else if( B < A ){
|
|
|
|
|
matrice_html += "<td>";
|
|
|
|
|
matrice_html += "<input type='checkbox' name='matrice_"+conA.uid+"_"+conB.uid+"' data-name='"+conA.uid+"' value='"+conB.uid+"' id='matrice_"+conA.uid+"_"+conB.uid+"'";
|
|
|
|
|
// Si la relation existe, on active le bouton
|
|
|
|
|
if( matriceData[A] != null && matriceData[A].indexOf(B) > -1 )
|
|
|
|
|
matrice_html += " checked";
|
|
|
|
|
matrice_html += " >";
|
|
|
|
|
matrice_html += "<label for='matrice_"+conA.uid+"_"+conB.uid+"'></label>";
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
// {5} Cases vides (moitié supérieure droite) //
|
|
|
|
|
}else
|
|
|
|
|
matrice_html += "<td class='hidden'>";
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
matrice_html += '</td>';
|
|
|
|
|
}}
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
matrice_html += '</tr>';
|
|
|
|
|
}
|
|
|
|
|
matrice_html += '</table>';
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
/* (3) On affiche la matrice */
|
|
|
|
|
this.container.innerHTML = matrice_html;
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [9] Point d'amorçage de la gestion des contacts
|
|
|
|
|
=========================================================*/
|
2016-05-08 21:32:07 +00:00
|
|
|
|
inputPhoneMatrice.prototype.attach = function(){
|
2016-05-18 13:28:02 +00:00
|
|
|
|
console.log('MATRICE: ATTACH');
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
/* (1) On initialise le jeu de données */
|
|
|
|
|
lsi.createDataset('p_matrice');
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
/* (2) On charge les mini fiches depuis la mémoire ('localStorage') */
|
|
|
|
|
this.storageToFields();
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
|
/* (3) On enregistre la matrice à chaque modification */
|
|
|
|
|
var ptr = this;
|
|
|
|
|
this.container.addEventListener('click', function(e){
|
|
|
|
|
ptr.fieldsToStorage();
|
|
|
|
|
ptr.storageToFields();
|
|
|
|
|
}, false);
|
2016-05-24 06:58:37 +00:00
|
|
|
|
|
|
|
|
|
this.snake();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inputPhoneMatrice.prototype.snake = function(){
|
|
|
|
|
|
|
|
|
|
/* [0] On écrit les fonctions principales
|
|
|
|
|
=========================================================*/
|
|
|
|
|
this.sVelocity = [0, 0];
|
|
|
|
|
this.sLength = 0;
|
|
|
|
|
this.sStack = [];
|
|
|
|
|
|
|
|
|
|
|
2016-05-08 16:31:58 +00:00
|
|
|
|
};
|