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

9 lines
2.5 KiB
JavaScript
Raw Normal View History

function inputPhoneContact(a,b){this.container=a;this.nav_container=b}inputPhoneContact.prototype={container:this.container,nav_container:this.nav_container,selected:1,handler:null};
inputPhoneContact.prototype.fieldsToStorage=function(){console.log("CONTACTS: FIELDS TO STORAGE");for(var a=$$("article.contact-panel .new-contact"),b=0;b<a.length;b++){var c=(new FormDeflater(a[b],["input"],["data-name"])).deflate(),d=0<c.number.value.length;if(d=d&&0<c.username.value.length+c.firstname.value.length+c.lastname.value.length)d={uid:parseInt(c.uid.value),number:c.number.value,username:c.username.value,firstname:c.firstname.value,lastname:c.lastname.value},d.hash=crc32(JSON.stringify(d)),
lsi.set("contacts",parseInt(c.uid.value),d)}};
inputPhoneContact.prototype.add=function(a){console.log("CONTACTS: ADD");if(null==a.uid||"number"!=typeof a.uid)return!1;a.number=null!=a.number?a.number:"";a.username=null!=a.username?a.username:"";a.firstname=null!=a.firstname?a.firstname:"";a.lastname=null!=a.lastname?a.lastname:"";this.container.innerHTML+=contactBuilder.build(a);a=$$("article.contact-panel .new-contact");for(var b=this,c=0;c<a.length;c++)a[c].removeEventListener("click",function(a){b.nav(a.target);b.handler(a.target)},!1),a[c].addEventListener("click",
function(a){b.nav(a.target);b.handler(a.target)},!1)};inputPhoneContact.prototype.storageToFields=function(){console.log("CONTACTS: STORAGE TO FIELDS");var a=lsi.keys("contacts");this.container.innerHTML="";for(var b=10*(this.selected-1)+10,c=10*(this.selected-1);c<b&&c<a.length;c++)this.add(lsi.get("contacts",a[c]));b>=a.length&&this.add({uid:a.length,number:"",firstname:"",lastname:"",username:""});this.updateNavBar()};
inputPhoneContact.prototype.nav=function(a){if("undefined"==typeof a||isNaN(a.innerHTML)||"nav-contact"!=a.parentNode.id)return!1;for(var b=$$("#nav-contact > span.active"),c=0;c<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.innerHTML)};
inputPhoneContact.prototype.updateNavBar=function(){var a=lsi.keys("contacts").length;if(this.nav_container.children.length!=a){this.nav_container.innerHTML="";for(var b=0;b<a;b+=10)this.nav_container.innerHTML+="<span>"+(1+b/10)+"</span>"}this.nav(this.nav_container.children[this.selected-1])};
inputPhoneContact.prototype.attach=function(a){console.log("CONTACTS: ATTACH");lsi.createDataset("contacts");this.storageToFields();this.handler=a;var b=this;this.nav_container.addEventListener("click",function(a){b.nav(a.target);b.handler(a.target)},!1)};