Gestion de l'impossibilité de dupliquer des contacts (en fonction de 'username' ou 'existing') [input/phone.contact] [FONCTIONNEL]
This commit is contained in:
parent
ed2a102e6d
commit
74afa03eed
|
@ -43,7 +43,7 @@ inputPhoneContact.prototype.sameContact = function(uid, username, existing, rang
|
||||||
for( var a = limits.min, b = limits.max ; a < b ; a++ ){
|
for( var a = limits.min, b = limits.max ; a < b ; a++ ){
|
||||||
/* (1) On récupère le contact */
|
/* (1) On récupère le contact */
|
||||||
contact = lsi.get('p_contacts', a);
|
contact = lsi.get('p_contacts', a);
|
||||||
console.log(uid, 'to', a, contact);
|
|
||||||
// si n'existe pas, on quitte
|
// si n'existe pas, on quitte
|
||||||
if( contact === null ) break;
|
if( contact === null ) break;
|
||||||
|
|
||||||
|
@ -56,8 +56,9 @@ inputPhoneContact.prototype.sameContact = function(uid, username, existing, rang
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/* (4) On vérifie par référence */
|
/* (4) On vérifie par référence */
|
||||||
else if( username.length === 0 && existing === contact.existing )
|
else if( username.length === 0 && parseInt(existing) === parseInt(contact.existing) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -76,7 +77,9 @@ inputPhoneContact.prototype.check = function(deflated){
|
||||||
/* (1) Si contact "identique" dans la même tranche
|
/* (1) Si contact "identique" dans la même tranche
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
if( this.sameContact(deflated.uid, deflated.username, deflated.existing, range) ){
|
if( this.sameContact(deflated.uid, deflated.username, deflated.existing, range) ){
|
||||||
Notification.error('Contact dupliqué', 'Le contact de nom '+deflated.username+' est déja utilisé');
|
if( deflated.username.length > 0 ) Notification.error('Contact dupliqué', 'Le contact de nom '+deflated.username+' est déja utilisé dans cette partie');
|
||||||
|
else Notification.error('Contact dupliqué', 'Le contact '+lsi.get('p_friends', deflated.existing).name+' est déja utilisé dans cette partie');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +148,6 @@ inputPhoneContact.prototype.add = function(objectData){
|
||||||
return false
|
return false
|
||||||
|
|
||||||
// {0} On formatte l'object //
|
// {0} On formatte l'object //
|
||||||
// objectData.number = (objectData.number != null) ? objectData.number : '';
|
|
||||||
objectData.username = (objectData.username != null) ? objectData.username : '';
|
objectData.username = (objectData.username != null) ? objectData.username : '';
|
||||||
objectData.existing = (objectData.existing != null) ? objectData.existing : '.';
|
objectData.existing = (objectData.existing != null) ? objectData.existing : '.';
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
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};
|
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);console.log(a,"to",d,e);if(null===e)break;if(parseInt(e.uid)!==parseInt(a)&&(0<e.username.length&&b===e.username||0===b.length&&c===e.existing))return!0}return!1};
|
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(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)?(Notification.error("Contact dupliqu\u00e9","Le contact de nom "+a.username+" est d\u00e9ja utilis\u00e9"),!1):!0};
|
inputPhoneContact.prototype.check=function(a){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"),
|
||||||
inputPhoneContact.prototype.fieldsToStorage=function(){console.log("CONTACTS: 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)}}};
|
!1):!0};inputPhoneContact.prototype.fieldsToStorage=function(){console.log("CONTACTS: 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)}}};
|
||||||
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 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="'+
|
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 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)};
|
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.log("CONTACTS: 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()};
|
inputPhoneContact.prototype.storageToFields=function(){console.log("CONTACTS: 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()};
|
||||||
|
|
Loading…
Reference in New Issue