NxTIC/public_html/js/includes/min/input-phone-mini.js

15 lines
5.7 KiB
JavaScript

function inputPhoneMini(a,b){this.container=a;this.nav_container=b}inputPhoneMini.prototype={container:this.container,nav_container:this.nav_container,selected:null,handler:null,defaultData:{contact:null,sexe:"2",age:".",studies:"0",loc:".",reltype:"9",reltypeSpecial:"",unknown:!1,timestamp:0,valid:!1}};
inputPhoneMini.prototype.fieldsToStorage=function(){console.group("[phone.mini] fields to storage");var a,b,c,d,e,f=$$('[data-sublink="phone"] article.mini-relation-panel .mini-fiche-relation');a=0;for(b=f.length;a<b;a++)if(c=new FormDeflater(f[a],["input","select"],["data-name"]),d=c.deflate(),c=lsi.get("p_mini-fiches",d.uid))d={contact:parseInt(d.uid),sexe:d.sexe,age:d.age,studies:d.studies,loc:d.loc,reltype:d.reltype,reltypeSpecial:d.reltypeSpecial,unknown:null!=d.unknown,uid:parseInt(d.uid)},
e=crc32(JSON.stringify(d)),c.hasOwnProperty("hash")&&e==c.hash||(d.hash=e,d.valid=this.check(d),d.timestamp=Date.now(),console.warn("> MINI UPDATE ("+(d.timestamp-input_ts)+")"),lsi.set("p_mini-fiches",d.uid,d));console.groupEnd()};
inputPhoneMini.prototype.add=function(a){if(null==a||null==a.uid)return!1;a.age=null!=a.age?a.age:this.defaultData.age;a.sexe=null!=a.sexe?a.sexe:this.defaultData.sexe;a.studies=null!=a.studies?a.studies:this.defaultData.studies;a.reltype=null!=a.reltype?a.reltype:this.defaultData.reltype;a.reltypeSpecial=null!=a.reltypeSpecial?a.reltypeSpecial:this.defaultData.reltypeSpecial;a.loc=null!=a.loc?a.loc:this.defaultData.loc;a.unknown=null!=a.unknown?a.unknown:this.defaultData.unknown;var b=lsi.get("p_contacts",
a.uid);if(!1===b)return!1;if(!isNaN(b.existing)){var c=lsi.get("p_friends",b.existing);b.username=c.name;a.contact=b.uid;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.studies1&&(a.studies=c.studies1)}this.container.innerHTML+=pMiniFicheBuilder.build({name:b.username,countcall:b.countcall,countsms:b.countsms,uid:a.uid,reltypespecial:a.reltypeSpecial});b=$('[data-sublink="phone"] 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=$('[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;b<c.length;b++)c[b].value==
a.sexe?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('[data-sublink="phone"] 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=$$('[data-sublink="phone"] 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");b=$('[data-sublink="phone"] article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[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_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<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.getData("n"))};
inputPhoneMini.prototype.updateNavBar=function(){var a=lsi["export"]("p_mini-fiches");this.nav_container.innerHTML="";var b=0,c;for(c in a)isNaN(c)||(this.nav_container.innerHTML+='<span data-n="'+c+'">'+ ++b+"</span>");for(c in a)isNaN(c)||(b=$('[data-sublink="phone"] #p_nav-mini [data-n="'+a[c].uid+'"]'),null!=b&&(!0===a[c].valid?b.addClass("done"):b.remClass("done")));this.nav($('[data-sublink="phone"] #p_nav-mini [data-n="'+this.selected+'"]'))};
inputPhoneMini.prototype.check=function(a){return a.unknown?!0:""==a.sexe||"."==a.studies||"."==a.age||""==a.loc||""==a.reltype||"10"==a.reltype&&2>a.reltypeSpecial.length?!1:!0};inputPhoneMini.prototype.attach=function(a){console.group("[phone.mini] attaching events");lsi.createDataset("p_mini-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()};