Gestion de la création des `mini` sans les contacts déja dans les `fiches` (import+manuel)

This commit is contained in:
xdrm-brackets 2016-05-11 19:34:52 +02:00
parent a6b20cb198
commit e2af89c7d7
8 changed files with 53 additions and 74 deletions

View File

@ -1,6 +1,6 @@
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:"H",age:".",job:".",famsit:"0",studies:".",reltype:"0",reltypeSpecial:"",city:"",cp:"",loc:"0",duration:["",""],context:"0",contextSpecial:["","",""],freq:["0","4","8","12","16"],connect:"1 3 5 7 9 11".split(" "),connectSpecial:["",""],timestamp:0,valid:!1}}; 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:"H",age:".",job:".",famsit:"0",studies:".",reltype:"0",reltypeSpecial:"",city:"",cp:"",loc:"0",duration:["",""],context:"0",contextSpecial:["","",""],freq:["0","4","8","12","16"],connect:"1 3 5 7 9 11".split(" "),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<a.length;b++){var c=(new FormDeflater(a[b],["input","select"],["data-name"])).deflate(),f=crc32(JSON.stringify(c)),d=lsi.get("fiches",c.uid);if(!1!==d){if(null!=d.hash&&d.hash==f)break;c={contact:parseInt(c.contact),uid:parseInt(c.uid),sexe:c.sexe,age:c.age,job:c.job,famsit:c.famsit,studies:c.studies,reltype:c.reltype,reltypeSpecial:c.reltypeSpecial, inputPhoneFiche.prototype.fieldsToStorage=function(){console.log("FICHE: FIELDS TO STORAGE");for(var a=$$("article.relation-panel .fiche-relation"),b=0;b<a.length;b++){var c=(new FormDeflater(a[b],["input","select"],["data-name"])).deflate(),e=crc32(JSON.stringify(c)),d=lsi.get("fiches",c.uid);if(!1!==d){if(null!=d.hash&&d.hash==e)break;c={contact:parseInt(c.contact),uid:parseInt(c.uid),sexe:c.sexe,age:c.age,job:c.job,famsit:c.famsit,studies:c.studies,reltype:c.reltype,reltypeSpecial:c.reltypeSpecial,
city:c.city,cp:c.cp,loc:c.loc,duration:c.duration,context:c.context,contextSpecial:c.contextSpecial,freq:c.freq,connect:c.connect,connectSpecial:c.connectSpecial,hash:f};c.valid=this.check(c);0<diff(d,c,["hash","valid","timestamp"]).length&&(console.log(diff(d,c,["hash","valid","timestamp"])),console.warn("> FICHE UPDATE"),c.timestamp=Date.now());lsi.set("fiches",c.uid,c)}}}; city:c.city,cp:c.cp,loc:c.loc,duration:c.duration,context:c.context,contextSpecial:c.contextSpecial,freq:c.freq,connect:c.connect,connectSpecial:c.connectSpecial,hash:e};c.valid=this.check(c);0<diff(d,c,["hash","valid","timestamp"]).length&&(console.log(diff(d,c,["hash","valid","timestamp"])),console.warn("> 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.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]: 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.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.job=null!=a.job?a.job:this.defaultData.job;a.studies=null!=a.studies? 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=== 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===
@ -10,11 +10,10 @@ b&&b.setAttribute("selected","selected");for(var c=$$('article.fiche-relation in
c=$$('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=$$('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=$$('article.fiche-relation input[data-name="uid"][value="'+ c=$$('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=$$('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=$$('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=$$('article.fiche-relation input[data-name="uid"][value="'+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=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="connect"]'); 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=$$('article.fiche-relation input[data-name="uid"][value="'+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=$$('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.log("FICHE: STORAGE TO FIELDS");var a=lsi["export"]("fiches");this.container.innerHTML="";for(var b in a)a[b].uid==this.selected&&this.add(a[b]);this.updateNavBar()}; 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.log("FICHE: STORAGE TO FIELDS");var a=lsi["export"]("fiches");this.container.innerHTML="";for(var b in a)a[b].uid==this.selected&&this.add(a[b]);this.updateNavBar()};
inputPhoneFiche.prototype.sync=function(){console.log("FICHE: SYNC");var a=lsi["export"]("contacts"),b=[],c;for(c in a){if(-1<a[c].call){var f=a[c].call;b.push(f);var d=lsi.get("fiches",f);null==d&&(d=this.defaultData);d.uid=f;d.contact=parseInt(c);lsi.set("fiches",f,d)}-1<a[c].sms&&(f=10+a[c].sms,b.push(f),d=lsi.get("fiches",f),null==d&&(d=this.defaultData),d.uid=f,d.contact=parseInt(c),lsi.set("fiches",f,d))}if(20>b.length)for(c in a){for(a=0;-1<b.indexOf(a)&&20>a;)a++;b.push(a);d=lsi.get("fiches", inputPhoneFiche.prototype.sync=function(){console.log("FICHE: SYNC");var a=lsi["export"]("contacts"),b=[],c;for(c in a){if(-1<a[c].call){var e=a[c].call;b.push(e);var d=lsi.get("fiches",e);null==d&&(d=this.defaultData);d.uid=e;d.contact=parseInt(c);lsi.set("fiches",e,d)}-1<a[c].sms&&(e=10+a[c].sms,b.push(e),d=lsi.get("fiches",e),null==d&&(d=this.defaultData),d.uid=e,d.contact=parseInt(c),lsi.set("fiches",e,d))}if(20>b.length)for(c in a){for(a=0;-1<b.indexOf(a)&&20>a;)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"),e;for(e in d)miniData=lsi.get("mini-fiches",d[e].contact),null==miniData.timestamp||d[e].timestamp>miniData.timestamp?(miniData.sexe=d[e].sexe,miniData.age=d[e].age,miniData.studies=d[e].studies,miniData.loc=d[e].loc,miniData.reltype=d[e].reltype,miniData.reltypeSpecial=d[e].reltypeSpecial):(d[e].sexe=miniData.sexe,d[e].age=miniData.age,d[e].studies=miniData.studies,d[e].loc= a);null==d&&(d=this.defaultData);d.uid=a;d.contact=parseInt(c);lsi.set("fiches",a,d);if(20<=b.length)break}for(var 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)))};
miniData.loc,d[e].reltype=miniData.reltype,d[e].reltypeSpecial=miniData.reltypeSpecial),lsi.set("mini-fiches",d[e].contact,miniData),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;c<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.getData("n"))}; 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;c<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.getData("n"))};
inputPhoneFiche.prototype.updateNavBar=function(){var a=lsi["export"]("fiches"),b=lsi.keys("fiches").length;if($$("#nav-fiche [data-n]").length!=b){this.nav_container.innerHTML="";for(var c=0;c<b;c++)0==c&&(this.nav_container.innerHTML+="<span>APPELS</span>"),9==c?this.nav_container.innerHTML+='<span data-n="'+c+'" class="lc">'+(c%10+1)+"</span>&nbsp;&nbsp;":(10==c&&(this.nav_container.innerHTML+='<span class="fc">SMS</span>'),this.nav_container.innerHTML+='<span data-n="'+c+'">'+(c%10+1)+"</span>")}for(var f in a)b= inputPhoneFiche.prototype.updateNavBar=function(){var a=lsi["export"]("fiches"),b=lsi.keys("fiches").length;if($$("#nav-fiche [data-n]").length!=b){this.nav_container.innerHTML="";for(var c=0;c<b;c++)0==c&&(this.nav_container.innerHTML+="<span>APPELS</span>"),9==c?this.nav_container.innerHTML+='<span data-n="'+c+'" class="lc">'+(c%10+1)+"</span>&nbsp;&nbsp;":(10==c&&(this.nav_container.innerHTML+='<span class="fc">SMS</span>'),this.nav_container.innerHTML+='<span data-n="'+c+'">'+(c%10+1)+"</span>")}for(var e in a)b=
$('#nav-fiche [data-n="'+a[f].uid+'"]'),null!=b&&(!0===a[f].valid?b.addClass("done"):b.remClass("done"));this.nav($('#nav-fiche [data-n="'+this.selected+'"]'))}; $('#nav-fiche [data-n="'+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(a.cp)||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"8"==a.reltype&&2>a.reltypeSpecial.length|| inputPhoneFiche.prototype.check=function(a){if(2>a.city.length||isNaN(a.cp)||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"8"==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.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)}; "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.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)};

View File

@ -383,7 +383,7 @@ inputPhoneFiche.prototype.sync = function(){
/* (4) On met à jour la fiche ET on l'enregistre */ /* (4) On met à jour la fiche ET on l'enregistre */
ficheData.uid = ficheUid; ficheData.uid = ficheUid;
ficheData.contact = uid; ficheData.contact = parseInt(uid);
lsi.set('fiches', ficheUid, ficheData); lsi.set('fiches', ficheUid, ficheData);
@ -394,45 +394,7 @@ inputPhoneFiche.prototype.sync = function(){
} }
/* (3) Mise à jour des fiches dupliquées entre le top 10 des APPELS et celui des SMS
/* (3) Mise à jour en fonction des MINI fiches
---------------------------------------------------------*/
/* (1) On récupère les valeurs des MINI fiches et des FICHES */
var ficheData = lsi.export('fiches');
/* (2) Pour chaque champ, on synchronise les MINI fiches avec les FICHES associées */
for( var key in ficheData ){
miniData = lsi.get('mini-fiches', ficheData[key].contact);
var ficheModifiedLast = miniData.timestamp == null || ficheData[key].timestamp > miniData.timestamp;
/* (3) Si la FICHE a été modifiée en dernier, on utilise ses données */
if( ficheModifiedLast ){
miniData.sexe = ficheData[key].sexe;
miniData.age = ficheData[key].age;
miniData.studies = ficheData[key].studies;
miniData.loc = ficheData[key].loc;
miniData.reltype = ficheData[key].reltype;
miniData.reltypeSpecial = ficheData[key].reltypeSpecial;
/* (4) Sinon, on utilise les données de la MINI */
}else{
ficheData[key].sexe = miniData.sexe;
ficheData[key].age = miniData.age;
ficheData[key].studies = miniData.studies;
ficheData[key].loc = miniData.loc;
ficheData[key].reltype = miniData.reltype;
ficheData[key].reltypeSpecial = miniData.reltypeSpecial;
}
/* (5) On enregistre les modifications */
lsi.set('mini-fiches', ficheData[key].contact, miniData);
lsi.set('fiches', key, ficheData[key]);
}
/* (4) Mise à jour des fiches dupliquées entre le top 10 des APPELS et celui des SMS
---------------------------------------------------------*/ ---------------------------------------------------------*/
for( var key in ficheData ){ for( var key in ficheData ){
/* (1) On récupère le contact associé */ /* (1) On récupère le contact associé */

View File

@ -5,6 +5,7 @@ inputPhoneMini.prototype.add=function(a){console.log("MINI FICHE: ADD");if(null=
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="'+ 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;b<c.length;b++)c[b].value==a.sexe?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('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"): 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;b<c.length;b++)c[b].value==a.sexe?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('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=$$('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.loc?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked")};inputPhoneMini.prototype.storageToFields=function(){console.log("MINI FICHE: STORAGE TO FIELDS");var a=lsi.get("mini-fiches",this.selected);this.container.innerHTML="";this.add(a);this.updateNavBar()}; c[b].removeAttribute("checked");c=$$('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.loc?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked")};inputPhoneMini.prototype.storageToFields=function(){console.log("MINI FICHE: STORAGE TO FIELDS");var a=lsi.get("mini-fiches",this.selected);this.container.innerHTML="";this.add(a);this.updateNavBar()};
inputPhoneMini.prototype.sync=function(){console.log("MINI FICHE: SYNC");var a=lsi["export"]("contacts"),b;for(b in a){var c=lsi.get("mini-fiches",b);null==c&&(c=this.defaultData,c.valid=!1);c.uid=a[b].uid;lsi.set("mini-fiches",b,c)}};inputPhoneMini.prototype.nav=function(a){if(null==a||!1===a.getData("n")||isNaN(a.getData("n"))||"nav-mini"!=a.parentNode.id)return!1;for(var b=$$("#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.sync=function(){console.log("MINI FICHE: SYNC");var a=lsi["export"]("contacts"),b=lsi["export"]("fiches"),c=[],e;for(e in b)-1==c.indexOf(b[e].contact)&&c.push(b[e].contact);for(var d in a)-1<c.indexOf(parseInt(d))?lsi.del("mini-fiches",d):(console.warn(d,c,c.indexOf(parseInt(d)),lsi["export"]("mini-fiches")),a=lsi.get("mini-fiches",d),null==a&&(a=this.defaultData,a.valid=!1),a.uid=parseInt(d),lsi.set("mini-fiches",d,a))};
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<b;c++)this.nav_container.innerHTML+='<span data-n="'+c+'">'+(c+1)+"</span>"}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.nav=function(a){if(null==a||!1===a.getData("n")||isNaN(a.getData("n"))||"nav-mini"!=a.parentNode.id)return!1;for(var b=$$("#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"]("mini-fiches");Object.keys(a);this.nav_container.innerHTML="";var b=0,c;for(c in a)this.nav_container.innerHTML+='<span data-n="'+c+'">'+ ++b+"</span>";for(c in a)b=$('#nav-mini [data-n="'+a[c].uid+'"]'),null!=b&&(!0===a[c].valid?b.addClass("done"):b.remClass("done"));this.nav($('#nav-mini [data-n="'+this.selected+'"]'))};
inputPhoneMini.prototype.check=function(a){return""==a.sexe||"."==a.studies||"."==a.age||""==a.loc||""==a.reltype||"8"==a.reltype&&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)}; inputPhoneMini.prototype.check=function(a){return""==a.sexe||"."==a.studies||"."==a.age||""==a.loc||""==a.reltype||"8"==a.reltype&&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)};

View File

@ -30,7 +30,7 @@ inputPhoneMini.prototype = {
inputPhoneMini.prototype.fieldsToStorage = function(){ inputPhoneMini.prototype.fieldsToStorage = function(){
console.log('MINI FICHE: FIELDS TO STORAGE'); console.log('MINI FICHE: FIELDS TO STORAGE');
// {1} Pour chaque formulaire de contact présent // // {1} Pour chaque formulaire de MINI fiche à l'écran //
var existingMiniFiches = $$('article.mini-relation-panel .mini-fiche-relation'); var existingMiniFiches = $$('article.mini-relation-panel .mini-fiche-relation');
for( var i = 0 ; i < existingMiniFiches.length ; i++ ){ for( var i = 0 ; i < existingMiniFiches.length ; i++ ){
// {2} On initialise notre deflater pour récupérer les valeurs // // {2} On initialise notre deflater pour récupérer les valeurs //
@ -219,24 +219,42 @@ inputPhoneMini.prototype.sync = function(){
/* (1) On récupère les clés de tous les CONTACTS */ /* (1) On récupère les clés de tous les CONTACTS */
var contactData = lsi.export('contacts'); var contactData = lsi.export('contacts');
/* (2) Pour chaque CONTACT, on met à jour/crée la MINI fiche associée */
/* (2) On enregistre les contacts qui sont déja dans les FICHES */
var fiches = lsi.export('fiches');
var ignoredContacts = [];
for( var id in fiches )
if( ignoredContacts.indexOf( fiches[id].contact ) == -1 )
ignoredContacts.push( fiches[id].contact );
/* (3) Pour chaque CONTACT, on met à jour/crée la MINI fiche associée */
for( var key in contactData ){ for( var key in contactData ){
/* (3) On récupère les informations de la MINI (si elle existe) */ /* (4) Si le contact est déja dans une fiche, on le retire */
if( ignoredContacts.indexOf(parseInt(key)) > -1 ){
// On supprime au cas ou
lsi.del('mini-fiches', key);
continue;
}
console.warn(key, ignoredContacts, ignoredContacts.indexOf(parseInt(key)), lsi.export('mini-fiches'));
/* (5) On récupère les informations de la MINI (si elle existe) */
var miniData = lsi.get('mini-fiches', key); var miniData = lsi.get('mini-fiches', key);
/* (4) Si la MINI fiche n'exise pas, on la crée avec les valeurs par défaut */ /* (6) Si la MINI fiche n'exise pas, on la crée avec les valeurs par défaut */
if( miniData == null ){ if( miniData == null ){
miniData = this.defaultData; miniData = this.defaultData;
miniData.valid = false; miniData.valid = false;
} }
/* (5) On met à jour la MINI fiche */ /* (7) On met à jour la MINI fiche */
miniData.uid = contactData[key].uid; miniData.uid = parseInt(key);
/* (6) On enregistre les modification */ /* (8) On enregistre les modification */
lsi.set('mini-fiches', key, miniData); lsi.set('mini-fiches', key, miniData);
} }
@ -282,19 +300,15 @@ inputPhoneMini.prototype.updateNavBar = function(){
var len = Object.keys(miniData).length; var len = Object.keys(miniData).length;
/* (1) On vérifie si la barre de navigation est à jour */ /* (1) On vide et remplit la barre de nav, si elle n'est pas à jour */
var navBarUpToDate = $$('#nav-mini [data-n]').length == len; this.nav_container.innerHTML = '';
var i = 0;
for( var key in miniData )
this.nav_container.innerHTML += '<span data-n="'+key+'">'+(++i)+'</span>';
/* (2) On vide et remplit la barre de nav, si elle n'est pas à jour */ /* (2) On montre les MINI fiches qui sont correctes dans la navbar */
if( !navBarUpToDate ){
this.nav_container.innerHTML = '';
for( var i = 0 ; i < len ; i++ )
this.nav_container.innerHTML += '<span data-n="'+i+'">'+(i+1)+'</span>';
}
/* (3) On montre les MINI fiches qui sont correctes dans la navbar */
for( var key in miniData ){ for( var key in miniData ){
var currentElement = $('#nav-mini [data-n="'+miniData[key].uid+'"]'); var currentElement = $('#nav-mini [data-n="'+miniData[key].uid+'"]');
@ -315,7 +329,7 @@ inputPhoneMini.prototype.updateNavBar = function(){
/* (4) On séléctionne par défaut la dernière MINI fiche sélectionnée */ /* (3) On séléctionne par défaut la dernière MINI fiche sélectionnée */
this.nav( $('#nav-mini [data-n="'+this.selected+'"]') ); this.nav( $('#nav-mini [data-n="'+this.selected+'"]') );
}; };

View File

@ -1,5 +1,5 @@
function localStorageInterface(){} function localStorageInterface(){}
localStorageInterface.prototype={dataset:[],dataset_keys:[],storage:localStorage,setStorage:function(a){if(a!=localStorage&&a!=sessionStorage)return!1;this.storage=a},set:function(a,b,d){b=b.toString();var c=this.dataset.indexOf(a);if(-1==c)return!1;-1==this.dataset_keys[c].indexOf(b)&&(this.dataset_keys[c].push(b),this.storage.setItem(a,JSON.stringify(this.dataset_keys[c])));this.storage.setItem(a+"_"+b,JSON.stringify(d));return!0},get:function(a,b){b=b.toString();return-1==this.dataset.indexOf(a)? localStorageInterface.prototype={dataset:[],dataset_keys:[],storage:localStorage,setStorage:function(a){if(a!=localStorage&&a!=sessionStorage)return!1;this.storage=a},set:function(a,b,d){b=b.toString();var c=this.dataset.indexOf(a);if(-1==c)return!1;-1==this.dataset_keys[c].indexOf(b)&&(this.dataset_keys[c].push(b),this.storage.setItem(a,JSON.stringify(this.dataset_keys[c])));this.storage.setItem(a+"_"+b,JSON.stringify(d));return!0},get:function(a,b){if(null!=b)return b=b.toString(),-1==this.dataset.indexOf(a)?
!1:JSON.parse(this.storage.getItem(a+"_"+b))},del:function(a,b){b=b.toString();var d=this.dataset.indexOf(a);if(-1==d)return!1;var c=this.dataset_keys[d].indexOf(b);if(-1==c)return!1;this.storage.removeItem(a+"_"+b);this.dataset_keys[d].splice(c,1);this.storage.setItem(a,JSON.stringify(this.dataset_keys[d]));return!0},createDataset:function(a){if("string"!=typeof a)return!1;if(-1<this.dataset.indexOf(a))return!0;var b=this.storage.getItem(a);null!=b?(this.dataset.push(a),this.dataset_keys.push(JSON.parse(b))): !1:JSON.parse(this.storage.getItem(a+"_"+b))},del:function(a,b){b=b.toString();var d=this.dataset.indexOf(a);if(-1==d)return!1;var c=this.dataset_keys[d].indexOf(b);if(-1==c)return!1;this.storage.removeItem(a+"_"+b);this.dataset_keys[d].splice(c,1);this.storage.setItem(a,JSON.stringify(this.dataset_keys[d]));return!0},createDataset:function(a){if("string"!=typeof a)return!1;if(-1<this.dataset.indexOf(a))return!0;var b=this.storage.getItem(a);null!=b?(this.dataset.push(a),this.dataset_keys.push(JSON.parse(b))):
(this.dataset.push(a),this.dataset_keys.push([]),this.storage.setItem(a,JSON.stringify([])));return!0},keys:function(a){a=this.dataset.indexOf(a);return-1==a?!1:this.dataset_keys[a]},"export":function(a){var b=this.dataset.indexOf(a);if(-1==b)return!1;for(var d={},c=0;c<this.dataset_keys[b].length;c++)d[this.dataset_keys[b][c]]=this.get(a,this.dataset_keys[b][c]);return d},"import":function(a,b){-1==this.dataset.indexOf(a)?this.createDataset(a):this.clear(a);for(var d in b)this.set(a,d,b[d]);return!0}, (this.dataset.push(a),this.dataset_keys.push([]),this.storage.setItem(a,JSON.stringify([])));return!0},keys:function(a){a=this.dataset.indexOf(a);return-1==a?!1:this.dataset_keys[a]},"export":function(a){var b=this.dataset.indexOf(a);if(-1==b)return!1;for(var d={},c=0;c<this.dataset_keys[b].length;c++)d[this.dataset_keys[b][c]]=this.get(a,this.dataset_keys[b][c]);return d},"import":function(a,b){-1==this.dataset.indexOf(a)?this.createDataset(a):this.clear(a);for(var d in b)this.set(a,d,b[d]);return!0},
clear:function(a){var b=this.dataset.indexOf(a);if(-1==b)return!1;var d=this["export"](a),c;for(c in d)this.del(a,c);this.dataset_keys[b]=[];this.storage.setItem(a,JSON.stringify(this.dataset_keys[b]));return!0}};var lsi=new localStorageInterface; clear:function(a){var b=this.dataset.indexOf(a);if(-1==b)return!1;var d=this["export"](a),c;for(c in d)this.del(a,c);this.dataset_keys[b]=[];this.storage.setItem(a,JSON.stringify(this.dataset_keys[b]));return!0}};var lsi=new localStorageInterface;

View File

@ -55,6 +55,9 @@ localStorageInterface.prototype = {
* *
*/ */
get: function(dataset_name, key){ get: function(dataset_name, key){
if( key == null )
return null;
// On met la clé en <String> // On met la clé en <String>
key = key.toString(); key = key.toString();

View File

@ -1,6 +1,6 @@
var subjectManager,contactManager,miniManager,ficheManager,matriceManager; var subjectManager,contactManager,miniManager,ficheManager,matriceManager;
function dynamicUpdate(a){var b=a instanceof Element,f=b&&"SPAN"==a.tagName&&"switch-left"==a.className,e=b&&"SPAN"==a.tagName&&"switch-both"==a.className,g=b&&"INPUT"==a.tagName&&"submit"==a.type,c=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(!(e||f||g||c||b)&&!0!==a)return!1;if(e)console.log("> switch firstname <-> lastname"),f=a.parentNode,a=f.children[8],f=f.children[10],e=a.value,a.value=f.value,f.value= function dynamicUpdate(a){var b=a instanceof Element,f=b&&"SPAN"==a.tagName&&"switch-left"==a.className,e=b&&"SPAN"==a.tagName&&"switch-both"==a.className,g=b&&"INPUT"==a.tagName&&"submit"==a.type,c=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(!(e||f||g||c||b)&&!0!==a)return!1;if(e)console.log("> switch firstname <-> lastname"),f=a.parentNode,a=f.children[8],f=f.children[10],e=a.value,a.value=f.value,f.value=
e;else if(f){console.log("> switch firstname+lastname -> username");f=a.parentNode;e=f.children[6];a=f.children[8];f=f.children[10];if(0<e.value.length||0==a.value.length&&0==f.value.length)return!1;e.value=a.value+" "+f.value;a.value="";f.value=""}else console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),matriceManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(), e;else if(f){console.log("> switch firstname+lastname -> username");f=a.parentNode;e=f.children[6];a=f.children[8];f=f.children[10];if(0<e.value.length||0==a.value.length&&0==f.value.length)return!1;e.value=a.value+" "+f.value;a.value="";f.value=""}else console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),matriceManager.fieldsToStorage(),ficheManager.sync(),miniManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),
matriceManager.storageToFields(),(g||b)&&contactManager.storageToFields()} matriceManager.storageToFields(),(g||b)&&contactManager.storageToFields()}
include("/js/includes/input-phone-subject.js",function(){include("/js/includes/input-phone-contact.js",function(){include("/js/includes/input-phone-mini.js",function(){include("/js/includes/input-phone-fiche.js",function(){include("/js/includes/input-phone-matrice.js",function(){subjectManager=new inputPhoneSubject($('article.subject-panel [data-name="number"]'),$('article.subject-panel [data-name="username"]'),$('article.subject-panel [data-name="firstname"]'),$('article.subject-panel [data-name="lastname"]'), include("/js/includes/input-phone-subject.js",function(){include("/js/includes/input-phone-contact.js",function(){include("/js/includes/input-phone-mini.js",function(){include("/js/includes/input-phone-fiche.js",function(){include("/js/includes/input-phone-matrice.js",function(){subjectManager=new inputPhoneSubject($('article.subject-panel [data-name="number"]'),$('article.subject-panel [data-name="username"]'),$('article.subject-panel [data-name="firstname"]'),$('article.subject-panel [data-name="lastname"]'),
$('article.subject-panel [data-name="submit"]'));subjectManager.attach();contactManager=new inputPhoneContact($("article.contact-panel"),$("#nav-contact"));contactManager.attach(dynamicUpdate);miniManager=new inputPhoneMini($("article.mini-relation-panel"),$("#nav-mini"));miniManager.attach(dynamicUpdate);ficheManager=new inputPhoneFiche($("article.relation-panel"),$("#nav-fiche"));ficheManager.attach(dynamicUpdate);matriceManager=new inputPhoneMatrice($("article.matrice-panel"));matriceManager.attach(dynamicUpdate); $('article.subject-panel [data-name="submit"]'));subjectManager.attach();contactManager=new inputPhoneContact($("article.contact-panel"),$("#nav-contact"));contactManager.attach(dynamicUpdate);miniManager=new inputPhoneMini($("article.mini-relation-panel"),$("#nav-mini"));miniManager.attach(dynamicUpdate);ficheManager=new inputPhoneFiche($("article.relation-panel"),$("#nav-fiche"));ficheManager.attach(dynamicUpdate);matriceManager=new inputPhoneMatrice($("article.matrice-panel"));matriceManager.attach(dynamicUpdate);

View File

@ -91,14 +91,14 @@ function dynamicUpdate(target){
/* (4) On enregistre la MATRICE */ /* (4) On enregistre la MATRICE */
matriceManager.fieldsToStorage(); matriceManager.fieldsToStorage();
/* (5) On synchronise les MINI avec les CONTACTS */ /* (5) On synchronise les FICHE avec les CONTACTS */
miniManager.sync();
/* (6) On synchronise les FICHE avec les CONTACTS */
// 1. On synchronise les `mini` et `fiches` associées en fonction de la dernière date de modification // 1. On synchronise les `mini` et `fiches` associées en fonction de la dernière date de modification
// 2. On synchronise les `fiches` dupliquées en fonction de la dernière date de modification // 2. On synchronise les `fiches` dupliquées en fonction de la dernière date de modification
ficheManager.sync(); ficheManager.sync();
/* (6) On synchronise les MINI avec les CONTACTS */
// Supprime les contacts déja dans les FICHES
miniManager.sync();
/* (7) On affiche le tout */ /* (7) On affiche le tout */
miniManager.storageToFields(); miniManager.storageToFields();