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

11 lines
3.7 KiB
JavaScript
Raw Normal View History

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};
inputPhoneFiche.prototype.fieldsToStorage=function(){console.log("MINI FICHE: FIELDS TO STORAGE");for(var a=$$("article.fiche-relation-panel .fiche-fiche-relation"),c=0;c<a.length;c++){var b=(new FormDeflater(a[c],["input","select"],["data-name"])).deflate(),d=lsi.get("fiche-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[0].status,b.sexe[1].status],age:b.age.value,
job:b.job.value,loc:[b.loc[0].status,b.loc[1].status,b.loc[2].status,b.loc[3].status]};lsi.set("fiche-fiches","form"+b.uid,b)}};
inputPhoneFiche.prototype.add=function(a){console.log("MINI FICHE: ADD");if(null==a.uid)return!1;a.firstname=null!=a.firstname?a.firstname:"";a.lastname=null!=a.lastname?a.lastname:"";a.username=null!=a.username?a.username:"";a.age=null!=a.age?a.age:"";a.sexe=null!=a.sexe?a.sexe:[!0,!1];a.job=null!=a.job?a.job:".";a.loc=null!=a.loc?a.loc:[!0,!1,!1,!1];this.container.innerHTML+=ficheFicheBuilder.build({firstname:a.firstname,lastname:a.lastname,username:a.username,uid:a.uid,age:a.age});$('[data-name="uid"][value="'+
a.uid+'"] ~ h5>span>select').value=a.job;for(var c=$$('[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'),b=0;b<c.length;b++)a.sexe[b]?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(b=0;b<c.length;b++)a.loc[b]?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked")};
inputPhoneFiche.prototype.storageToFields=function(){console.log("MINI FICHE: STORAGE TO FIELDS");var a=lsi.keys("fiche-fiches");this.container.innerHTML="";for(var c=[],b=0;b<a.length;b++){var d=lsi.get("fiche-fiches",a[b]);this.add({uid:d.uid,firstname:d.firstname,lastname:d.lastname,username:d.username,age:d.age,sexe:d.sexe,job:d.job,loc:d.loc});c.push(d.uid)}this.updateNavBar(c)};
inputPhoneFiche.prototype.sync=function(){console.log("MINI FICHE: SYNC");for(var a=lsi.keys("contacts"),c=0;c<a.length;c++){var b=lsi.get("contacts",a[c]),d=lsi.get("fiche-fiches",a[c]);null==d?lsi.set("fiche-fiches",a[c],{uid:b.uid,firstname:b.firstname,lastname:b.lastname,username:b.username,sexe:[!0,!1],age:"",job:".",loc:[!0,!1,!1,!1]}):(d.firstname=b.firstname,d.lastname=b.lastname,d.username=b.username,lsi.set("fiche-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.fiche-relation-panel .fiche-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("fiche-fiches"),c=0;c<a.length;c++){var b=lsi.get("fiche-fiches",a[c]),d=!0;(d=(d=d&&!isNaN(parseInt(b.age)))&&"."!=b.job)?this.nav_container.children[b.uid].addClass("done"):this.nav_container.children[b.uid].remClass("done")}};
inputPhoneFiche.prototype.attach=function(a){console.log("MINI FICHE: ATTACH");lsi.createDataset("fiche-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)};