NxTIC/js/includes/input-phone-fiche-min.js

22 lines
8.8 KiB
JavaScript

function inputPhoneFiche(a,c){this.container=a;this.nav_container=c}
inputPhoneFiche.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null,defaultData:{firstname:"",lastname:"",username:"",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:["",""]}};
inputPhoneFiche.prototype.fieldsToStorage=function(){console.log("FICHE: FIELDS TO STORAGE");for(var a=$$("article.relation-panel .fiche-relation"),c=0;c<a.length;c++){var b=(new FormDeflater(a[c],["input","select"],["data-name"])).deflate();console.log(b);var d=lsi.get("fiches","form"+b.uid.value);!1===d&&(d.username="inconnu",d.firstname="inconnu",d.lastname="inconnu");b={uid:b.uid.value,firstname:d.firstname,lastname:d.lastname,username:d.username,sexe:b.sexe,age:b.age.value,job:b.job.value,famsit:b.famsit,
studies:b.studies.value,reltype:b.reltype,reltypeSpecial:b.reltypeSpecial.value,city:b.city.value,loc:b.loc,duration:[b.duration[0].value,b.duration[1].value],context:b.context,contextSpecial:[b.contextSpecial[0].value,b.contextSpecial[1].value,b.contextSpecial[2].value],freq:[b.freq0,b.freq1,b.freq2,b.freq3,b.freq4],connect:[b.connect0,b.connect1,b.connect2,b.connect3,b.connect4,b.connect5],connectSpecial:[b.connectSpecial[0].value,b.connectSpecial[1].value]};lsi.set("fiches","form"+b.uid,b)}};
inputPhoneFiche.prototype.add=function(a){console.log("FICHE: ADD");if(null==a.uid)return!1;a.firstname=null!=a.firstname?a.firstname:this.defaultData.firstname;a.lastname=null!=a.lastname?a.lastname:this.defaultData.lastname;a.username=null!=a.username?a.username:this.defaultData.username;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?a.studies:this.defaultData.studies;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;this.container.innerHTML+=ficheBuilder.build({firstname:a.firstname,lastname:a.lastname,username:a.username,uid:a.uid,age:a.age,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]});var c=$('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=$('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");for(var b=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'),c=0;c<b.length&&c<a.sexe.length;c++)a.sexe[c].status?b[c].setAttribute("checked",
"checked"):b[c].removeAttribute("checked");b=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="famsit"]');for(c=0;c<b.length&&c<a.famsit.length;c++)a.famsit[c].status?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked");b=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="reltype"]');for(c=0;c<b.length&&c<a.reltype.length;c++)a.reltype[c].status?b[c].setAttribute("checked",
"checked"):b[c].removeAttribute("checked");b=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(c=0;c<b.length&&c<a.loc.length;c++)a.loc[c].status?b[c].setAttribute("checked","checked"):b[c].removeAttribute("checked");b=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="context"]');for(c=0;c<b.length&&c<a.context.length;c++)a.context[c].status?b[c].setAttribute("checked","checked"):
b[c].removeAttribute("checked");for(b=0;b<a.freq.length;b++)for(var d=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="freq'+b+'"]'),c=0;c<d.length&&c<a.freq[b].length;c++)a.freq[b][c].status?d[c].setAttribute("checked","checked"):d[c].removeAttribute("checked");for(b=0;b<a.connect.length;b++)for(d=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="connect'+b+'"]'),c=0;c<d.length&&c<a.connect[b].length;c++)a.connect[b][c].status?
d[c].setAttribute("checked","checked"):d[c].removeAttribute("checked")};inputPhoneFiche.prototype.storageToFields=function(){console.log("FICHE: STORAGE TO FIELDS");var a=lsi.keys("fiches");this.container.innerHTML="";for(var c=[],b=0;b<a.length;b++){var d=lsi.get("fiches",a[b]);this.add(d);c.push(d.uid)}this.updateNavBar(c)};
inputPhoneFiche.prototype.sync=function(){console.log("FICHE: SYNC");for(var a=lsi.keys("contacts"),c=0;c<a.length&&9>c;c++){var b=lsi.get("contacts",a[c]),d=lsi.get("fiches",a[c]);null==d&&(d=this.defaultData);d.uid=b.uid;d.firstname=b.firstname;d.lastname=b.lastname;d.username=b.username;lsi.set("fiches",a[c],d)}};
inputPhoneFiche.prototype.nav=function(a){if("undefined"==typeof a||isNaN(a.innerHTML))return!1;for(var c=$$("#nav-fiche > span.active"),b=0;b<c.length;b++)c[b].remClass("active");a.addClass("active");this.selected=parseInt(a.innerHTML)-1;a=$$("article.relation-panel .fiche-relation.active");for(b=0;b<a.length;b++)a[b].remClass("active");this.container.children[this.selected].addClass("active")};
inputPhoneFiche.prototype.updateNavBar=function(a){this.nav_container.innerHTML="";for(var c=0;c<a.length;c++){var b=parseInt(a[c])+1;this.nav_container.innerHTML+="<span>"+b+"</span>"}this.check();this.nav(this.nav_container.children[this.selected])};
inputPhoneFiche.prototype.check=function(){for(var a=lsi.keys("fiches"),c=0;c<a.length;c++){for(var b=lsi.get("fiches",a[c]),d=!0,d=(d=(d=(d=(d=(d=(d=(d=(d=(d=(d=(d=d&&!isNaN(parseInt(b.age)))&&2<=b.city.length)&&(!isNaN(parseInt(b.duration[0]))||""==b.duration[0].length))&&(!isNaN(parseInt(b.duration[1]))||""==b.duration[1].length))&&0<b.duration[0].length+b.duration[1].length)&&"."!=b.job)&&"."!=b.studies)&&checkRadioValue(b.sexe))&&checkRadioValue(b.famsit))&&checkRadioValue(b.reltype))&&checkRadioValue(b.loc))&&
checkRadioValue(b.context),c=0;c<b.freq.length;c++)d=d&&checkRadioValue(b.freq[c]);for(c=0;c<b.connect.length;c++)d=d&&checkRadioValue(b.connect[c]);(d=(d=(d=(d=d&&(!b.reltype[8].status||b.reltype[8].status&&2<=b.reltypeSpecial.length))&&(!b.context[11].status||b.context[11].status&&2<=b.contextSpecial[0].length))&&(!b.context[12].status||b.context[12].status&&2<=b.contextSpecial[1].length))&&(!b.context[13].status||b.context[13].status&&2<=b.contextSpecial[2].length))?this.nav_container.children[b.uid].addClass("done"):
this.nav_container.children[b.uid].remClass("done")}};inputPhoneFiche.prototype.attach=function(a){console.log("FICHE: ATTACH");lsi.createDataset("fiches");this.storageToFields();this.handler=a;var c=this,c=this;this.nav_container.addEventListener("click",function(a){c.nav(a.target);c.handler()},!1)};