2016-05-08 16:31:58 +00:00
|
|
|
/* [0] Constructeur -> définit le conteneur et le bouton d'ajout
|
|
|
|
=========================================================*/
|
2016-10-02 16:01:35 +00:00
|
|
|
var inputPhoneMatrice = function(container){
|
2016-05-18 13:28:02 +00:00
|
|
|
this.container = container;
|
2016-10-02 16:01:35 +00:00
|
|
|
};
|
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-10-10 08:58:44 +00:00
|
|
|
console.group('[phone.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();
|
2016-10-22 14:05:11 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
// 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
|
|
|
/* (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
|
2016-10-09 15:44:06 +00:00
|
|
|
for( var O in deflated[i] ){
|
2016-05-18 13:28:02 +00:00
|
|
|
if( obj[i] == null )
|
|
|
|
obj[i] = [];
|
2016-05-08 16:31:58 +00:00
|
|
|
|
2016-10-09 15:44:06 +00:00
|
|
|
obj[i].push( parseInt(deflated[i][O]) );
|
2016-05-18 13:28:02 +00:00
|
|
|
}
|
2016-05-08 16:31:58 +00:00
|
|
|
|
2016-10-22 14:05:11 +00:00
|
|
|
// {2} Si il n'y qu'un sujet //
|
2016-05-18 13:28:02 +00:00
|
|
|
}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
|
|
|
|
//
|
2016-10-09 15:44:06 +00:00
|
|
|
// idA: [idV, idW], # O connait V et W (et réciproquement)
|
2016-05-18 13:28:02 +00:00
|
|
|
// idB: [idX, idY], # B connait X et Y (et réciproquement)
|
|
|
|
// ...
|
|
|
|
//
|
2016-10-10 08:58:44 +00:00
|
|
|
|
|
|
|
|
2016-10-11 12:05:59 +00:00
|
|
|
console.groupEnd();
|
2016-05-08 16:31:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] Gestion de l'affichage depuis le 'localStorage'
|
|
|
|
=========================================================*/
|
|
|
|
inputPhoneMatrice.prototype.storageToFields = function(){
|
2016-10-10 08:58:44 +00:00
|
|
|
console.group('[phone.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-24 09:51:46 +00:00
|
|
|
// On récupère les contacts pour afficher les noms/prénoms
|
2016-05-18 13:28:02 +00:00
|
|
|
var contactData = lsi.export('p_contacts');
|
2016-05-08 16:31:58 +00:00
|
|
|
|
2016-05-24 09:51:46 +00:00
|
|
|
// Contiendra les UID des contacts à mettre dans la matrice
|
2016-05-18 13:28:02 +00:00
|
|
|
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
|
2016-10-22 14:05:11 +00:00
|
|
|
var matrice_html = ["<div class='line matrice'>"];
|
|
|
|
var conA, conB, L, Ll, C, Cl;
|
2016-05-08 16:31:58 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
// {1} Pour chaque ligne //
|
2016-10-22 14:05:11 +00:00
|
|
|
for( L = 0, Ll = contacts.length ; L < Ll ; L++ ){
|
|
|
|
conA = contactData[L];
|
|
|
|
|
|
|
|
// {2} Pour chaque case //
|
|
|
|
for( C = L+1, Cl = contacts.length ; C < Cl ; C++ ){
|
|
|
|
conB = contactData[C];
|
2016-05-08 16:31:58 +00:00
|
|
|
|
2016-10-22 14:05:11 +00:00
|
|
|
// {3} Insertion //
|
|
|
|
matrice_html.push( "<input type='checkbox' data-name='"+conA.uid+"' value='"+conB.uid+"' id='f_matrice_"+conA.uid+"_"+conB.uid+"'" );
|
2016-05-08 16:31:58 +00:00
|
|
|
|
2016-10-22 14:05:11 +00:00
|
|
|
// Si lien actif, on le restitue
|
|
|
|
if( matriceData.hasOwnProperty(conA.uid) && matriceData[conA.uid].indexOf(conB.uid) > -1 )
|
|
|
|
matrice_html.push( "checked='checked'");
|
2016-05-08 16:31:58 +00:00
|
|
|
|
2016-10-22 14:05:11 +00:00
|
|
|
matrice_html.push( ">" );
|
|
|
|
|
|
|
|
matrice_html.push( "<label class='matrice-content' for='f_matrice_"+conA.uid+"_"+conB.uid+"'>")
|
|
|
|
matrice_html.push( "Est-ce que <span>" );
|
2016-10-12 14:20:46 +00:00
|
|
|
matrice_html.push( !isNaN(conA.existing) ? lsi.get('p_friends', conA.existing).name : conA.username );
|
2016-10-22 14:05:11 +00:00
|
|
|
matrice_html.push( '</span> et <span>' );
|
|
|
|
matrice_html.push( !isNaN(conB.existing) ? lsi.get('p_friends', conB.existing).name : conB.username );
|
|
|
|
matrice_html.push( '</span> se connaissant ?' );
|
|
|
|
matrice_html.push( "</label>" );
|
|
|
|
|
|
|
|
}
|
2016-05-08 16:31:58 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
}
|
2016-10-22 14:05:11 +00:00
|
|
|
matrice_html.push( '</div>' );
|
2016-05-08 16:31:58 +00:00
|
|
|
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
/* (3) On affiche la matrice */
|
2016-10-12 14:20:46 +00:00
|
|
|
this.container.innerHTML = matrice_html.join('');
|
2016-05-08 16:31:58 +00:00
|
|
|
|
2016-10-11 12:05:59 +00:00
|
|
|
console.groupEnd();
|
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-10-10 08:58:44 +00:00
|
|
|
console.group('[phone.matrice] attaching events');
|
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){
|
2016-06-07 09:06:59 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
ptr.fieldsToStorage();
|
2016-06-07 09:06:59 +00:00
|
|
|
|
|
|
|
setTimeout(function(){ ptr.storageToFields(); }, 500);
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
}, false);
|
2016-10-10 08:58:44 +00:00
|
|
|
|
2016-10-10 10:24:03 +00:00
|
|
|
|
2016-10-11 12:05:59 +00:00
|
|
|
console.groupEnd();
|
2016-05-24 07:01:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-24 09:51:46 +00:00
|
|
|
inputPhoneMatrice.prototype.parseGrid = function(){
|
|
|
|
/* (1) On récupère la matrice des éléments de la grille */
|
|
|
|
var gridElements = $$('.matrice-panel input[data-name][value]');
|
|
|
|
for( var i in gridElements ){
|
|
|
|
if( !(gridElements[i] instanceof Element) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
var col = gridElements[i].getData('name');
|
|
|
|
var row = gridElements[i].value;
|
|
|
|
|
|
|
|
if( !(this.sGrid[col] instanceof Array) )
|
|
|
|
this.sGrid[col] = [];
|
|
|
|
|
|
|
|
this.sGrid[col][row] = gridElements[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|