Calcul du hash lors du `storageToFields` car c'est la qu'on verra s'il y a de "réelles" modifications par l'utilisateur + Vérification du hash lors de `fieldsToStorage` [FICHES+MINI-FICHES] + désactivation de la gestion du clonage qui bug
This commit is contained in:
parent
0e961f69b9
commit
a7db32ec6f
|
@ -65,8 +65,6 @@ inputPhoneFiche.prototype.fieldsToStorage = function(){
|
||||||
|
|
||||||
/* (4) On récupère et met en forme les valeurs du deflater */
|
/* (4) On récupère et met en forme les valeurs du deflater */
|
||||||
obj = {
|
obj = {
|
||||||
contact: parseInt(deflated.contact),
|
|
||||||
uid: parseInt(deflated.uid),
|
|
||||||
sexe: deflated.sexe,
|
sexe: deflated.sexe,
|
||||||
age: deflated.age,
|
age: deflated.age,
|
||||||
job: deflated.job,
|
job: deflated.job,
|
||||||
|
@ -83,7 +81,9 @@ inputPhoneFiche.prototype.fieldsToStorage = function(){
|
||||||
contextSpecial: deflated.contextSpecial,
|
contextSpecial: deflated.contextSpecial,
|
||||||
freq: deflated.freq,
|
freq: deflated.freq,
|
||||||
connect: deflated.connect,
|
connect: deflated.connect,
|
||||||
connectSpecial: deflated.connectSpecial
|
connectSpecial: deflated.connectSpecial,
|
||||||
|
uid: parseInt(deflated.uid),
|
||||||
|
contact: parseInt(deflated.contact)
|
||||||
};
|
};
|
||||||
|
|
||||||
/* (5) On calcule/compare le hash */
|
/* (5) On calcule/compare le hash */
|
||||||
|
@ -92,7 +92,7 @@ inputPhoneFiche.prototype.fieldsToStorage = function(){
|
||||||
hash = crc32( JSON.stringify(obj) );
|
hash = crc32( JSON.stringify(obj) );
|
||||||
|
|
||||||
// {5.2} Si le hash est identique, on ne fait rien //
|
// {5.2} Si le hash est identique, on ne fait rien //
|
||||||
if( existingData != null && existingData.hash != null && hash == existingData.hash )
|
if( existingData['hash'] != undefined && hash == existingData.hash )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// {5.3} On enregistre le hash //
|
// {5.3} On enregistre le hash //
|
||||||
|
@ -104,7 +104,7 @@ inputPhoneFiche.prototype.fieldsToStorage = function(){
|
||||||
|
|
||||||
/* (7) On met à jour le `timestamp` (car à ce point, on a une modification) */
|
/* (7) On met à jour le `timestamp` (car à ce point, on a une modification) */
|
||||||
obj.timestamp = Date.now();
|
obj.timestamp = Date.now();
|
||||||
console.warn('> FICHE UPDATE ('+(obj.timestamp-input_ts)+')');
|
console.warn('> FICHE UPDATE ('+(obj.timestamp-input_ts)+')', existingData, obj);
|
||||||
|
|
||||||
/* (8) On enregistre les données dans le 'localStorage' */
|
/* (8) On enregistre les données dans le 'localStorage' */
|
||||||
lsi.set('p_fiches', obj.uid, obj);
|
lsi.set('p_fiches', obj.uid, obj);
|
||||||
|
@ -318,9 +318,7 @@ inputPhoneFiche.prototype.storageToFields = function(){
|
||||||
/* (3) Pour chaque fiche */
|
/* (3) Pour chaque fiche */
|
||||||
for( var key in ficheData ){
|
for( var key in ficheData ){
|
||||||
|
|
||||||
// {3.1} Pour toutes les fiches //
|
// {3.1} On calcule/enregistre le hash (sans `timestamp`, `hash`, `valid`) //
|
||||||
|
|
||||||
// On enregistre le hash (sans `timestamp`, `hash`, `valid`)
|
|
||||||
clone = cloneObject( ficheData[key] );
|
clone = cloneObject( ficheData[key] );
|
||||||
delete clone['hash'];
|
delete clone['hash'];
|
||||||
delete clone['timestamp'];
|
delete clone['timestamp'];
|
||||||
|
@ -331,16 +329,13 @@ inputPhoneFiche.prototype.storageToFields = function(){
|
||||||
lsi.set('p_fiches', ficheData[key].uid, ficheData[key]);
|
lsi.set('p_fiches', ficheData[key].uid, ficheData[key]);
|
||||||
|
|
||||||
// {3.2} Pour la fiche à rendre graphiquement //
|
// {3.2} Pour la fiche à rendre graphiquement //
|
||||||
if( ficheData[key].uid == this.selected ){
|
if( ficheData[key].uid == this.selected )
|
||||||
|
|
||||||
this.add(ficheData[key]);
|
this.add(ficheData[key]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* (4) On met à jour la navigation */
|
||||||
// {4} On met à jour la navigation //
|
|
||||||
this.updateNavBar();
|
this.updateNavBar();
|
||||||
|
|
||||||
|
|
||||||
|
@ -403,7 +398,7 @@ inputPhoneFiche.prototype.sync = function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{ /* (3) Gestion des liens entre mini-fiches et fiches
|
if( false ){ /* (3) Gestion des liens entre mini-fiches et fiches
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
var originalContact, cloneContact,
|
var originalContact, cloneContact,
|
||||||
hasSameUsername, hasSameLink,
|
hasSameUsername, hasSameLink,
|
||||||
|
|
|
@ -5,6 +5,7 @@ function inputPhoneMini(container, navContainer){
|
||||||
this.nav_container = navContainer;
|
this.nav_container = navContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* [1] Attributs
|
/* [1] Attributs
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
inputPhoneMini.prototype = {
|
inputPhoneMini.prototype = {
|
||||||
|
@ -32,75 +33,60 @@ inputPhoneMini.prototype = {
|
||||||
inputPhoneMini.prototype.fieldsToStorage = function(){
|
inputPhoneMini.prototype.fieldsToStorage = function(){
|
||||||
console.group('[phone.mini] fields to storage');
|
console.group('[phone.mini] fields to storage');
|
||||||
|
|
||||||
// {1} Pour chaque formulaire de MINI fiche à l'écran //
|
var i, l, deflater, deflated, existingData, obj, hash;
|
||||||
|
|
||||||
|
/* (1) Pour chaque formulaire de MINI fiche à l'écran
|
||||||
|
---------------------------------------------------------*/
|
||||||
var existingMiniFiches = $$('[data-sublink="phone"] article.mini-relation-panel .mini-fiche-relation');
|
var existingMiniFiches = $$('[data-sublink="phone"] article.mini-relation-panel .mini-fiche-relation');
|
||||||
for( var i = 0 ; i < existingMiniFiches.length ; i++ ){
|
for( i = 0, l = existingMiniFiches.length ; i < l ; i++ ){
|
||||||
// {2} On initialise notre deflater pour récupérer les valeurs //
|
|
||||||
var deflater = new FormDeflater(existingMiniFiches[i], ['input', 'select'], ['data-name']);
|
|
||||||
|
|
||||||
// {3} On enregistre ce contact si le numéro n'est pas vide et soit pseudo/prénom/nom //
|
/* (1) On initialise notre deflater pour récupérer les valeurs */
|
||||||
var deflated = deflater.deflate();
|
deflater = new FormDeflater(existingMiniFiches[i], ['input', 'select'], ['data-name']);
|
||||||
// On crée le hash
|
|
||||||
var deflatedHash = crc32(JSON.stringify(deflated));
|
|
||||||
|
|
||||||
|
/* (2) On récupère les données */
|
||||||
|
deflated = deflater.deflate();
|
||||||
|
|
||||||
|
/* (3) On récupère les données du LSI si elles existent */
|
||||||
|
existingData = lsi.get('p_mini-fiches', deflated.uid);
|
||||||
|
|
||||||
|
// Si erreur, on passe à la fiche suivante
|
||||||
// {4} On récupère les données du LSI si elles existent //
|
|
||||||
var existingData = lsi.get('p_mini-fiches', deflated.uid);
|
|
||||||
|
|
||||||
// Si n'existe pas, on passe à la suivante
|
|
||||||
if( existingData === false )
|
if( existingData === false )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// {5} On récupère et met en forme les valeurs du deflater //
|
/* (4) On récupère et met en forme les valeurs du deflater */
|
||||||
// Si le hash est le même, on ne fait rien
|
obj = {
|
||||||
if( existingData != null && existingData.hash != null )
|
|
||||||
if( existingData.hash === 0 )
|
|
||||||
console.log('MINI#'+existingData.uid+' UPDATED BUT NO TIMESTAMP UPDATE');
|
|
||||||
else if( existingData.hash == deflatedHash )
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
var obj = {
|
|
||||||
uid: parseInt(deflated.uid),
|
|
||||||
contact: parseInt(deflated.uid),
|
contact: parseInt(deflated.uid),
|
||||||
sexe: deflated.sexe, // [0] Homme, [1] Femme, [2] Indéterminé
|
sexe: deflated.sexe,
|
||||||
age: deflated.age,
|
age: deflated.age,
|
||||||
studies: deflated.studies,
|
studies: deflated.studies,
|
||||||
reltype: deflated.reltype, // [0] ...
|
loc: deflated.loc,
|
||||||
|
reltype: deflated.reltype,
|
||||||
reltypeSpecial: deflated.reltypeSpecial,
|
reltypeSpecial: deflated.reltypeSpecial,
|
||||||
loc: deflated.loc, // [0] Choix 1 -> [3] Choix 4
|
|
||||||
unknown: deflated.unknown != null,
|
unknown: deflated.unknown != null,
|
||||||
hash: deflatedHash
|
uid: parseInt(deflated.uid)
|
||||||
};
|
};
|
||||||
|
|
||||||
/* (8) On vérifie la validité des données et on l'enregistre dans l'objet avec la date de modification */
|
/* (5) On calcule/compare le hash */
|
||||||
|
|
||||||
|
// {5.1} On calcule le hash //
|
||||||
|
hash = crc32( JSON.stringify(obj) );
|
||||||
|
|
||||||
|
// {5.2} Si le hash est identique, on ne fait rien //
|
||||||
|
if( existingData['hash'] != undefined && hash == existingData.hash )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// {5.3} On enregistre le hash //
|
||||||
|
obj.hash = hash;
|
||||||
|
|
||||||
|
|
||||||
|
/* (6) On calcule la validité des données */
|
||||||
obj.valid = this.check(obj);
|
obj.valid = this.check(obj);
|
||||||
|
|
||||||
// On met à jour la date de modification, si on a pas qu'@uid de différent
|
/* (7) On met à jour le `timestamp` (car à ce point, on a une modification) */
|
||||||
// {8.1} Si on doit mettre à jour //
|
|
||||||
if( existingData.hash !== 0 ){
|
|
||||||
|
|
||||||
// Si on a des modifications, on met à jour le `timestamp` //
|
|
||||||
if( diff(existingData, obj, ['hash', 'valid', 'timestamp']).length > 0 ){
|
|
||||||
console.log( diff(existingData, obj, ['hash', 'valid', 'timestamp']) );
|
|
||||||
|
|
||||||
obj.timestamp = Date.now();
|
obj.timestamp = Date.now();
|
||||||
console.warn('> MINI UPDATE ('+(obj.timestamp-input_ts)+')');
|
console.warn('> MINI UPDATE ('+(obj.timestamp-input_ts)+')');
|
||||||
|
|
||||||
}
|
/* (8) On enregistre les données dans le 'localStorage' */
|
||||||
|
|
||||||
if( existingData['timestamp'] == undefined || !isNaN(existingData.timestamp) )
|
|
||||||
obj.timestamp = Date.now();
|
|
||||||
|
|
||||||
// {6.2} Initialisation du `timestamp` si pas encore fait //
|
|
||||||
}else if( existingData['timestamp'] == undefined || !isNaN(existingData.timestamp) )
|
|
||||||
obj.timestamp = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/* (9) On enregistre les données dans le 'localStorage' */
|
|
||||||
console.warn('saving mini#'+obj.uid+' with timestamp of '+obj.timestam+' and hash of '+existingData.hash+' and now '+obj.hash);
|
|
||||||
lsi.set('p_mini-fiches', obj.uid, obj);
|
lsi.set('p_mini-fiches', obj.uid, obj);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,13 +96,6 @@ inputPhoneMini.prototype.fieldsToStorage = function(){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [3] Gestion de l'ajout physique d'un nouveau contact
|
/* [3] Gestion de l'ajout physique d'un nouveau contact
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/*
|
/*
|
||||||
|
@ -225,14 +204,6 @@ inputPhoneMini.prototype.add = function(objectData){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [4] Gestion de l'affichage depuis le 'localStorage'
|
/* [4] Gestion de l'affichage depuis le 'localStorage'
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
inputPhoneMini.prototype.storageToFields = function(){
|
inputPhoneMini.prototype.storageToFields = function(){
|
||||||
|
@ -240,44 +211,63 @@ inputPhoneMini.prototype.storageToFields = function(){
|
||||||
|
|
||||||
/* (1) On charge le contact selectionné
|
/* (1) On charge le contact selectionné
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
var miniData = lsi.get('p_mini-fiches', this.selected);
|
var miniData = lsi.export('p_mini-fiches');
|
||||||
|
var miniKeys = lsi.keys('p_mini-fiches');
|
||||||
|
var selectedMini = miniData[this.selected] != undefined ? miniData[this.selected] : null;
|
||||||
|
|
||||||
/* (2.1) Si on ne trouve pas
|
/* (2) Si aucune mini sélectionnée, on prend la première
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
if( miniData === null ){
|
if( selectedMini === null ){
|
||||||
|
|
||||||
/* (2.1.1) Si `selected` est pas encore défini
|
/* (2.1) Si `selected` n'est pas encore défini
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
if( this.selected === null ){
|
if( this.selected === null ){
|
||||||
|
|
||||||
var k = lsi.keys('p_mini-fiches');
|
/* (1) Si aucune mini, on quitte */
|
||||||
|
if( miniKeys.length == 0 )
|
||||||
/* (1) S'il y a au moins 1 contact -> on le prend */
|
|
||||||
if( k.length > 0 ){
|
|
||||||
this.selected = k[0];
|
|
||||||
return this.storageToFields();
|
|
||||||
|
|
||||||
/* (2) Sinon, on quitte */
|
|
||||||
}else
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
/* (2) Sinon, on prend la première */
|
||||||
|
this.selected = miniKeys[0];
|
||||||
|
return this.storageToFields();
|
||||||
|
|
||||||
/* (2.1.2) S'il est déja défini, on met à jour la nav
|
/* (2.2) S'il est déja défini, on met à jour la nav
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
}else{
|
}else{
|
||||||
this.updateNavBar();
|
this.updateNavBar();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (2.2) Si on trouve
|
/* (3) Affichage de la fiche sélectionnée
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
|
var clone, hash;
|
||||||
|
|
||||||
/* (1) On réinitialise le HTML */
|
/* (1) On réinitialise le HTML */
|
||||||
this.container.innerHTML = '';
|
this.container.innerHTML = '';
|
||||||
|
|
||||||
/* (2) On affiche la MINI fiche sélectionnée */
|
/* (2) Pour chaque mini */
|
||||||
this.add(miniData);
|
for( var key in miniData ){
|
||||||
|
|
||||||
|
// {3.1} On calcule/enregistre le hash (sans `timestamp`, `hash`, `valid`) //
|
||||||
|
clone = cloneObject( miniData[key] );
|
||||||
|
delete clone['hash'];
|
||||||
|
delete clone['timestamp'];
|
||||||
|
delete clone['valid'];
|
||||||
|
miniData[key].hash = crc32( JSON.stringify(clone) );
|
||||||
|
|
||||||
|
// On enregistre dans le `localStorage`
|
||||||
|
lsi.set('p_fiches', miniData[key].uid, miniData[key]);
|
||||||
|
|
||||||
|
// {2.2} Pour la fiche à rendre graphiquement //
|
||||||
|
if( miniData[key].uid == this.selected )
|
||||||
|
this.add(miniData[key]);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (3) On met à jour la navigation */
|
/* (3) On met à jour la navigation */
|
||||||
this.updateNavBar();
|
this.updateNavBar();
|
||||||
|
@ -287,15 +277,6 @@ inputPhoneMini.prototype.storageToFields = function(){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [5] Synchronisation des CONTACT vers les MINI fiches
|
/* [5] Synchronisation des CONTACT vers les MINI fiches
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
inputPhoneMini.prototype.sync = function(){
|
inputPhoneMini.prototype.sync = function(){
|
||||||
|
@ -353,19 +334,10 @@ inputPhoneMini.prototype.sync = function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.groupEnd();
|
console.groupEnd();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [6] Gestion de la navigation entre les fiches
|
/* [6] Gestion de la navigation entre les fiches
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
inputPhoneMini.prototype.nav = function(element){
|
inputPhoneMini.prototype.nav = function(element){
|
||||||
|
@ -387,11 +359,6 @@ inputPhoneMini.prototype.nav = function(element){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [7] Mise à jour de la navigation
|
/* [7] Mise à jour de la navigation
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
inputPhoneMini.prototype.updateNavBar = function(){
|
inputPhoneMini.prototype.updateNavBar = function(){
|
||||||
|
@ -437,8 +404,6 @@ inputPhoneMini.prototype.updateNavBar = function(){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [8] Vérification des données du formulaire
|
/* [8] Vérification des données du formulaire
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
inputPhoneMini.prototype.check = function(miniData){
|
inputPhoneMini.prototype.check = function(miniData){
|
||||||
|
@ -472,9 +437,6 @@ inputPhoneMini.prototype.check = function(miniData){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [9] Point d'amorçage de la gestion des contacts
|
/* [9] Point d'amorçage de la gestion des contacts
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
inputPhoneMini.prototype.attach = function(handler){
|
inputPhoneMini.prototype.attach = function(handler){
|
||||||
|
|
|
@ -1,23 +1,20 @@
|
||||||
function inputPhoneFiche(a,c){this.container=a;this.nav_container=c;this.top_size=10}inputPhoneFiche.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null,defaultData:{sexe:"2",age:".",job:".",famsit:"0",studies:"0",reltype:"0",reltypeSpecial:"",city:"",quartier:"",cp:"",loc:"0",duration:["",""],context:"0",contextSpecial:["","",""],freq:["4","9","14","19","24"],connect:"1 3 5 7 9 11".split(" "),connectSpecial:["",""],timestamp:0,valid:!1}};
|
function inputPhoneFiche(a,b){this.container=a;this.nav_container=b;this.top_size=10}inputPhoneFiche.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null,defaultData:{sexe:"2",age:".",job:".",famsit:"0",studies:"0",reltype:"0",reltypeSpecial:"",city:"",quartier:"",cp:"",loc:"0",duration:["",""],context:"0",contextSpecial:["","",""],freq:["4","9","14","19","24"],connect:"1 3 5 7 9 11".split(" "),connectSpecial:["",""],timestamp:0,valid:!1}};
|
||||||
inputPhoneFiche.prototype.fieldsToStorage=function(){console.group("[phone.fiche] fields to storage");var a,c,b,d,k,e=$$('[data-sublink="phone"] article.relation-panel .fiche-relation');a=0;for(c=e.length;a<c;a++)if(b=new FormDeflater(e[a],["input","select"],["data-name"]),d=b.deflate(),b=lsi.get("p_fiches",d.uid),!1!==b&&(d={contact:parseInt(d.contact),uid:parseInt(d.uid),sexe:d.sexe,age:d.age,job:d.job,famsit:d.famsit,studies:d.studies,reltype:d.reltype,reltypeSpecial:d.reltypeSpecial,city:d.city,
|
inputPhoneFiche.prototype.fieldsToStorage=function(){console.group("[phone.fiche] fields to storage");var a,b,c,d,e,f=$$('[data-sublink="phone"] article.relation-panel .fiche-relation');a=0;for(b=f.length;a<b;a++)if(c=new FormDeflater(f[a],["input","select"],["data-name"]),d=c.deflate(),c=lsi.get("p_fiches",d.uid),!1!==c&&(d={sexe:d.sexe,age:d.age,job:d.job,famsit:d.famsit,studies:d.studies,reltype:d.reltype,reltypeSpecial:d.reltypeSpecial,city:d.city,quartier:d.quartier,cp:d.cp,loc:d.loc,duration:d.duration,
|
||||||
quartier:d.quartier,cp:d.cp,loc:d.loc,duration:d.duration,context:d.context,contextSpecial:d.contextSpecial,freq:d.freq,connect:d.connect,connectSpecial:d.connectSpecial},k=crc32(JSON.stringify(d)),null==b||null==b.hash||k!=b.hash))d.hash=k,d.valid=this.check(d),d.timestamp=Date.now(),console.warn("> FICHE UPDATE ("+(d.timestamp-input_ts)+")"),lsi.set("p_fiches",d.uid,d);console.groupEnd()};
|
context:d.context,contextSpecial:d.contextSpecial,freq:d.freq,connect:d.connect,connectSpecial:d.connectSpecial,uid:parseInt(d.uid),contact:parseInt(d.contact)},e=crc32(JSON.stringify(d)),void 0==c.hash||e!=c.hash))d.hash=e,d.valid=this.check(d),d.timestamp=Date.now(),console.warn("> FICHE UPDATE ("+(d.timestamp-input_ts)+")",c,d),lsi.set("p_fiches",d.uid,d);console.groupEnd()};
|
||||||
inputPhoneFiche.prototype.add=function(a){if(null==a.uid||isNaN(a.uid)||null==a.contact||isNaN(a.contact))return!1;a.city=null!=a.city?a.city:this.defaultData.city;a.quartier=null!=a.quartier?a.quartier:this.defaultData.quartier;a.cp=null!=a.cp?a.cp:this.defaultData.cp;a.duration[0]=null!=a.duration[0]?a.duration[0]:this.defaultData.duration[0];a.duration[1]=null!=a.duration[1]?a.duration[1]:this.defaultData.duration[1];a.reltypeSpecial=null!=a.reltypeSpecial?a.reltypeSpecial:this.defaultData.reltypeSpecial;
|
inputPhoneFiche.prototype.add=function(a){if(null==a.uid||isNaN(a.uid)||null==a.contact||isNaN(a.contact))return!1;a.city=null!=a.city?a.city:this.defaultData.city;a.quartier=null!=a.quartier?a.quartier:this.defaultData.quartier;a.cp=null!=a.cp?a.cp:this.defaultData.cp;a.duration[0]=null!=a.duration[0]?a.duration[0]:this.defaultData.duration[0];a.duration[1]=null!=a.duration[1]?a.duration[1]:this.defaultData.duration[1];a.reltypeSpecial=null!=a.reltypeSpecial?a.reltypeSpecial:this.defaultData.reltypeSpecial;
|
||||||
a.contextSpecial[0]=null!=a.contextSpecial[0]?a.contextSpecial[0]:this.defaultData.contextSpecial[0];a.contextSpecial[1]=null!=a.contextSpecial[1]?a.contextSpecial[1]:this.defaultData.contextSpecial[1];a.contextSpecial[2]=null!=a.contextSpecial[2]?a.contextSpecial[2]:this.defaultData.contextSpecial[2];a.connectSpecial[0]=null!=a.connectSpecial[0]?a.connectSpecial[0]:this.defaultData.connectSpecial[0];a.connectSpecial[1]=null!=a.connectSpecial[1]?a.connectSpecial[1]:this.defaultData.connectSpecial[1];
|
a.contextSpecial[0]=null!=a.contextSpecial[0]?a.contextSpecial[0]:this.defaultData.contextSpecial[0];a.contextSpecial[1]=null!=a.contextSpecial[1]?a.contextSpecial[1]:this.defaultData.contextSpecial[1];a.contextSpecial[2]=null!=a.contextSpecial[2]?a.contextSpecial[2]:this.defaultData.contextSpecial[2];a.connectSpecial[0]=null!=a.connectSpecial[0]?a.connectSpecial[0]:this.defaultData.connectSpecial[0];a.connectSpecial[1]=null!=a.connectSpecial[1]?a.connectSpecial[1]:this.defaultData.connectSpecial[1];
|
||||||
a.job=null!=a.job?a.job:this.defaultData.job;a.studies=null!=a.studies?a.studies:this.defaultData.studies;a.age=null!=a.age?a.age:this.defaultData.age;a.sexe=null!=a.sexe?a.sexe:this.defaultData.sexe;a.famsit=null!=a.famsit?a.famsit:this.defaultData.famsit;a.reltype=null!=a.reltype?a.reltype:this.defaultData.reltype;a.loc=null!=a.loc?a.loc:this.defaultData.loc;a.context=null!=a.context?a.context:this.defaultData.context;a.freq=null!=a.freq?a.freq:this.defaultData.freq;a.connect=null!=a.connect?a.connect:
|
a.job=null!=a.job?a.job:this.defaultData.job;a.studies=null!=a.studies?a.studies:this.defaultData.studies;a.age=null!=a.age?a.age:this.defaultData.age;a.sexe=null!=a.sexe?a.sexe:this.defaultData.sexe;a.famsit=null!=a.famsit?a.famsit:this.defaultData.famsit;a.reltype=null!=a.reltype?a.reltype:this.defaultData.reltype;a.loc=null!=a.loc?a.loc:this.defaultData.loc;a.context=null!=a.context?a.context:this.defaultData.context;a.freq=null!=a.freq?a.freq:this.defaultData.freq;a.connect=null!=a.connect?a.connect:
|
||||||
this.defaultData.connect;var c=lsi.get("p_contacts",a.contact);if(!1===c)return!1;var b="";isNaN(c.existing)||(b=lsi.get("p_friends",c.existing),c.username=b.name,a.age=b.age,a.sexe=b.sexe,a.loc=b.dist,isNaN(b.reltype)?(a.reltype=10,a.reltypeSpecial=b.reltype):(a.reltype=b.reltype,a.reltypeSpecial=""),null!=b.studies2?(a.studies=b.studies2,a.job=b.job,a.famsit=b.famsit,a.city=b.city,a.cp=b.cp,a.quartier=b.quartier,a.duration[0]=b.duration[0],a.duration[1]=b.duration[1],a.context=b.context,a.contextSpecial=
|
this.defaultData.connect;var b=lsi.get("p_contacts",a.contact);if(!1===b)return!1;var c="";isNaN(b.existing)||(c=lsi.get("p_friends",b.existing),b.username=c.name,a.age=c.age,a.sexe=c.sexe,a.loc=c.dist,isNaN(c.reltype)?(a.reltype=10,a.reltypeSpecial=c.reltype):(a.reltype=c.reltype,a.reltypeSpecial=""),null!=c.studies2?(a.studies=c.studies2,a.job=c.job,a.famsit=c.famsit,a.city=c.city,a.cp=c.cp,a.quartier=c.quartier,a.duration[0]=c.duration[0],a.duration[1]=c.duration[1],a.context=c.context,a.contextSpecial=
|
||||||
b.contextExtra,a.connect=b.connect,a.connectSpecial=b.connectExtra,a.freq=b.freq,b="Contact import\u00e9: non modifiable!"):b="Contact import\u00e9 (incomplet): modifiable partiellement!");this.container.innerHTML+=pFicheBuilder.build({importedfiche:b,name:c.username,countcall:c.countcall,countsms:c.countsms,uid:a.uid,contact:a.contact,city:a.city,quartier:a.quartier,cp:a.cp,duration0:a.duration[0],duration1:a.duration[1],reltypespecial:a.reltypeSpecial,contextspecial0:a.contextSpecial[0],contextspecial1:a.contextSpecial[1],
|
c.contextExtra,a.connect=c.connect,a.connectSpecial=c.connectExtra,a.freq=c.freq,c="Contact import\u00e9: non modifiable!"):c="Contact import\u00e9 (incomplet): modifiable partiellement!");this.container.innerHTML+=pFicheBuilder.build({importedfiche:c,name:b.username,countcall:b.countcall,countsms:b.countsms,uid:a.uid,contact:a.contact,city:a.city,quartier:a.quartier,cp:a.cp,duration0:a.duration[0],duration1:a.duration[1],reltypespecial:a.reltypeSpecial,contextspecial0:a.contextSpecial[0],contextspecial1:a.contextSpecial[1],
|
||||||
contextspecial2:a.contextSpecial[2],connectspecial0:a.connectSpecial[0],connectspecial1:a.connectSpecial[1]});c=$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="job"]>option[value="'+a.job+'"]');null!=c&&c.setAttribute("selected","selected");c=$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="studies"]>option[value="'+a.studies+'"]');null!=c&&c.setAttribute("selected",
|
contextspecial2:a.contextSpecial[2],connectspecial0:a.connectSpecial[0],connectspecial1:a.connectSpecial[1]});b=$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="job"]>option[value="'+a.job+'"]');null!=b&&b.setAttribute("selected","selected");b=$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="studies"]>option[value="'+a.studies+'"]');null!=b&&b.setAttribute("selected",
|
||||||
"selected");c=$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="age"]>option[value="'+a.age+'"]');null!=c&&c.setAttribute("selected","selected");b=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]');for(c=0;c<b.length;c++)b[c].value==a.sexe?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked");b=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+
|
"selected");b=$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="age"]>option[value="'+a.age+'"]');null!=b&&b.setAttribute("selected","selected");c=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]');for(b=0;b<c.length;b++)c[b].value==a.sexe?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+
|
||||||
a.uid+'"] ~ h5>input[type="radio"][data-name="famsit"]');for(c=0;c<b.length;c++)b[c].value==a.famsit?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked");b=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="reltype"]');for(c=0;c<b.length;c++)b[c].value==a.reltype?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked");b=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+
|
a.uid+'"] ~ h5>input[type="radio"][data-name="famsit"]');for(b=0;b<c.length;b++)c[b].value==a.famsit?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="reltype"]');for(b=0;b<c.length;b++)c[b].value==a.reltype?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+
|
||||||
a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(c=0;c<b.length;c++)b[c].value==a.loc?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked");b=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="context"]');for(c=0;c<b.length;c++)b[c].value==a.context?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked");b=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+
|
a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(b=0;b<c.length;b++)c[b].value==a.loc?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="context"]');for(b=0;b<c.length;b++)c[b].value==a.context?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+
|
||||||
a.uid+'"] ~ h5>input[type="radio"][data-name="freq"]');for(c=0;c<b.length;c++)-1<a.freq.indexOf(b[c].value)?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked");b=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="connect"]');for(c=0;c<b.length;c++)-1<a.connect.indexOf(b[c].value)?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked")};
|
a.uid+'"] ~ h5>input[type="radio"][data-name="freq"]');for(b=0;b<c.length;b++)-1<a.freq.indexOf(c[b].value)?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('[data-sublink="phone"] article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="connect"]');for(b=0;b<c.length;b++)-1<a.connect.indexOf(c[b].value)?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked")};
|
||||||
inputPhoneFiche.prototype.storageToFields=function(){console.group("[phone.fiche] storage to fields");var a,c=lsi["export"]("p_fiches");this.container.innerHTML="";for(var b in c)a=cloneObject(c[b]),delete a.hash,delete a.timestamp,delete a.valid,c[b].hash=crc32(JSON.stringify(a)),lsi.set("p_fiches",c[b].uid,c[b]),c[b].uid==this.selected&&this.add(c[b]);this.updateNavBar();console.groupEnd()};
|
inputPhoneFiche.prototype.storageToFields=function(){console.group("[phone.fiche] storage to fields");var a,b=lsi["export"]("p_fiches");this.container.innerHTML="";for(var c in b)a=cloneObject(b[c]),delete a.hash,delete a.timestamp,delete a.valid,b[c].hash=crc32(JSON.stringify(a)),lsi.set("p_fiches",b[c].uid,b[c]),b[c].uid==this.selected&&this.add(b[c]);this.updateNavBar();console.groupEnd()};
|
||||||
inputPhoneFiche.prototype.sync=function(){console.group("[phone.fiche] synchronisation");var a=lsi["export"]("p_contacts"),c=[],b,d=lsi.keys("p_contacts").length<2*this.top_size?lsi.keys("p_contacts").length:2*this.top_size,k;for(k in a){for(ficheUid=0;-1<c.indexOf(ficheUid)&&ficheUid<d;)ficheUid++;c.push(ficheUid);a=lsi.get("p_fiches",ficheUid);!a&&(a=this.defaultData);a.uid=ficheUid;a.contact=parseInt(k);lsi.set("p_fiches",ficheUid,a);if(c.length>=d)break}var e,f,h,d={};k={};var a=lsi["export"]("p_fiches"),
|
inputPhoneFiche.prototype.sync=function(){console.group("[phone.fiche] synchronisation");var a=lsi["export"]("p_contacts"),b=[],c=lsi.keys("p_contacts").length<2*this.top_size?lsi.keys("p_contacts").length:2*this.top_size,d;for(d in a){for(ficheUid=0;-1<b.indexOf(ficheUid)&&ficheUid<c;)ficheUid++;b.push(ficheUid);a=lsi.get("p_fiches",ficheUid);!a&&(a=this.defaultData);a.uid=ficheUid;a.contact=parseInt(d);lsi.set("p_fiches",ficheUid,a);if(b.length>=c)break}console.groupEnd()};
|
||||||
c=lsi["export"]("p_mini-fiches"),l;for(l in a)if(e=lsi.get("p_contacts",a[l].contact),!(0<e.username.length&&void 0!=d[e.username]||0==e.username.length&&void 0!=k[e.existing])&&(0<e.username.length?d[e.username]=0:k[e.existing]=0,e)){var g=[["fiche",a[l]]];for(b in a)f=lsi.get("p_contacts",a[b].contact),b!=l&&f&&(h=0<f.username.length&&e.username===f.username,f=!isNaN(f.existing)&&e.existing===f.existing,(h||f)&&g.push(["fiche",a[b]]));for(b in c)f=lsi.get("p_contacts",c[b].contact),h=0<f.username.length&&
|
inputPhoneFiche.prototype.nav=function(a){if(!(a instanceof Element&&a.getData("n"))||isNaN(a.getData("n"))||"p_nav-fiche"!=a.parentNode.id)return!1;for(var b=$$('[data-sublink="phone"] #p_nav-fiche > span.active'),c=0;c<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.getData("n"))};
|
||||||
e.username===f.username,f=!isNaN(f.existing)&&e.existing===f.existing,(h||f)&&g.push(["mini",c[b]]);if(1!==g.length){h=[];for(b in g)h[b]=g[b][1].hasOwnProperty("timestamp")?g[b][1].timestamp:0;f=h.indexOf(Math.max.apply(Math,h));for(b in g)b!=f&&(g[b][0]==g[f][0]?(console.warn("copying fiche#"+g[f][1].uid+" to fiche#"+g[b][1].uid,h[f]-input_ts,h[b]-input_ts),e=cloneObject(g[f][1]),e.uid=g[b][1].uid,e.hash=0,lsi.set("p_fiches",e.uid,e)):"fiche"==g[f][0]?(console.warn("copying fiche#"+g[f][1].uid+
|
inputPhoneFiche.prototype.updateNavBar=function(){var a=lsi["export"]("p_fiches");this.nav_container.innerHTML="";for(var b=Object.keys(a),c=0;c<b.length;c++){var d=parseInt(b[c]);0==d&&(this.nav_container.innerHTML+="<span>APPELS</span>");20>d&&c<b.length-1&&20<=b[c+1]?this.nav_container.innerHTML+='<span data-n="'+d+'" class="lc">'+(d%20+1)+"</span> ":(20==d&&(this.nav_container.innerHTML+='<br><span class="fc"> SMS </span>'),this.nav_container.innerHTML+='<span data-n="'+
|
||||||
" to mini#"+g[b][1].uid,h[f]-input_ts,h[b]-input_ts),e=cloneObject(g[b][1]),e.age=g[f][1].age,e.sexe=g[f][1].sexe,e.loc=g[f][1].loc,e.reltype=g[f][1].reltype,e.reltypeSpecial=g[f][1].reltypeSpecial,e.hash=0,lsi.set("p_mini-fiches",e.uid,e)):(console.warn("copying mini#"+g[f][1].uid+" to fiche#"+g[b][1].uid,h[f]-input_ts,h[b]-input_ts),e=cloneObject(g[b][1]),e.age=g[f][1].age,e.sexe=g[f][1].sexe,e.loc=g[f][1].loc,e.reltype=g[f][1].reltype,e.reltypeSpecial=g[f][1].reltypeSpecial,e.hash=0,lsi.set("p_fiches",
|
d+'">'+(d%20+1)+"</span>")}for(var e in a)b=$('[data-sublink="phone"] #p_nav-fiche [data-n="'+a[e].uid+'"]'),null!=b&&(!0===a[e].valid?b.addClass("done"):b.remClass("done"));this.nav($('[data-sublink="phone"] #p_nav-fiche [data-n="'+this.selected+'"]'))};
|
||||||
e.uid,e)))}}console.groupEnd()};inputPhoneFiche.prototype.nav=function(a){if(!(a instanceof Element&&a.getData("n"))||isNaN(a.getData("n"))||"p_nav-fiche"!=a.parentNode.id)return!1;for(var c=$$('[data-sublink="phone"] #p_nav-fiche > span.active'),b=0;b<c.length;b++)c[b].remClass("active");a.addClass("active");this.selected=parseInt(a.getData("n"))};
|
inputPhoneFiche.prototype.check=function(a){if(2>a.city.length||isNaN(parseInt(a.duration[0]))&&0<a.duration[0].length||isNaN(parseInt(a.duration[1]))&&0<a.duration[1].length||0==a.duration[0].length+a.duration[1].length||"."==a.job||"."==a.studies||"."==a.age||""==a.sexe||""==a.famsit||""==a.reltype||""==a.loc||""==a.context)return!1;for(var b=0;b<a.freq.length;b++)if(""==a.freq[b])return!1;for(b=0;b<a.connect.length;b++)if(""==a.connect[b])return!1;return"10"==a.reltype&&2>a.reltypeSpecial.length||
|
||||||
inputPhoneFiche.prototype.updateNavBar=function(){var a=lsi["export"]("p_fiches");this.nav_container.innerHTML="";for(var c=Object.keys(a),b=0;b<c.length;b++){var d=parseInt(c[b]);0==d&&(this.nav_container.innerHTML+="<span>APPELS</span>");20>d&&b<c.length-1&&20<=c[b+1]?this.nav_container.innerHTML+='<span data-n="'+d+'" class="lc">'+(d%20+1)+"</span> ":(20==d&&(this.nav_container.innerHTML+='<br><span class="fc"> SMS </span>'),this.nav_container.innerHTML+='<span data-n="'+
|
|
||||||
d+'">'+(d%20+1)+"</span>")}for(var k in a)c=$('[data-sublink="phone"] #p_nav-fiche [data-n="'+a[k].uid+'"]'),null!=c&&(!0===a[k].valid?c.addClass("done"):c.remClass("done"));this.nav($('[data-sublink="phone"] #p_nav-fiche [data-n="'+this.selected+'"]'))};
|
|
||||||
inputPhoneFiche.prototype.check=function(a){if(2>a.city.length||isNaN(parseInt(a.duration[0]))&&0<a.duration[0].length||isNaN(parseInt(a.duration[1]))&&0<a.duration[1].length||0==a.duration[0].length+a.duration[1].length||"."==a.job||"."==a.studies||"."==a.age||""==a.sexe||""==a.famsit||""==a.reltype||""==a.loc||""==a.context)return!1;for(var c=0;c<a.freq.length;c++)if(""==a.freq[c])return!1;for(c=0;c<a.connect.length;c++)if(""==a.connect[c])return!1;return"10"==a.reltype&&2>a.reltypeSpecial.length||
|
|
||||||
"11"==a.context&&2>a.contextSpecial[0].length||"12"==a.context&&2>a.contextSpecial[1].length||"13"==a.context&&2>a.contextSpecial[2].length?!1:!0};inputPhoneFiche.prototype.attach=function(a){console.group("[phone.fiche] attaching events");lsi.createDataset("p_fiches");this.storageToFields();this.handler=a;this.nav_container.addEventListener("click",function(a){this.nav(a.target);this.handler(a.target)}.bind(this),!1);console.groupEnd()};
|
"11"==a.context&&2>a.contextSpecial[0].length||"12"==a.context&&2>a.contextSpecial[1].length||"13"==a.context&&2>a.contextSpecial[2].length?!1:!0};inputPhoneFiche.prototype.attach=function(a){console.group("[phone.fiche] attaching events");lsi.createDataset("p_fiches");this.storageToFields();this.handler=a;this.nav_container.addEventListener("click",function(a){this.nav(a.target);this.handler(a.target)}.bind(this),!1);console.groupEnd()};
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
function inputPhoneMini(a,c){this.container=a;this.nav_container=c}inputPhoneMini.prototype={container:this.container,nav_container:this.nav_container,selected:null,handler:null,defaultData:{contact:null,sexe:"2",age:".",studies:"0",loc:".",reltype:"9",reltypeSpecial:"",unknown:!1,timestamp:0,valid:!1}};
|
function inputPhoneMini(a,b){this.container=a;this.nav_container=b}inputPhoneMini.prototype={container:this.container,nav_container:this.nav_container,selected:null,handler:null,defaultData:{contact:null,sexe:"2",age:".",studies:"0",loc:".",reltype:"9",reltypeSpecial:"",unknown:!1,timestamp:0,valid:!1}};
|
||||||
inputPhoneMini.prototype.fieldsToStorage=function(){console.group("[phone.mini] fields to storage");for(var a=$$('[data-sublink="phone"] article.mini-relation-panel .mini-fiche-relation'),c=0;c<a.length;c++){var b=(new FormDeflater(a[c],["input","select"],["data-name"])).deflate(),e=crc32(JSON.stringify(b)),d=lsi.get("p_mini-fiches",b.uid);if(!1!==d){if(null!=d&&null!=d.hash)if(0===d.hash)console.log("MINI#"+d.uid+" UPDATED BUT NO TIMESTAMP UPDATE");else if(d.hash==e)return;b={uid:parseInt(b.uid),
|
inputPhoneMini.prototype.fieldsToStorage=function(){console.group("[phone.mini] fields to storage");var a,b,c,d,e,f=$$('[data-sublink="phone"] article.mini-relation-panel .mini-fiche-relation');a=0;for(b=f.length;a<b;a++)if(c=new FormDeflater(f[a],["input","select"],["data-name"]),d=c.deflate(),c=lsi.get("p_mini-fiches",d.uid),!1!==c&&(d={contact:parseInt(d.uid),sexe:d.sexe,age:d.age,studies:d.studies,loc:d.loc,reltype:d.reltype,reltypeSpecial:d.reltypeSpecial,unknown:null!=d.unknown,uid:parseInt(d.uid)},
|
||||||
contact:parseInt(b.uid),sexe:b.sexe,age:b.age,studies:b.studies,reltype:b.reltype,reltypeSpecial:b.reltypeSpecial,loc:b.loc,unknown:null!=b.unknown,hash:e};b.valid=this.check(b);0!==d.hash?(0<diff(d,b,["hash","valid","timestamp"]).length&&(console.log(diff(d,b,["hash","valid","timestamp"])),b.timestamp=Date.now(),console.warn("> MINI UPDATE ("+(b.timestamp-input_ts)+")")),void 0!=d.timestamp&&isNaN(d.timestamp)||(b.timestamp=Date.now())):void 0!=d.timestamp&&isNaN(d.timestamp)||(b.timestamp=0);console.warn("saving mini#"+
|
e=crc32(JSON.stringify(d)),void 0==c.hash||e!=c.hash))d.hash=e,d.valid=this.check(d),d.timestamp=Date.now(),console.warn("> MINI UPDATE ("+(d.timestamp-input_ts)+")"),lsi.set("p_mini-fiches",d.uid,d);console.groupEnd()};
|
||||||
b.uid+" with timestamp of "+b.timestam+" and hash of "+d.hash+" and now "+b.hash);lsi.set("p_mini-fiches",b.uid,b)}}console.groupEnd()};
|
inputPhoneMini.prototype.add=function(a){if(null==a||null==a.uid)return!1;a.age=null!=a.age?a.age:this.defaultData.age;a.sexe=null!=a.sexe?a.sexe:this.defaultData.sexe;a.studies=null!=a.studies?a.studies:this.defaultData.studies;a.reltype=null!=a.reltype?a.reltype:this.defaultData.reltype;a.reltypeSpecial=null!=a.reltypeSpecial?a.reltypeSpecial:this.defaultData.reltypeSpecial;a.loc=null!=a.loc?a.loc:this.defaultData.loc;a.unknown=null!=a.unknown?a.unknown:this.defaultData.unknown;var b=lsi.get("p_contacts",
|
||||||
inputPhoneMini.prototype.add=function(a){if(null==a||null==a.uid)return!1;a.age=null!=a.age?a.age:this.defaultData.age;a.sexe=null!=a.sexe?a.sexe:this.defaultData.sexe;a.studies=null!=a.studies?a.studies:this.defaultData.studies;a.reltype=null!=a.reltype?a.reltype:this.defaultData.reltype;a.reltypeSpecial=null!=a.reltypeSpecial?a.reltypeSpecial:this.defaultData.reltypeSpecial;a.loc=null!=a.loc?a.loc:this.defaultData.loc;a.unknown=null!=a.unknown?a.unknown:this.defaultData.unknown;var c=lsi.get("p_contacts",
|
a.uid);if(!1===b)return!1;if(!isNaN(b.existing)){var c=lsi.get("p_friends",b.existing);b.username=c.name;a.contact=b.uid;a.age=c.age;a.sexe=c.sexe;a.loc=c.dist;isNaN(c.reltype)?(a.reltype=10,a.reltypeSpecial=c.reltype):(a.reltype=c.reltype,a.reltypeSpecial="");null!=c.studies1&&(a.studies=c.studies1)}this.container.innerHTML+=pMiniFicheBuilder.build({name:b.username,countcall:b.countcall,countsms:b.countsms,uid:a.uid,reltypespecial:a.reltypeSpecial});b=$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+
|
||||||
a.uid);if(!1===c)return!1;if(!isNaN(c.existing)){var b=lsi.get("p_friends",c.existing);c.username=b.name;a.contact=c.uid;a.age=b.age;a.sexe=b.sexe;a.loc=b.dist;isNaN(b.reltype)?(a.reltype=10,a.reltypeSpecial=b.reltype):(a.reltype=b.reltype,a.reltypeSpecial="");null!=b.studies1&&(a.studies=b.studies1)}this.container.innerHTML+=pMiniFicheBuilder.build({name:c.username,countcall:c.countcall,countsms:c.countsms,uid:a.uid,reltypespecial:a.reltypeSpecial});c=$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+
|
a.uid+'"] ~ h5>span>select[data-name="studies"]>option[value="'+a.studies+'"]');null!=b&&b.setAttribute("selected","selected");b=$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="age"]>option[value="'+a.age+'"]');null!=b&&b.setAttribute("selected","selected");c=$$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]');for(b=0;b<c.length;b++)c[b].value==
|
||||||
a.uid+'"] ~ h5>span>select[data-name="studies"]>option[value="'+a.studies+'"]');null!=c&&c.setAttribute("selected","selected");c=$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="age"]>option[value="'+a.age+'"]');null!=c&&c.setAttribute("selected","selected");b=$$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]');for(c=0;c<b.length;c++)b[c].value==
|
a.sexe?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="reltype"]');for(b=0;b<c.length;b++)c[b].value==a.reltype?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(b=0;b<c.length;b++)c[b].value==
|
||||||
a.sexe?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked");b=$$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="reltype"]');for(c=0;c<b.length;c++)b[c].value==a.reltype?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked");b=$$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(c=0;c<b.length;c++)b[c].value==
|
a.loc?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");b=$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="checkbox"][data-name="unknown"]');null!=b&&a.unknown&&b.setAttribute("checked","checked")};
|
||||||
a.loc?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked");c=$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="checkbox"][data-name="unknown"]');null!=c&&a.unknown&&c.setAttribute("checked","checked")};
|
inputPhoneMini.prototype.storageToFields=function(){console.group("[phone.mini] storage to fields");var a=lsi["export"]("p_mini-fiches"),b=lsi.keys("p_mini-fiches");if(null===(void 0!=a[this.selected]?a[this.selected]:null)){if(null===this.selected){if(0==b.length)return!1;this.selected=b[0];return this.storageToFields()}this.updateNavBar();return!1}this.container.innerHTML="";for(var c in a)b=cloneObject(a[c]),delete b.hash,delete b.timestamp,delete b.valid,a[c].hash=crc32(JSON.stringify(b)),lsi.set("p_fiches",
|
||||||
inputPhoneMini.prototype.storageToFields=function(){console.group("[phone.mini] storage to fields");var a=lsi.get("p_mini-fiches",this.selected);if(null===a){if(null===this.selected)return a=lsi.keys("p_mini-fiches"),0<a.length?(this.selected=a[0],this.storageToFields()):!1;this.updateNavBar();return!1}this.container.innerHTML="";this.add(a);this.updateNavBar();console.groupEnd()};
|
a[c].uid,a[c]),a[c].uid==this.selected&&this.add(a[c]);this.updateNavBar();console.groupEnd()};
|
||||||
inputPhoneMini.prototype.sync=function(){console.group("[phone.mini] synchronisation");var a=lsi["export"]("p_contacts"),c;ficheIndexes=lsi.keys("p_fiches");for(c in ficheIndexes)delete a[ficheIndexes[c]];for(var b in a){var e=0==a[b].username.length?b.toString()+"-":b;c=lsi.get("p_mini-fiches",e);null==c&&(c=this.defaultData,c.contact=a[b].uid,c.valid=!1);c.uid=parseInt(b);lsi.set("p_mini-fiches",e,c)}c=lsi["export"]("p_mini-fiches");if(null==c[this.selected])for(b in c)if(!isNaN(b)){this.selected=
|
inputPhoneMini.prototype.sync=function(){console.group("[phone.mini] synchronisation");var a=lsi["export"]("p_contacts"),b;ficheIndexes=lsi.keys("p_fiches");for(b in ficheIndexes)delete a[ficheIndexes[b]];for(var c in a){var d=0==a[c].username.length?c.toString()+"-":c;b=lsi.get("p_mini-fiches",d);null==b&&(b=this.defaultData,b.contact=a[c].uid,b.valid=!1);b.uid=parseInt(c);lsi.set("p_mini-fiches",d,b)}b=lsi["export"]("p_mini-fiches");if(null==b[this.selected])for(c in b)if(!isNaN(c)){this.selected=
|
||||||
parseInt(b);break}console.groupEnd()};inputPhoneMini.prototype.nav=function(a){if(!(a instanceof Element&&a.getData("n"))||isNaN(a.getData("n"))||"p_nav-mini"!=a.parentNode.id)return!1;for(var c=$$('[data-sublink="phone"] #p_nav-mini > span.active'),b=0;b<c.length;b++)c[b].remClass("active");a.addClass("active");this.selected=parseInt(a.getData("n"))};
|
parseInt(c);break}console.groupEnd()};inputPhoneMini.prototype.nav=function(a){if(!(a instanceof Element&&a.getData("n"))||isNaN(a.getData("n"))||"p_nav-mini"!=a.parentNode.id)return!1;for(var b=$$('[data-sublink="phone"] #p_nav-mini > span.active'),c=0;c<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.getData("n"))};
|
||||||
inputPhoneMini.prototype.updateNavBar=function(){var a=lsi["export"]("p_mini-fiches");this.nav_container.innerHTML="";var c=0,b;for(b in a)isNaN(b)||(this.nav_container.innerHTML+='<span data-n="'+b+'">'+ ++c+"</span>");for(b in a)isNaN(b)||(c=$('[data-sublink="phone"] #p_nav-mini [data-n="'+a[b].uid+'"]'),null!=c&&(!0===a[b].valid?c.addClass("done"):c.remClass("done")));this.nav($('[data-sublink="phone"] #p_nav-mini [data-n="'+this.selected+'"]'))};
|
inputPhoneMini.prototype.updateNavBar=function(){var a=lsi["export"]("p_mini-fiches");this.nav_container.innerHTML="";var b=0,c;for(c in a)isNaN(c)||(this.nav_container.innerHTML+='<span data-n="'+c+'">'+ ++b+"</span>");for(c in a)isNaN(c)||(b=$('[data-sublink="phone"] #p_nav-mini [data-n="'+a[c].uid+'"]'),null!=b&&(!0===a[c].valid?b.addClass("done"):b.remClass("done")));this.nav($('[data-sublink="phone"] #p_nav-mini [data-n="'+this.selected+'"]'))};
|
||||||
inputPhoneMini.prototype.check=function(a){return a.unknown?!0:""==a.sexe||"."==a.studies||"."==a.age||""==a.loc||""==a.reltype||"10"==a.reltype&&2>a.reltypeSpecial.length?!1:!0};inputPhoneMini.prototype.attach=function(a){console.group("[phone.mini] attaching events");lsi.createDataset("p_mini-fiches");this.storageToFields();this.handler=a;this.nav_container.addEventListener("click",function(a){this.nav(a.target);this.handler(a.target)}.bind(this),!1);console.groupEnd()};
|
inputPhoneMini.prototype.check=function(a){return a.unknown?!0:""==a.sexe||"."==a.studies||"."==a.age||""==a.loc||""==a.reltype||"10"==a.reltype&&2>a.reltypeSpecial.length?!1:!0};inputPhoneMini.prototype.attach=function(a){console.group("[phone.mini] attaching events");lsi.createDataset("p_mini-fiches");this.storageToFields();this.handler=a;this.nav_container.addEventListener("click",function(a){this.nav(a.target);this.handler(a.target)}.bind(this),!1);console.groupEnd()};
|
||||||
|
|
Loading…
Reference in New Issue