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

13 lines
4.0 KiB
JavaScript
Raw Permalink Normal View History

function inputFacebookContact(a,c){this.container=a;this.nav_container=c}inputFacebookContact.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null};inputFacebookContact.prototype.callRange=function(a){return 0<=a&&20>a};inputFacebookContact.prototype.smsRange=function(a){return 20<=a&&40>a};
inputFacebookContact.prototype.sameContact=function(a,c,b,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("f_contacts",d);if(null===e)break;if(parseInt(e.uid)!==parseInt(a)&&(0<e.username.length&&c===e.username||0===c.length&&parseInt(b)===parseInt(e.existing)))return!0}return!1};
inputFacebookContact.prototype.check=function(a){if(0===lsi.keys("f_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 c=this.callRange(a.uid)?"call":this.smsRange(a.uid)?"sms":"mini";return this.sameContact(a.uid,a.username,a.existing,c)?(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("f_friends",a.existing).name+" est d\u00e9ja utilis\u00e9 dans cette partie"),!1):!0};
inputFacebookContact.prototype.fieldsToStorage=function(){console.group("[facebook.contact] fields to storage");for(var a=$$('[data-sublink="facebook"] 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,firstname:b.firstname,lastname:b.lastname,existing:isNaN(b.existing)?".":parseInt(b.existing)};d.hash=crc32(JSON.stringify(d));lsi.set("f_contacts",parseInt(b.uid),
d)}}console.groupEnd()};
inputFacebookContact.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 c=lsi["export"]("f_friends");a.contacts="";for(var b in c)a.contacts+="\t\t<option value='"+b+"'>"+c[b].name+"</option>\n";this.container.innerHTML+=fContactBuilder.build(a);b=$('[data-sublink="facebook"] 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="facebook"] 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)};
inputFacebookContact.prototype.storageToFields=function(){console.group("[facebook.contact] storage to fields");var a=lsi.keys("f_contacts");this.container.innerHTML="";for(var c=this.selected+10,b=this.selected;b<c&&b<a.length;b++)this.add(lsi.get("f_contacts",a[b]));c>=a.length&&this.add({uid:a.length});this.updateNavBar();console.groupEnd()};
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 c=$$('[data-sublink="facebook"] #f_nav-contact > span.active'),b=0;b<c.length;b++)c[b].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 c=0;c<a;c+=10)this.nav_container.innerHTML+='<span data-n="'+c+'">'+(1+c/10)+"</span>"}this.nav($('[data-sublink="facebook"] #f_nav-contact [data-n="'+this.selected+'"]'))};
inputFacebookContact.prototype.attach=function(a){console.group("[facebook.contact] attaching events");lsi.createDataset("f_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);console.groupEnd()};