Vérification que le sujet soit défini avant la saisie des contacts dans les formulaires 'input/phone' et 'input/facebook' + gestion de la vérification d'unicité dans 'facebook.contact'

This commit is contained in:
xdrm-brackets 2016-10-12 17:44:23 +02:00
parent 08502b65fb
commit d5da2387c2
4 changed files with 99 additions and 10 deletions

View File

@ -15,12 +15,86 @@ inputFacebookContact.prototype = {
};
/* [2.1] Fiche CALL range
=========================================================*/
inputFacebookContact.prototype.callRange = function(uid){ return uid >= 0 && uid < 20; };
/* [2] Vérification des données d'un contact
/* [2.2] Fiche SMS range
=========================================================*/
inputFacebookContact.prototype.smsRange = function(uid){ return uid >= 20 && uid < 40; };
/* [2.3] Si contact identique
=========================================================*/
inputFacebookContact.prototype.sameContact = function(uid, username, existing, range){
var contact = null,
limits = null;
/* (1) Gestion de la tranche
---------------------------------------------------------*/
if( range === 'call' ) limits = { min: 0, max: 19 };
else if( range === 'sms' ) limits = { min: 29, max: 39 };
else if( range === 'mini' ) limits = { min: 40, max: Infinity };
else
return false;
/* (2) Gestion de la vérification
---------------------------------------------------------*/
for( var a = limits.min, b = limits.max ; a < b ; a++ ){
/* (1) On récupère le contact */
contact = lsi.get('f_contacts', a);
// si n'existe pas, on quitte
if( contact === null ) break;
/* (2) si c'est le contact actuel, on passe au suivant */
if( parseInt(contact.uid) === parseInt(uid) )
continue;
/* (3) On vérifie si le contact est identique (si défini par `username`) */
if( contact.username.length > 0 && username === contact.username )
return true;
/* (4) On vérifie par référence */
else if( username.length === 0 && parseInt(existing) === parseInt(contact.existing) )
return true;
}
return false;
};
/* [2.4] Vérification des données d'un contact
=========================================================*/
inputFacebookContact.prototype.check = function(deflated){
/* On retourne la validité du formulaire */
return !isNaN(deflated.existing) || deflated.username.length > 0;
/* (1) Si on a pas renseigné le sujet
---------------------------------------------------------*/
if( lsi.keys('f_subject').length === 0 ){
Notification.warning('ATTENTION', 'Il faut renseigner le sujet avant de saisir les contacts');
return false;
}
/* (2) On vérifie la validité du formulaire
---------------------------------------------------------*/
var isValid = !isNaN(deflated.existing) || deflated.username.length > 0;
if( !isValid ) return false;
/* (3) On vérifie l'unicité du contact dans le top/mini
---------------------------------------------------------*/
/* (1) On calcule la tranche actuelle (call, sms, mini) */
var range = this.callRange(deflated.uid) ? 'call' : this.smsRange(deflated.uid) ? 'sms' : 'mini';
/* (2) On effectue la vérification */
if( this.sameContact(deflated.uid, deflated.username, deflated.existing, range) ){
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('f_friends', deflated.existing).name+' est déja utilisé dans cette partie');
return false;
}
return true;
}

View File

@ -67,15 +67,24 @@ inputPhoneContact.prototype.sameContact = function(uid, username, existing, rang
/* [2.4] Vérification des données d'un contact
=========================================================*/
inputPhoneContact.prototype.check = function(deflated){
/* On vérifie la validité du formulaire */
/* (1) Si on a pas renseigné le sujet
---------------------------------------------------------*/
if( lsi.keys('p_subject').length === 0 ){
Notification.warning('ATTENTION', 'Il faut renseigner le sujet avant de saisir les contacts');
return false;
}
/* (2) On vérifie la validité du formulaire
---------------------------------------------------------*/
var isValid = !isNaN(deflated.existing) || deflated.username.length > 0;
if( !isValid ) return false;
/* On vérifie l'unicité du contact */
/* (3) On vérifie l'unicité du contact dans le top/mini
---------------------------------------------------------*/
/* (1) On calcule la tranche actuelle (call, sms, mini) */
var range = this.callRange(deflated.uid) ? 'call' : this.smsRange(deflated.uid) ? 'sms' : 'mini';
/* (1) Si contact "identique" dans la même tranche
---------------------------------------------------------*/
/* (2) On effectue la vérification */
if( this.sameContact(deflated.uid, deflated.username, deflated.existing, range) ){
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');
@ -83,6 +92,8 @@ inputPhoneContact.prototype.check = function(deflated){
return false;
}
return true;
};

View File

@ -1,4 +1,7 @@
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.check=function(a){return!isNaN(a.existing)||0<a.username.length};
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+

View File

@ -1,7 +1,8 @@
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(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.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()};