diff --git a/public_html/js/includes/input-phone-fiche.js b/public_html/js/includes/input-phone-fiche.js index 767e821..a9d6192 100644 --- a/public_html/js/includes/input-phone-fiche.js +++ b/public_html/js/includes/input-phone-fiche.js @@ -356,7 +356,7 @@ inputPhoneFiche.prototype.sync = function(){ /* (2) Contiendra les uids des fiches qui seront crées */ var addedFicheUids = []; - var ficheData, contactData, miniData, i; + var ficheData, contactData, miniData, i, ficheUid, uid, nbMaxFiche; } @@ -365,47 +365,35 @@ inputPhoneFiche.prototype.sync = function(){ ---------------------------------------------------------*/ // Nombre maximum de fiches (40, sauf si moins de 40 contacts, dans ce cas, le nombre de contacts); - var nbMaxFiche = lsi.keys('p_contacts').length < 2*this.top_size ? lsi.keys('p_contacts').length : 2*this.top_size; + nbMaxFiche = lsi.keys('p_contacts').length < 2*this.top_size ? lsi.keys('p_contacts').length : 2*this.top_size; /* (1) Pour chaque CONTACT, on met à jour/crée la FICHE associée */ - for( var uid in contacts ){ - - /* (1) On cherche un uid de fiche non existant dans l'intervalle [0;40[ */ - ficheUid = 0; - while( addedFicheUids.indexOf(ficheUid) > -1 && ficheUid < nbMaxFiche ) - ficheUid++; - - // On enregistre le nouvel UID dans les uid crées - addedFicheUids.push(ficheUid); + for( uid = 0 ; uid < nbMaxFiche ; uid++ ){ /* (2) On récupère les informations de la FICHE (si elle existe) */ - var ficheData = lsi.get('p_fiches', ficheUid); + ficheData = lsi.get('p_fiches', uid); // Si la fiche n'existe pas, on la crée avec les valeurs par défaut !ficheData && ( ficheData = this.defaultData ); /* (3) On met à jour la fiche ET on l'enregistre */ - ficheData.uid = ficheUid; - ficheData.contact = parseInt(uid); - lsi.set('p_fiches', ficheUid, ficheData); + ficheData.uid = uid; + ficheData.contact = uid; + lsi.set('p_fiches', uid, ficheData); - - /* (4) Si on a déja crée 20+20 fiches, on arrête */ - if( addedFicheUids.length >= nbMaxFiche ) - break; } } - if( false ){ /* (3) Gestion des liens entre mini-fiches et fiches + { /* (3) Gestion des liens entre mini-fiches et fiches ---------------------------------------------------------*/ var originalContact, cloneContact, hasSameUsername, hasSameLink, copied; - var alreadyDoneUsername = {}, - alreadyDoneExisting = {}; + var alreadyProcessedUsername = {}, + alreadyProcessedExisting = {}; ficheData = lsi.export('p_fiches'); miniData = lsi.export('p_mini-fiches'); @@ -417,13 +405,13 @@ inputPhoneFiche.prototype.sync = function(){ originalContact = lsi.get('p_contacts', ficheData[key].contact); // {1.1} On vérifie que le contact n'a pas déja été traité // - if( originalContact.username.length > 0 && alreadyDoneUsername[originalContact.username] != undefined - || originalContact.username.length == 0 && alreadyDoneExisting[originalContact.existing] != undefined ) + if( originalContact.username.length > 0 && alreadyProcessedUsername[originalContact.username] != undefined + || originalContact.username.length == 0 && alreadyProcessedExisting[originalContact.existing] != undefined ) continue; // {1.2} On enregistre username || existing // - if( originalContact.username.length > 0 ) alreadyDoneUsername[originalContact.username] = 0; - else alreadyDoneExisting[originalContact.existing] = 0; + if( originalContact.username.length > 0 ) alreadyProcessedUsername[originalContact.username] = 0; + else alreadyProcessedExisting[originalContact.existing] = 0; // Si erreur, on passe au suivant if( !originalContact ) @@ -496,38 +484,24 @@ inputPhoneFiche.prototype.sync = function(){ console.warn('copying fiche#'+clone[last_index][1].uid+' to fiche#'+clone[i][1].uid, clones_ts[last_index]-input_ts, clones_ts[i]-input_ts); copied = cloneObject( clone[last_index][1] ); copied.uid = clone[i][1].uid; - copied.hash = 0 lsi.set('p_fiches', copied.uid, copied); - /* (5.2) fiche vers mini */ + /* (5.2) fiche vers mini OU mini vers fiche*/ }else if( clone[last_index][0] == 'fiche' ){ - console.warn('copying fiche#'+clone[last_index][1].uid+' to mini#'+clone[i][1].uid, clones_ts[last_index]-input_ts, clones_ts[i]-input_ts); + console.warn('copying '+clone[last_index][0]+'#'+clone[last_index][1].uid+' to '+clone[i][0]+'#'+clone[i][1].uid, clones_ts[last_index]-input_ts, clones_ts[i]-input_ts); copied = cloneObject( clone[i][1] ); copied.age = clone[last_index][1].age; copied.sexe = clone[last_index][1].sexe; copied.loc = clone[last_index][1].loc; copied.reltype = clone[last_index][1].reltype; copied.reltypeSpecial = clone[last_index][1].reltypeSpecial; - copied.hash = 0; - lsi.set('p_mini-fiches', copied.uid, copied); - - /* (5.3) mini vers fiche */ - }else{ - - console.warn('copying mini#'+clone[last_index][1].uid+' to fiche#'+clone[i][1].uid, clones_ts[last_index]-input_ts, clones_ts[i]-input_ts); - copied = cloneObject( clone[i][1] ); - copied.age = clone[last_index][1].age; - copied.sexe = clone[last_index][1].sexe; - copied.loc = clone[last_index][1].loc; - copied.reltype = clone[last_index][1].reltype; - copied.reltypeSpecial = clone[last_index][1].reltypeSpecial; - copied.hash = 0; - lsi.set('p_fiches', copied.uid, copied); + lsi.set( (clone[i][0]=='mini') ? 'p_mini-fiches' : 'p_fiches', copied.uid, copied); } } + console.warn('cloning done'); } @@ -535,7 +509,6 @@ inputPhoneFiche.prototype.sync = function(){ } - console.groupEnd(); }; diff --git a/public_html/js/includes/input-phone-mini.js b/public_html/js/includes/input-phone-mini.js index 57a5116..58303af 100644 --- a/public_html/js/includes/input-phone-mini.js +++ b/public_html/js/includes/input-phone-mini.js @@ -259,7 +259,7 @@ inputPhoneMini.prototype.storageToFields = function(){ miniData[key].hash = crc32( JSON.stringify(clone) ); // On enregistre dans le `localStorage` - lsi.set('p_fiches', miniData[key].uid, miniData[key]); + lsi.set('p_mini-fiches', miniData[key].uid, miniData[key]); // {2.2} Pour la fiche à rendre graphiquement // if( miniData[key].uid == this.selected ) diff --git a/public_html/js/includes/min/input-phone-fiche.js b/public_html/js/includes/min/input-phone-fiche.js index 3ef8b8a..b537b50 100644 --- a/public_html/js/includes/min/input-phone-fiche.js +++ b/public_html/js/includes/min/input-phone-fiche.js @@ -1,20 +1,22 @@ -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,b,c,d,e,f=$$('[data-sublink="phone"] article.relation-panel .fiche-relation');a=0;for(b=f.length;a FICHE UPDATE ("+(d.timestamp-input_ts)+")",c,d),lsi.set("p_fiches",d.uid,d);console.groupEnd()}; +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}}; +inputPhoneFiche.prototype.fieldsToStorage=function(){console.group("[phone.fiche] fields to storage");var a,c,b,d,f,e=$$('[data-sublink="phone"] article.relation-panel .fiche-relation');a=0;for(c=e.length;a FICHE UPDATE ("+(d.timestamp-input_ts)+")",b,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; 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("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= -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]});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");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;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;binput[type="radio"][data-name="freq"]');for(b=0;binput[type="radio"][data-name="connect"]');for(b=0;b=c)break}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 b=$$('[data-sublink="phone"] #p_nav-fiche > span.active'),c=0;cAPPELS");20>d&&c'+(d%20+1)+"  ":(20==d&&(this.nav_container.innerHTML+='
   SMS   '),this.nav_container.innerHTML+=''+(d%20+1)+"")}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+'"]'))}; -inputPhoneFiche.prototype.check=function(a){if(2>a.city.length||isNaN(parseInt(a.duration[0]))&&0a.reltypeSpecial.length|| +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= +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], +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", +"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;cinput[type="radio"][data-name="famsit"]');for(c=0;cinput[type="radio"][data-name="reltype"]');for(c=0;cinput[type="radio"][data-name="loc"]');for(c=0;cinput[type="radio"][data-name="context"]');for(c=0;cinput[type="radio"][data-name="freq"]');for(c=0;cinput[type="radio"][data-name="connect"]');for(c=0;c span.active'),b=0;bAPPELS");20>d&&b'+(d%20+1)+"  ":(20==d&&(this.nav_container.innerHTML+='
   SMS   '),this.nav_container.innerHTML+=''+(d%20+1)+"")}for(var f in a)c=$('[data-sublink="phone"] #p_nav-fiche [data-n="'+a[f].uid+'"]'),null!=c&&(!0===a[f].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]))&&0a.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()}; diff --git a/public_html/js/includes/min/input-phone-mini.js b/public_html/js/includes/min/input-phone-mini.js index 1f43722..c85d740 100644 --- a/public_html/js/includes/min/input-phone-mini.js +++ b/public_html/js/includes/min/input-phone-mini.js @@ -6,7 +6,7 @@ a.uid);if(!1===b)return!1;if(!isNaN(b.existing)){var c=lsi.get("p_friends",b.exi 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;binput[type="radio"][data-name="reltype"]');for(b=0;binput[type="radio"][data-name="loc"]');for(b=0;binput[type="checkbox"][data-name="unknown"]');null!=b&&a.unknown&&b.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["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_mini-fiches", 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"),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(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