9 lines
2.8 KiB
JavaScript
9 lines
2.8 KiB
JavaScript
function inputPhoneContact(a,c){this.container=a;this.nav_container=c}inputPhoneContact.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null};inputPhoneContact.prototype.check=function(a){return!isNaN(a.existing)||0<a.username.length};
|
|
inputPhoneContact.prototype.fieldsToStorage=function(){console.log("CONTACTS: FIELDS TO STORAGE");for(var a=$$('[data-sublink="phone"] article.contact-panel .new-contact'),c=0;c<a.length;c++){var b=(new FormDeflater(a[c],["input","select"],["data-name"])).deflate();if(this.check(b)){var d={uid:parseInt(b.uid),username:b.username,existing:isNaN(b.existing)?".":parseInt(b.existing)};d.hash=crc32(JSON.stringify(d));lsi.set("p_contacts",parseInt(b.uid),d)}}};
|
|
inputPhoneContact.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.existing=null!=a.existing?a.existing:".";var c=lsi["export"]("p_friends");a.contacts="";for(var b in c)a.contacts+="\t\t<option value='"+b+"'>"+c[b].name+"</option>\n";this.container.innerHTML+=pContactBuilder.build(a);b=$('[data-sublink="phone"] article.contact-panel .new-contact input[data-name="uid"][value="'+a.uid+'"] ~ span select[data-name="existing"]>option[value="'+
|
|
a.existing+'"]');null!=b&&b.setAttribute("selected","selected");a=$$('[data-sublink="phone"] article.contact-panel .new-contact');var d=this;for(b=0;b<a.length;b++)a[b].removeEventListener("click",function(a){d.nav(a.target);d.handler(a.target)},!1),a[b].addEventListener("click",function(a){d.nav(a.target);d.handler(a.target)},!1)};
|
|
inputPhoneContact.prototype.storageToFields=function(){console.log("CONTACTS: STORAGE TO FIELDS");var a=lsi.keys("p_contacts");this.container.innerHTML="";for(var c=this.selected+10,b=this.selected;b<c&&b<a.length;b++)this.add(lsi.get("p_contacts",a[b]));c>=a.length&&this.add({uid:a.length});this.updateNavBar()};
|
|
inputPhoneContact.prototype.nav=function(a){if(null==a||!1===a.getData("n")||isNaN(a.getData("n"))||"p_nav-contact"!=a.parentNode.id)return!1;for(var c=$$('[data-sublink="phone"] #p_nav-contact > span.active'),b=0;b<c.length;b++)c[b].remClass("active");a.addClass("active");this.selected=parseInt(a.getData("n"))};
|
|
inputPhoneContact.prototype.updateNavBar=function(){var a=lsi.keys("p_contacts").length;if(this.nav_container.children.length!=a){this.nav_container.innerHTML="";for(var c=0;c<a;c+=10)this.nav_container.innerHTML+='<span data-n="'+c+'">'+(1+c/10)+"</span>"}this.nav($('[data-sublink="phone"] #p_nav-contact [data-n="'+this.selected+'"]'))};
|
|
inputPhoneContact.prototype.attach=function(a){console.log("CONTACTS: ATTACH");lsi.createDataset("p_contacts");this.storageToFields();this.handler=a;var c=this;this.nav_container.addEventListener("click",function(a){c.nav(a.target);c.handler(a.target)},!1)};
|