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

8 lines
2.7 KiB
JavaScript

function inputFacebookContact(a,b){this.container=a;this.nav_container=b}inputFacebookContact.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null};inputFacebookContact.prototype.check=function(a){return 0<a.username.length+a.firstname.length+a.lastname.length};
inputFacebookContact.prototype.fieldsToStorage=function(){console.log("CONTACTS: FIELDS TO STORAGE");for(var a=$$('[data-sublink="facebook"] article.contact-panel .new-contact'),b=0;b<a.length;b++){var c=(new FormDeflater(a[b],["input"],["data-name"])).deflate();if(this.check(c)){var d={uid:parseInt(c.uid),username:c.username,firstname:c.firstname,lastname:c.lastname};d.hash=crc32(JSON.stringify(d));lsi.set("f_contacts",parseInt(c.uid),d)}}};
inputFacebookContact.prototype.add=function(a){console.log("CONTACTS: ADD");if(null==a||null==a.uid||isNaN(a.uid))return!1;a.username=null!=a.username?a.username:"";a.firstname=null!=a.firstname?a.firstname:"";a.lastname=null!=a.lastname?a.lastname:"";a.call=null!=a.call?a.call:-1;a.sms=null!=a.sms?a.sms:-1;a.countcall=null!=a.countcall?a.countcall:0;a.countsms=null!=a.countsms?a.countsms:0;this.container.innerHTML+=fContactBuilder.build(a);a=$$('[data-sublink="facebook"] 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)};inputFacebookContact.prototype.storageToFields=function(){console.log("CONTACTS: STORAGE TO FIELDS");var a=lsi.keys("f_contacts");this.container.innerHTML="";for(var b=this.selected+10,c=this.selected;c<b&&c<a.length;c++)this.add(lsi.get("f_contacts",a[c]));b>=a.length&&this.add({uid:a.length});this.updateNavBar()};
inputFacebookContact.prototype.nav=function(a){if(null==a||!1===a.getData("n")||isNaN(a.getData("n"))||"f_nav-contact"!=a.parentNode.id)return!1;for(var b=$$('[data-sublink="facebook"] #f_nav-contact > span.active'),c=0;c<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.getData("n"))};
inputFacebookContact.prototype.updateNavBar=function(){var a=lsi.keys("f_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 data-n="'+b+'">'+(1+b/10)+"</span>"}this.nav($('[data-sublink="facebook"] #f_nav-contact [data-n="'+this.selected+'"]'))};
inputFacebookContact.prototype.attach=function(a){console.log("CONTACTS: ATTACH");lsi.createDataset("f_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)};