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

12 lines
3.9 KiB
JavaScript

function inputPhoneContact(a,b){this.container=a;this.nav_container=b}inputPhoneContact.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null};inputPhoneContact.prototype.callRange=function(a){return 0<=a&&20>a};inputPhoneContact.prototype.smsRange=function(a){return 20<=a&&40>a};
inputPhoneContact.prototype.sameContact=function(a,b,c,d){var e=null,e=null;if("call"===d)e={min:0,max:19};else if("sms"===d)e={min:29,max:39};else if("mini"===d)e={min:40,max:Infinity};else return!1;d=e.min;for(var f=e.max;d<f;d++){e=lsi.get("p_contacts",d);if(null===e)break;if(parseInt(e.uid)!==parseInt(a)&&(0<e.username.length&&b===e.username||0===b.length&&parseInt(c)===parseInt(e.existing)))return!0}return!1};
inputPhoneContact.prototype.check=function(a){if(0===lsi.keys("p_subject").length)return Notification.warning("ATTENTION","Il faut renseigner le sujet avant de saisir les contacts"),!1;if(isNaN(a.existing)&&!(0<a.username.length))return!1;var b=this.callRange(a.uid)?"call":this.smsRange(a.uid)?"sms":"mini";return this.sameContact(a.uid,a.username,a.existing,b)?(0<a.username.length?Notification.error("Contact dupliqu\u00e9","Le contact de nom "+a.username+" est d\u00e9ja utilis\u00e9 dans cette partie"):
Notification.error("Contact dupliqu\u00e9","Le contact "+lsi.get("p_friends",a.existing).name+" est d\u00e9ja utilis\u00e9 dans cette partie"),!1):!0};
inputPhoneContact.prototype.fieldsToStorage=function(){console.group("[phone.contact] fields to storage");for(var a=$$('[data-sublink="phone"] article.contact-panel .new-contact'),b=0;b<a.length;b++){var c=(new FormDeflater(a[b],["input","select"],["data-name"])).deflate();if(this.check(c)){var d={uid:parseInt(c.uid),username:c.username,existing:isNaN(c.existing)?".":parseInt(c.existing)};d.hash=crc32(JSON.stringify(d));lsi.set("p_contacts",parseInt(c.uid),d)}}console.groupEnd()};
inputPhoneContact.prototype.add=function(a){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 b=lsi["export"]("p_friends");a.contacts="";for(var c in b)a.contacts+="\t\t<option value='"+c+"'>"+b[c].name+"</option>\n";this.container.innerHTML+=pContactBuilder.build(a);c=$('[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!=c&&c.setAttribute("selected","selected");a=$$('[data-sublink="phone"] article.contact-panel .new-contact');var d=this;for(c=0;c<a.length;c++)a[c].removeEventListener("click",function(a){d.nav(a.target);d.handler(a.target)},!1),a[c].addEventListener("click",function(a){d.nav(a.target);d.handler(a.target)},!1)};
inputPhoneContact.prototype.storageToFields=function(){console.group("[phone.contact] storage to fields");var a=lsi.keys("p_contacts");this.container.innerHTML="";for(var b=this.selected+10,c=this.selected;c<b&&c<a.length;c++)this.add(lsi.get("p_contacts",a[c]));b>=a.length&&this.add({uid:a.length});this.updateNavBar();console.groupEnd()};
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 b=$$('[data-sublink="phone"] #p_nav-contact > span.active'),c=0;c<b.length;c++)b[c].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 b=0;b<a;b+=10)this.nav_container.innerHTML+='<span data-n="'+b+'">'+(1+b/10)+"</span>"}this.nav($('[data-sublink="phone"] #p_nav-contact [data-n="'+this.selected+'"]'))};
inputPhoneContact.prototype.attach=function(a){console.group("[phone.contact] attaching events");lsi.createDataset("p_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);console.groupEnd()};