diff --git a/js/includes/input-phone-fiche-min.js b/js/includes/input-phone-fiche-min.js index fa4986e..f1c56b0 100644 --- a/js/includes/input-phone-fiche-min.js +++ b/js/includes/input-phone-fiche-min.js @@ -2,8 +2,8 @@ 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}],loc2:[{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,loc2:c.loc2,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:f};c.valid=this.check(c);c.timestamp=Date.now(); +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,loc2:c.loc2,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.age=null!=a.age?a.age:this.defaultData.age;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? @@ -12,14 +12,14 @@ if(!1===b)return!1;this.container.innerHTML+=ficheBuilder.build({firstname:b.fir 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");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="loc2"]');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;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 b=lsi["export"]("mini-fiches"),d=lsi["export"]("fiches"),e;for(e in b)d[e].timestamp>b[e].timestamp?(b[e].sexe=d[e].sexe,b[e].age=d[e].age,b[e].studies=d[e].studies,b[e].loc=d[e].loc):(d[e].sexe=b[e].sexe,d[e].age=b[e].age,d[e].studies=b[e].studies,d[e].loc=b[e].loc),lsi.set("mini-fiches",e,b[e]),lsi.set("fiches",e,d[e]);for(e in d)b=lsi.get("contacts",d[e].contact),null!=b&&-1!=b.sms&&-1!=b.call&&(b=10>parseInt(e)?10+b.sms:b.call, -b=d[b],b.timestamp>=d[e].timestamp||(c=d[e],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 f in a)b=$('#nav-fiche [data-n="'+ -a[f].uid+'"]'),!0===a[f].valid?b.addClass("done"):b.remClass("done");this.nav($('#nav-fiche [data-n="'+this.selected+'"]'))}; +inputPhoneFiche.prototype.sync=function(){console.log("FICHE: SYNC");var a=lsi["export"]("contacts"),b=[],c;for(c in a){if(-1b.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 b=lsi["export"]("mini-fiches"),d=lsi["export"]("fiches"),f;for(f in d)c=d[f].contact,d[f].timestamp>b[c].timestamp?(b[c].sexe=d[f].sexe,b[c].age=d[f].age,b[c].studies=d[f].studies,b[c].loc=d[f].loc):(d[f].sexe=b[c].sexe,d[f].age=b[c].age,d[f].studies=b[c].studies,d[f].loc=b[c].loc),lsi.set("mini-fiches",f,b[f]),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+'"]'))}; inputPhoneFiche.prototype.check=function(a){if(isNaN(parseInt(a.age))||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 ba82fb0..7e7b03c 100644 --- a/js/includes/input-phone-fiche.js +++ b/js/includes/input-phone-fiche.js @@ -440,22 +440,24 @@ inputPhoneFiche.prototype.sync = function(){ /* (2) Pour chaque champ, on synchronise les MINI fiches avec les FICHES associées */ - for( var key in miniData ){ - var ficheModifiedLast = ficheData[key].timestamp > miniData[key].timestamp; + for( var key in ficheData ){ + var contactUid = ficheData[key].contact; + + var ficheModifiedLast = ficheData[key].timestamp > miniData[contactUid].timestamp; /* (3) Si la FICHE a été modifiée en dernier, on utilise ses données */ if( ficheModifiedLast ){ - miniData[key].sexe = ficheData[key].sexe; - miniData[key].age = ficheData[key].age; - miniData[key].studies = ficheData[key].studies; - miniData[key].loc = ficheData[key].loc; + miniData[contactUid].sexe = ficheData[key].sexe; + miniData[contactUid].age = ficheData[key].age; + miniData[contactUid].studies = ficheData[key].studies; + miniData[contactUid].loc = ficheData[key].loc; /* (4) Sinon, on utilise les données de la MINI */ }else{ - ficheData[key].sexe = miniData[key].sexe; - ficheData[key].age = miniData[key].age; - ficheData[key].studies = miniData[key].studies; - ficheData[key].loc = miniData[key].loc; + ficheData[key].sexe = miniData[contactUid].sexe; + ficheData[key].age = miniData[contactUid].age; + ficheData[key].studies = miniData[contactUid].studies; + ficheData[key].loc = miniData[contactUid].loc; } /* (5) On enregistre les modifications */