diff --git a/js/includes/input-phone-fiche-min.js b/js/includes/input-phone-fiche-min.js index 3dd3448..ea2cde4 100644 --- a/js/includes/input-phone-fiche-min.js +++ b/js/includes/input-phone-fiche-min.js @@ -1,24 +1,23 @@ function inputPhoneFiche(a,b){this.container=a;this.nav_container=b} -inputPhoneFiche.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null,defaultData:{sexe:[{status:!0},{status:!1}],age:".",job:".",famsit:[{status:!0},{status:!1},{status:!1}],studies:".",reltype:[{status:!0},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1}],reltypeSpecial:"",city:"",loc:[{status:!0},{status:!1},{status:!1},{status:!1}],duration:["",""],context:[{status:!0},{status:!1},{status:!1},{status:!1},{status:!1}, -{status:!1},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1}],contextSpecial:["","",""],freq:[[{status:!0},{status:!1},{status:!1},{status:!1}],[{status:!0},{status:!1},{status:!1},{status:!1}],[{status:!0},{status:!1},{status:!1},{status:!1}],[{status:!0},{status:!1},{status:!1},{status:!1}],[{status:!0},{status:!1},{status:!1},{status:!1}]],connect:[[{status:!1},{status:!0}],[{status:!1},{status:!0}],[{status:!1},{status:!0}],[{status:!1},{status:!0}], -[{status:!1},{status:!0}],[{status:!1},{status:!0}]],connectSpecial:["",""],timestamp:0,valid:!1}}; -inputPhoneFiche.prototype.fieldsToStorage=function(){console.log("FICHE: FIELDS TO STORAGE");for(var a=$$("article.relation-panel .fiche-relation"),b=0;b FICHE UPDATE");c={contact:c.contact.value,uid:c.uid.value,sexe:c.sexe,age:c.age.value,job:c.job.value,famsit:c.famsit,studies:c.studies.value, -reltype:c.reltype,reltypeSpecial:c.reltypeSpecial.value,city:c.city.value,loc:c.loc,duration:[c.duration[0].value,c.duration[1].value],context:c.context,contextSpecial:[c.contextSpecial[0].value,c.contextSpecial[1].value,c.contextSpecial[2].value],freq:[c.freq0,c.freq1,c.freq2,c.freq3,c.freq4],connect:[c.connect0,c.connect1,c.connect2,c.connect3,c.connect4,c.connect5],connectSpecial:[c.connectSpecial[0].value,c.connectSpecial[1].value],hash:e};c.valid=this.check(c);c.timestamp=Date.now();lsi.set("fiches", -c.uid,c)}}}; -inputPhoneFiche.prototype.add=function(a){console.log("FICHE: ADD");if(null==a.uid||null==a.contact)return!1;a.city=null!=a.city?a.city:this.defaultData.city;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.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 b=lsi.get("contacts",a.contact);if(!1===b)return!1;this.container.innerHTML+=ficheBuilder.build({firstname:b.firstname, -lastname:b.lastname,username:0==b.username.length?"":"("+b.username+")",countcall:b.countcall,countsms:b.countsms,uid:a.uid,contact:a.contact,city:a.city,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]});b=$('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=$('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");b=$('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");for(var c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'), -b=0;binput[type="radio"][data-name="famsit"]');for(b=0;binput[type="radio"][data-name="reltype"]');for(b=0;b< -c.length&&binput[type="radio"][data-name="loc"]');for(b=0;binput[type="radio"][data-name="context"]');for(b=0;binput[type="radio"][data-name="freq'+c+'"]'),b=0;binput[type="radio"][data-name="connect'+c+'"]'),b=0;bb.length)for(c in a){for(a=0;-1a;)a++;b.push(a);d=lsi.get("fiches",a);null==d&&(d=this.defaultData); -d.uid=a;d.contact=c;lsi.set("fiches",a,d);if(20<=b.length)break}var d=lsi["export"]("fiches"),f;for(f in d)miniData=lsi.get("mini-fiches",d[f].contact),d[f].timestamp>=miniData.timestamp?(miniData.sexe=d[f].sexe,miniData.age=d[f].age,miniData.studies=d[f].studies,miniData.loc=d[f].loc,miniData.reltype=d[f].reltype,miniData.reltypeSpecial=d[f].reltypeSpecial):(d[f].sexe=miniData.sexe,d[f].age=miniData.age,d[f].studies=miniData.studies,d[f].loc=miniData.loc,d[f].reltype=miniData.reltype,d[f].reltypeSpecial= -miniData.reltypeSpecial),lsi.set("mini-fiches",d[f].contact,miniData),lsi.set("fiches",f,d[f]);for(f in d)b=lsi.get("contacts",d[f].contact),null!=b&&-1!=b.sms&&-1!=b.call&&(b=10>parseInt(f)?10+b.sms:b.call,b=d[b],b.timestamp>=d[f].timestamp||(c=d[f],c.uid=b.uid,lsi.set("fiches",b.uid,c)))}; +inputPhoneFiche.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null,defaultData:{sexe:[defTrue,defFalse],age:".",job:".",famsit:[defTrue,defFalse,defFalse],studies:".",reltype:[defTrue,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse],reltypeSpecial:"",city:"",loc:[defTrue,defFalse,defFalse,defFalse],duration:["",""],context:[defTrue,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse, +defFalse],contextSpecial:["","",""],freq:[[defTrue,defFalse,defFalse,defFalse],[defTrue,defFalse,defFalse,defFalse],[defTrue,defFalse,defFalse,defFalse],[defTrue,defFalse,defFalse,defFalse],[defTrue,defFalse,defFalse,defFalse]],connect:[[defFalse,defTrue],[defFalse,defTrue],[defFalse,defTrue],[defFalse,defTrue],[defFalse,defTrue],[defFalse,defTrue]],connectSpecial:["",""],timestamp:0,valid:!1}}; +inputPhoneFiche.prototype.fieldsToStorage=function(){console.log("FICHE: FIELDS TO STORAGE");for(var a=$$("article.relation-panel .fiche-relation"),b=0;b FICHE UPDATE"), +c.timestamp=Date.now());lsi.set("fiches",c.uid,c)}}}; +inputPhoneFiche.prototype.add=function(a){console.log("FICHE: ADD");if(null==a.uid||null==a.contact)return!1;a.city=null!=a.city?a.city:this.defaultData.city;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.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 b=lsi.get("contacts",a.contact);if(!1===b)return!1;this.container.innerHTML+= +ficheBuilder.build({firstname:b.firstname,lastname:b.lastname,username:0==b.username.length?"":"("+b.username+")",countcall:b.countcall,countsms:b.countsms,uid:a.uid,contact:a.contact,city:a.city,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]});b=$('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=$('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");b=$('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");for(var c=$$('article.fiche-relation input[data-name="uid"][value="'+ +a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'),b=0;binput[type="radio"][data-name="famsit"]');for(b=0;binput[type="radio"][data-name="reltype"]'); +for(b=0;binput[type="radio"][data-name="loc"]');for(b=0;binput[type="radio"][data-name="context"]');for(b=0;b< +c.length&&binput[type="radio"][data-name="freq'+c+'"]'),b=0;binput[type="radio"][data-name="connect'+c+'"]'),b=0;bb.length)for(c in a){for(a=0;-1a;)a++;b.push(a);d=lsi.get("fiches", +a);null==d&&(d=this.defaultData);d.uid=a;d.contact=c;lsi.set("fiches",a,d);if(20<=b.length)break}var d=lsi["export"]("fiches"),f;for(f in d)miniData=lsi.get("mini-fiches",d[f].contact),d[f].timestamp>=miniData.timestamp?(miniData.sexe=d[f].sexe,miniData.age=d[f].age,miniData.studies=d[f].studies,miniData.loc=d[f].loc,miniData.reltype=d[f].reltype,miniData.reltypeSpecial=d[f].reltypeSpecial):(d[f].sexe=miniData.sexe,d[f].age=miniData.age,d[f].studies=miniData.studies,d[f].loc=miniData.loc,d[f].reltype= +miniData.reltype,d[f].reltypeSpecial=miniData.reltypeSpecial),lsi.set("mini-fiches",d[f].contact,miniData),lsi.set("fiches",f,d[f]);for(f in d)b=lsi.get("contacts",d[f].contact),null!=b&&-1!=b.sms&&-1!=b.call&&(b=10>parseInt(f)?10+b.sms:b.call,b=d[b],b.timestamp>=d[f].timestamp||(c=d[f],c.uid=b.uid,lsi.set("fiches",b.uid,c)))}; inputPhoneFiche.prototype.nav=function(a){if(null==a||!1===a.getData("n")||isNaN(a.getData("n"))||"nav-fiche"!=a.parentNode.id)return!1;for(var b=$$("#nav-fiche > span.active"),c=0;cAPPELS";for(var c=0;c'+(c%10+1)+"  ":(10==c&&(this.nav_container.innerHTML+='SMS'),this.nav_container.innerHTML+=''+(c%10+1)+"")}for(var e in a)b=$('#nav-fiche [data-n="'+ -a[e].uid+'"]'),!0===a[e].valid?b.addClass("done"):b.remClass("done");this.nav($('#nav-fiche [data-n="'+this.selected+'"]'))}; +a[e].uid+'"]'),null!=b&&(!0===a[e].valid?b.addClass("done"):b.remClass("done"));this.nav($('#nav-fiche [data-n="'+this.selected+'"]'))}; inputPhoneFiche.prototype.check=function(a){if(2>a.city.length||isNaN(parseInt(a.duration[0]))&&0a.reltypeSpecial.length||a.context[11].status&&2>a.contextSpecial[0].length||a.context[12].status&&2>a.contextSpecial[1].length||a.context[13].status&&2>a.contextSpecial[2].length?!1:!0};inputPhoneFiche.prototype.attach=function(a){console.log("FICHE: ATTACH");lsi.createDataset("fiches");this.storageToFields();this.handler=a;var b=this,b=this;this.nav_container.addEventListener("click",function(a){b.nav(a.target);b.handler(a.target)},!1)}; diff --git a/js/includes/input-phone-fiche.js b/js/includes/input-phone-fiche.js index f6ea8a0..29221fa 100644 --- a/js/includes/input-phone-fiche.js +++ b/js/includes/input-phone-fiche.js @@ -13,34 +13,34 @@ inputPhoneFiche.prototype = { selected: 0, // UID de la FICHE sélectionnée handler: null, // Fonction pour l'enregistrement et la synchronisation des données defaultData: { // Valeurs par défaut - sexe: [ {status:true}, {status:false}], + sexe: [ defTrue, defFalse], age: '.', job: '.', - famsit: [ {status:true}, {status:false}, {status:false} ], // Choix 1 à 3 + famsit: [ defTrue, defFalse, defFalse ], // Choix 1 à 3 studies: '.', - reltype: [ {status:true}, {status:false}, {status:false}, {status:false}, {status:false}, - {status:false}, {status:false}, {status:false}, {status:false}], // Choix 1 à 9 + reltype: [ defTrue, defFalse, defFalse, defFalse, defFalse, + defFalse, defFalse, defFalse, defFalse], // Choix 1 à 9 reltypeSpecial: '', city: '', - loc: [ {status:true}, {status:false}, {status:false}, {status:false} ], + loc: [ defTrue, defFalse, defFalse, defFalse ], duration: ['', ''], - context: [ {status:true}, {status:false}, {status:false}, {status:false}, {status:false}, - {status:false}, {status:false}, {status:false}, {status:false}, {status:false}, - {status:false}, {status:false}, {status:false}, {status:false}], // Choix 1 à 14 + context: [ defTrue, defFalse, defFalse, defFalse, defFalse, + defFalse, defFalse, defFalse, defFalse, defFalse, + defFalse, defFalse, defFalse, defFalse], // Choix 1 à 14 contextSpecial: ['', '', ''], freq: [ - [ {status:true}, {status:false}, {status:false}, {status:false} ], - [ {status:true}, {status:false}, {status:false}, {status:false} ], - [ {status:true}, {status:false}, {status:false}, {status:false} ], - [ {status:true}, {status:false}, {status:false}, {status:false} ], - [ {status:true}, {status:false}, {status:false}, {status:false} ]], + [ defTrue, defFalse, defFalse, defFalse ], + [ defTrue, defFalse, defFalse, defFalse ], + [ defTrue, defFalse, defFalse, defFalse ], + [ defTrue, defFalse, defFalse, defFalse ], + [ defTrue, defFalse, defFalse, defFalse ]], connect: [ - [ {status:false}, {status:true} ], - [ {status:false}, {status:true} ], - [ {status:false}, {status:true} ], - [ {status:false}, {status:true} ], - [ {status:false}, {status:true} ], - [ {status:false}, {status:true} ]], + [ defFalse, defTrue ], + [ defFalse, defTrue ], + [ defFalse, defTrue ], + [ defFalse, defTrue ], + [ defFalse, defTrue ], + [ defFalse, defTrue ]], connectSpecial: ['', ''], timestamp: 0, valid: false @@ -82,12 +82,10 @@ inputPhoneFiche.prototype.fieldsToStorage = function(){ if( existingData.hash != null && existingData.hash == deflatedHash ) return; - console.warn('> FICHE UPDATE'); - var obj = { - contact: deflated.contact.value, - uid: deflated.uid.value, + contact: parseInt(deflated.contact.value), + uid: parseInt(deflated.uid.value), sexe: deflated.sexe, // Choix 1 à 2 age: deflated.age.value, job: deflated.job.value, @@ -131,8 +129,13 @@ inputPhoneFiche.prototype.fieldsToStorage = function(){ /* (6) On vérifie la validité des données et on l'enregistre dans l'objet avec la date de modification */ - obj.valid = this.check(obj); - obj.timestamp = Date.now(); + obj.valid = this.check(obj); + + // On met à jour la date de modification, si on a pas qu'@uid de différent + if( diff(existingData, obj).length > 0 ){ + console.warn('> FICHE UPDATE'); + obj.timestamp = Date.now(); + } /* (7) On enregistre les données dans le 'localStorage' */ lsi.set('fiches', obj.uid, obj); @@ -360,7 +363,7 @@ inputPhoneFiche.prototype.sync = function(){ // On met à jour la fiche ET on l'enregistre ficheData.uid = ficheIndex; - ficheData.contact = uid; + ficheData.contact = parseInt(uid); lsi.set('fiches', ficheIndex, ficheData); } @@ -380,7 +383,7 @@ inputPhoneFiche.prototype.sync = function(){ // On met à jour la fiche ET on l'enregistre ficheData.uid = ficheIndex; - ficheData.contact = uid; + ficheData.contact = parseInt(uid); lsi.set('fiches', ficheIndex, ficheData); @@ -568,6 +571,8 @@ inputPhoneFiche.prototype.updateNavBar = function(){ var currentElement = $('#nav-fiche [data-n="'+ficheData[key].uid+'"]'); + if( currentElement == null ) + continue; // Si on ne trouve pas le bouton diff --git a/js/includes/input-phone-mini-min.js b/js/includes/input-phone-mini-min.js index 0700423..22a2f0f 100644 --- a/js/includes/input-phone-mini-min.js +++ b/js/includes/input-phone-mini-min.js @@ -1,10 +1,10 @@ -function inputPhoneMini(a,b){this.container=a;this.nav_container=b}inputPhoneMini.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null,defaultData:{sexe:[{status:!0},{status:!1}],age:".",studies:".",loc:[{status:!0},{status:!1},{status:!1},{status:!1}],reltype:[{status:!0},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1},{status:!1}],reltypeSpecial:"",timestamp:0,valid:!1}}; -inputPhoneMini.prototype.fieldsToStorage=function(){console.log("MINI FICHE: FIELDS TO STORAGE");for(var a=$$("article.mini-relation-panel .mini-fiche-relation"),b=0;b MINI UPDATE");c={uid:c.uid.value,firstname:d.firstname,lastname:d.lastname,username:d.username,sexe:c.sexe,age:c.age.value, -studies:c.studies.value,reltype:c.reltype,reltypeSpecial:c.reltypeSpecial.value,loc:c.loc,hash:e};c.valid=this.check(c);c.timestamp=Date.now();lsi.set("mini-fiches",c.uid,c)}}}; +function inputPhoneMini(a,b){this.container=a;this.nav_container=b}inputPhoneMini.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null,defaultData:{sexe:[defTrue,defFalse],age:".",studies:".",loc:[defTrue,defFalse,defFalse,defFalse],reltype:[defTrue,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse,defFalse],reltypeSpecial:"",timestamp:0,valid:!1}}; +inputPhoneMini.prototype.fieldsToStorage=function(){console.log("MINI FICHE: FIELDS TO STORAGE");for(var a=$$("article.mini-relation-panel .mini-fiche-relation"),b=0;b MINI UPDATE");c={uid:parseInt(c.uid.value),firstname:d.firstname,lastname:d.lastname,username:d.username,sexe:c.sexe,age:c.age.value, +studies:c.studies.value,reltype:c.reltype,reltypeSpecial:c.reltypeSpecial.value,loc:c.loc,hash:e};c.valid=this.check(c);0 FICHE UPDATE"),c.timestamp=Date.now());lsi.set("mini-fiches",c.uid,c)}}}; inputPhoneMini.prototype.add=function(a){console.log("MINI FICHE: ADD");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;var b=lsi.get("contacts",a.uid);if(!1===b)return!1; this.container.innerHTML+=miniFicheBuilder.build({firstname:b.firstname,lastname:b.lastname,username:0==b.username.length?"":"("+b.username+")",countcall:b.countcall,countsms:b.countsms,uid:a.uid,reltypespecial:a.reltypeSpecial});b=$('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=$('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");for(var c=$$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'),b=0;binput[type="radio"][data-name="reltype"]');for(b=0;binput[type="radio"][data-name="loc"]');for(b=0;b span.active"),c=0;c'+(c+1)+""}for(var e in a)b=$('#nav-mini [data-n="'+a[e].uid+'"]'),!0===a[e].valid?b.addClass("done"):b.remClass("done");this.nav($('#nav-mini [data-n="'+this.selected+'"]'))}; +inputPhoneMini.prototype.updateNavBar=function(){var a=lsi["export"]("mini-fiches"),b=Object.keys(a).length;if($$("#nav-mini [data-n]").length!=b){this.nav_container.innerHTML="";for(var c=0;c'+(c+1)+""}for(var e in a)b=$('#nav-mini [data-n="'+a[e].uid+'"]'),null!=b&&(!0===a[e].valid?b.addClass("done"):b.remClass("done"));this.nav($('#nav-mini [data-n="'+this.selected+'"]'))}; inputPhoneMini.prototype.check=function(a){return!checkRadioValue(a.sexe)||"."==a.studies||"."==a.age||!checkRadioValue(a.loc)||!checkRadioValue(a.reltype)||a.reltype[8].status&&2>a.reltypeSpecial.length?!1:!0};inputPhoneMini.prototype.attach=function(a){console.log("MINI FICHE: ATTACH");lsi.createDataset("mini-fiches");this.storageToFields();this.handler=a;var b=this;this.nav_container.addEventListener("click",function(a){b.nav(a.target);b.handler(a.target)},!1)}; diff --git a/js/includes/input-phone-mini.js b/js/includes/input-phone-mini.js index 79f64c4..64fc97e 100644 --- a/js/includes/input-phone-mini.js +++ b/js/includes/input-phone-mini.js @@ -13,12 +13,12 @@ inputPhoneMini.prototype = { selected: 0, // UID de la MINI fiche sélectionnée handler: null, // Fonction pour l'enregistrement et la synchronisation des données defaultData: { // Valeur par défaut - sexe: [{status:true}, {status:false}], + sexe: [defTrue, defFalse], age: '.', studies: '.', - loc: [{status:true}, {status:false}, {status:false}, {status:false}], - reltype: [ {status:true}, {status:false}, {status:false}, {status:false}, {status:false}, - {status:false}, {status:false}, {status:false}, {status:false}], // Choix 1 à 9 + loc: [defTrue, defFalse, defFalse, defFalse], + reltype: [ defTrue, defFalse, defFalse, defFalse, defFalse, + defFalse, defFalse, defFalse, defFalse], // Choix 1 à 9 reltypeSpecial: '', timestamp: 0, valid: false @@ -63,7 +63,7 @@ inputPhoneMini.prototype.fieldsToStorage = function(){ var obj = { - uid: deflated.uid.value, + uid: parseInt(deflated.uid.value), firstname: existingData.firstname, lastname: existingData.lastname, username: existingData.username, @@ -78,7 +78,12 @@ inputPhoneMini.prototype.fieldsToStorage = function(){ /* (8) On vérifie la validité des données et on l'enregistre dans l'objet avec la date de modification */ obj.valid = this.check(obj); - obj.timestamp = Date.now(); + + // On met à jour la date de modification, si on a pas qu'@uid de différent + if( diff(existingData, obj).length > 0 ){ + console.warn('> FICHE UPDATE'); + obj.timestamp = Date.now(); + } /* (9) On enregistre les données dans le 'localStorage' */ @@ -294,6 +299,9 @@ inputPhoneMini.prototype.updateNavBar = function(){ var currentElement = $('#nav-mini [data-n="'+miniData[key].uid+'"]'); + if( currentElement == null ) + continue; + // On remplit avec le numéro de la MINI fiche // currentElement.setAttribute('data-n', miniData[key].uid); // currentElement.innerHTML = miniData[key].uid + 1; diff --git a/js/lib/reset-min.js b/js/lib/reset-min.js index cd66fc3..6f1db48 100644 --- a/js/lib/reset-min.js +++ b/js/lib/reset-min.js @@ -1,4 +1,4 @@ function $(a){return document.querySelector(a)}function $$(a){return document.querySelectorAll(a)}Element.prototype.getData=function(a){return"undefined"==typeof this.dataset?!1:this.dataset.hasOwnProperty(a)?this.dataset[a]:!1};Element.prototype.addClass=function(a){var b=this.className.split(" ");-1 EXCLUSION, SIN +/* RETOURNE LES CLÉS N'AYANT PAS UNE VALEUR EGALE POUR 2 OBJETS +* +* @A Premier Objet +* @B Second Objet +* +* @return diff Tableau contenant les clés des valeurs différentes (uniquement les clés communes et non NULLes) +* +*/ +function diff(A, B){ + var dKeys = []; + + for( var key in A ){ + // Si A[key] ou B[key] est NULL, on ne compare pas + if( B[key] == null || A[key] == null ) + continue; + + + /* (1) On vérifie le type */ + if( typeof A[key] !== typeof B[key] ) + dKeys.push(key); + + /* (2) Vérification récursive si 2 objets */ + else if( A[key] instanceof Object && B[key] instanceof Object ){ + // Si au moins 1 différence profonde (récursive), on ajoute la clé + if( diff(A[key], B[key]).length > 0 ) + dKeys.push(key); + + /* (3) Vérification superficielle (types non composés) */ + }else if( A[key] != B[key] ) + dKeys.push(key); + + } + + return dKeys; +} + + + /* DEFINITION DES FORMATS UTILES POUR INPUT-CHECKER * diff --git a/view/js/input-min.js b/view/js/input-min.js index 15a0b98..418b19f 100644 --- a/view/js/input-min.js +++ b/view/js/input-min.js @@ -1,4 +1,4 @@ -var clearAllButton=$("#clear-all"),submitAllButton=$("#submit-all"),importCallLog=$('input#call_log-import[type="file"]'),subjectManager,contactManager,miniManager,ficheManager; +var clearAllButton=$("#clear-all"),submitAllButton=$("#submit-all"),importCallLog=$('input#call_log-import[type="file"]'),subjectManager,contactManager,miniManager,ficheManager,defTrue={status:!0,value:"on"},defFalse={status:!1,value:"on"}; function dynamicUpdate(a){var b=a instanceof Element,e=b&&"SPAN"==a.tagName&&"switch-left"==a.className,f=b&&"SPAN"==a.tagName&&"switch-both"==a.className,c=b&&"INPUT"==a.tagName&&"submit"==a.type,d=b&&"SPAN"==a.tagName&&("nav-mini"==a.parentNode.id||"nav-fiche"==a.parentNode.id),b=b&&"SPAN"==a.tagName&&"nav-contact"==a.parentNode.id;if(!(f||e||c||d||b)&&!0!==a)return!1;if(f)console.log("> switch firstname <-> lastname"),e=a.parentNode,a=e.children[8],e=e.children[10],f=a.value,a.value=e.value,e.value= f;else if(e){console.log("> switch firstname+lastname -> username");e=a.parentNode;f=e.children[6];a=e.children[8];e=e.children[10];if(0 dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),(c||b)&&contactManager.storageToFields()} function checkRadioValue(a){for(var b=0,e=0;e