Correction de la navigation dans les `contacts`

This commit is contained in:
xdrm-brackets 2016-05-04 11:51:13 +02:00
parent 9158f68911
commit 5a410d6b87
3 changed files with 8 additions and 8 deletions

View File

@ -1,8 +1,8 @@
function inputPhoneContact(a,c){this.container=a;this.nav_container=c}inputPhoneContact.prototype={container:this.container,nav_container:this.nav_container,selected:1,handler:null};
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.fieldsToStorage=function(){console.log("CONTACTS: FIELDS TO STORAGE");for(var a=$$("article.contact-panel .new-contact"),c=0;c<a.length;c++){var b=(new FormDeflater(a[c],["input"],["data-name"])).deflate(),d=0<b.number.value.length;if(d=d&&0<b.username.value.length+b.firstname.value.length+b.lastname.value.length)d={uid:parseInt(b.uid.value),number:b.number.value,username:b.username.value,firstname:b.firstname.value,lastname:b.lastname.value,call:parseInt(b.call.value),
sms:parseInt(b.sms.value),countcall:parseInt(b.countcall.value),countsms:parseInt(b.countsms.value)},d.hash=crc32(JSON.stringify(d)),lsi.set("contacts",parseInt(b.uid.value),d)}};
inputPhoneContact.prototype.add=function(a){console.log("CONTACTS: ADD");if(null==a||null==a.uid||isNaN(a.uid))return!1;a.number=null!=a.number?a.number:"";a.username=null!=a.username?a.username:"";a.firstname=null!=a.firstname?a.firstname:"";a.lastname=null!=a.lastname?a.lastname:"";a.call=null!=a.call?a.call:-1;a.sms=null!=a.sms?a.sms:-1;a.countcall=null!=a.countcall?a.countcall:0;a.countsms=null!=a.countsms?a.countsms:0;this.container.innerHTML+=contactBuilder.build(a);a=$$("article.contact-panel .new-contact");
for(var c=this,b=0;b<a.length;b++)a[b].removeEventListener("click",function(a){c.nav(a.target);c.handler(a.target)},!1),a[b].addEventListener("click",function(a){c.nav(a.target);c.handler(a.target)},!1)};inputPhoneContact.prototype.storageToFields=function(){console.log("CONTACTS: STORAGE TO FIELDS");var a=lsi.keys("contacts");this.container.innerHTML="";for(var c=this.selected+10,b=this.selected;b<c&&b<a.length;b++)this.add(lsi.get("contacts",a[b]));c>=a.length&&this.add({uid:a.length});this.updateNavBar()};
inputPhoneContact.prototype.nav=function(a){if("undefined"==typeof a||isNaN(a.getData("n"))||"nav-contact"!=a.parentNode.id)return!1;for(var c=$$("#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("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(this.nav_container.children[this.selected-1])};
inputPhoneContact.prototype.nav=function(a){if(null==a||!1===a.getData("n")||isNaN(a.getData("n"))||"nav-contact"!=a.parentNode.id)return!1;for(var c=$$("#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("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($('#nav-contact [data-n="'+this.selected+'"]'))};
inputPhoneContact.prototype.attach=function(a){console.log("CONTACTS: ATTACH");lsi.createDataset("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)};

View File

@ -10,7 +10,7 @@ function inputPhoneContact(container, navContainer){
inputPhoneContact.prototype = {
container: this.container, // Conteneur des formulaires de contact
nav_container: this.nav_container, // Conteneur de la navigation entre les formulaires
selected: 1, // UID du permier des contacts sélectionnés (10 par 10)
selected: 0, // UID du permier des contacts sélectionnés (10 par 10)
handler: null // Fonction pour l'enregistrement et la synchronisation des données
};
@ -157,10 +157,10 @@ inputPhoneContact.prototype.storageToFields = function(){
=========================================================*/
inputPhoneContact.prototype.nav = function(element){
/* (1) On vérifie que l'élément contient un nombre et existe */
if( typeof element == 'undefined' )
if( element == null )
return false;
if( isNaN(element.getData('n')) || element.parentNode.id != 'nav-contact' )
if( element.getData('n') === false || isNaN(element.getData('n')) || element.parentNode.id != 'nav-contact' )
return false;
/* (2) On désactive tous les éléments actifs */
@ -200,7 +200,7 @@ inputPhoneContact.prototype.updateNavBar = function(){
/* (4) On séléctionne par défaut la dernière MINI fiche sélectionnée */
this.nav( this.nav_container.children[this.selected-1] );
this.nav( $('#nav-contact [data-n="'+( this.selected )+'"]') );
};

File diff suppressed because one or more lines are too long