Utilisation du `for( .. in .. )` au niveau des classes dynamiques
This commit is contained in:
parent
9654855506
commit
d505d50a39
|
@ -1,4 +1,4 @@
|
|||
function inputPhoneContact(a){this.container=a}inputPhoneContact.prototype={container:this.container,handler:null};
|
||||
inputPhoneContact.prototype.fieldsToStorage=function(){console.log("CONTACTS: FIELDS TO STORAGE");for(var a=$$("article.contact-panel .new-contact"),b=0;b<a.length;b++){var c=a[b].parentNode.children.indexOf(a[b]),d=(new FormDeflater(a[b],["input"],["data-name"])).deflate(),e=0<d.number.value.length;(e=e&&0<d.username.value.length+d.firstname.value.length+d.lastname.value.length)&&lsi.set("contacts","form"+c,{uid:c,number:d.number.value,username:d.username.value,firstname:d.firstname.value,lastname:d.lastname.value})}};
|
||||
inputPhoneContact.prototype.add=function(a){console.log("CONTACTS: ADD");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:"";this.container.innerHTML+=contactBuilder.build(a);a=$$("article.contact-panel .new-contact");for(var b=this,c=0;c<a.length;c++)a[c].removeEventListener("click",function(a){b.handler(a.target)},!1),a[c].addEventListener("click",function(a){b.handler(a.target)},!1)};
|
||||
inputPhoneContact.prototype.storageToFields=function(){console.log("CONTACTS: STORAGE TO FIELDS");var a=lsi.keys("contacts");this.container.innerHTML="";for(var b=0;b<a.length;b++){var c=lsi.get("contacts",a[b]);this.add(c)}this.add({number:"",firstname:"",lastname:"",username:""})};inputPhoneContact.prototype.attach=function(a){console.log("CONTACTS: ATTACH");lsi.createDataset("contacts");this.handler=a;this.storageToFields()};
|
||||
inputPhoneContact.prototype.fieldsToStorage=function(){console.log("CONTACTS: FIELDS TO STORAGE");for(var a=$$("article.contact-panel .new-contact"),b=0;b<a.length;b++){var d=a[b].parentNode.children.indexOf(a[b]),c=(new FormDeflater(a[b],["input"],["data-name"])).deflate(),e=0<c.number.value.length;(e=e&&0<c.username.value.length+c.firstname.value.length+c.lastname.value.length)&&lsi.set("contacts","form"+d,{uid:d,number:c.number.value,username:c.username.value,firstname:c.firstname.value,lastname:c.lastname.value})}};
|
||||
inputPhoneContact.prototype.add=function(a){console.log("CONTACTS: ADD");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:"";this.container.innerHTML+=contactBuilder.build(a);a=$$("article.contact-panel .new-contact");for(var b=this,d=0;d<a.length;d++)a[d].removeEventListener("click",function(a){b.handler(a.target)},!1),a[d].addEventListener("click",function(a){b.handler(a.target)},!1)};
|
||||
inputPhoneContact.prototype.storageToFields=function(){console.log("CONTACTS: STORAGE TO FIELDS");var a=lsi["export"]("contacts");this.container.innerHTML="";for(var b in a)this.add(a[b]);this.add({number:"",firstname:"",lastname:"",username:""})};inputPhoneContact.prototype.attach=function(a){console.log("CONTACTS: ATTACH");lsi.createDataset("contacts");this.handler=a;this.storageToFields()};
|
||||
|
|
|
@ -111,19 +111,15 @@ inputPhoneContact.prototype.storageToFields = function(){
|
|||
console.log('CONTACTS: STORAGE TO FIELDS');
|
||||
|
||||
// {1} Pour chaque contact du 'localStorage' //
|
||||
var existingContacts = lsi.keys('contacts');
|
||||
var contactsData = lsi.export('contacts');
|
||||
|
||||
// On réinitialise le HTML
|
||||
this.container.innerHTML = '';
|
||||
|
||||
for( var i = 0 ; i < existingContacts.length ; i++ ){
|
||||
// {2} On récupère les informations du contact //
|
||||
var contactData = lsi.get('contacts', existingContacts[i]);
|
||||
// {2} On ajoute chaque contact à la liste //
|
||||
for( var key in contactsData )
|
||||
this.add(contactsData[key]);
|
||||
|
||||
// {3} On ajoute un contact à la liste //
|
||||
this.add(contactData);
|
||||
|
||||
}
|
||||
|
||||
// On ajoute un champ de plus à remplir
|
||||
this.add({number:'', firstname:'', lastname:'', username:''});
|
||||
|
|
|
@ -13,10 +13,10 @@ a.uid+'"] ~ h5>span>select[data-name="job"]>option[value="'+a.job+'"]');null!=b&
|
|||
"checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="famsit"]');for(b=0;b<c.length&&b<a.famsit.length;b++)a.famsit[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="reltype"]');for(b=0;b<c.length&&b<a.reltype.length;b++)a.reltype[b].status?c[b].setAttribute("checked",
|
||||
"checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(b=0;b<c.length&&b<a.loc.length;b++)a.loc[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="context"]');for(b=0;b<c.length&&b<a.context.length;b++)a.context[b].status?c[b].setAttribute("checked","checked"):
|
||||
c[b].removeAttribute("checked");for(c=0;c<a.freq.length;c++)for(var d=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="freq'+c+'"]'),b=0;b<d.length&&b<a.freq[c].length;b++)a.freq[c][b].status?d[b].setAttribute("checked","checked"):d[b].removeAttribute("checked");for(c=0;c<a.connect.length;c++)for(d=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="connect'+c+'"]'),b=0;b<d.length&&b<a.connect[c].length;b++)a.connect[c][b].status?
|
||||
d[b].setAttribute("checked","checked"):d[b].removeAttribute("checked")};inputPhoneFiche.prototype.storageToFields=function(){console.log("FICHE: STORAGE TO FIELDS");var a=lsi.keys("fiches");this.container.innerHTML="";for(var b=[],c=0;c<a.length;c++){var d=lsi.get("fiches",a[c]);b.push(d.uid);c==this.selected&&this.add(d)}this.updateNavBar(b)};
|
||||
d[b].setAttribute("checked","checked"):d[b].removeAttribute("checked")};inputPhoneFiche.prototype.storageToFields=function(){console.log("FICHE: STORAGE TO FIELDS");var a=lsi["export"]("fiches");this.container.innerHTML="";var b=[],c;for(c in a){var d=a[c].uid;d==this.selected&&this.add(a[c]);b.push(d)}this.updateNavBar(b)};
|
||||
inputPhoneFiche.prototype.sync=function(){console.log("FICHE: SYNC");for(var a=lsi.keys("contacts"),b=0;b<a.length&&10>b;b++){var c=lsi.get("contacts",a[b]),d=lsi.get("fiches",a[b]);null==d&&(d=this.defaultData);d.uid=c.uid;d.firstname=c.firstname;d.lastname=c.lastname;d.username=c.username;lsi.set("fiches",a[b],d)}};
|
||||
inputPhoneFiche.prototype.nav=function(a){if("undefined"==typeof a||isNaN(a.innerHTML))return!1;for(var b=$$("#nav-fiche > span.active"),c=0;c<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.innerHTML)-1};
|
||||
inputPhoneFiche.prototype.updateNavBar=function(a){this.nav_container.innerHTML="";for(var b=0;b<a.length;b++){var c=parseInt(a[b])+1;this.nav_container.innerHTML+="<span>"+c+"</span>"}a=lsi.keys("fiches");for(b=0;b<a.length;b++)c=lsi.get("fiches",a[b]),!0===c.valid?this.nav_container.children[c.uid].addClass("done"):this.nav_container.children[c.uid].remClass("done");this.nav(this.nav_container.children[this.selected])};
|
||||
inputPhoneFiche.prototype.updateNavBar=function(a){this.nav_container.innerHTML="";for(var b=0;b<a.length;b++){var c=parseInt(a[b])+1;this.nav_container.innerHTML+="<span>"+c+"</span>"}a=lsi["export"]("fiches");for(var d in a)!0===a[d].valid?this.nav_container.children[a[d].uid].addClass("done"):this.nav_container.children[a[d].uid].remClass("done");this.nav(this.nav_container.children[this.selected])};
|
||||
inputPhoneFiche.prototype.check=function(a){if(isNaN(parseInt(a.age))||2>a.city.length||isNaN(parseInt(a.duration[0]))&&0<a.duration[0].length||isNaN(parseInt(a.duration[1]))&&0<a.duration[1].length||0==a.duration[0].length+a.duration[1].length||"."==a.job||"."==a.studies||!checkRadioValue(a.sexe)||!checkRadioValue(a.famsit)||!checkRadioValue(a.reltype)||!checkRadioValue(a.loc)||!checkRadioValue(a.context))return!1;for(var b=0;b<a.freq.length;b++)if(!checkRadioValue(a.freq[b]))return!1;for(b=0;b<
|
||||
a.connect.length;b++)if(!checkRadioValue(a.connect[b]))return!1;return a.reltype[8].status&&2>a.reltypeSpecial.length||a.context[11].status&&2>a.contextSpecial[0].length||a.context[12].status&&2>a.contextSpecial[1].length||a.context[13].status&&2>a.contextSpecial[2].length?!1:!0};
|
||||
inputPhoneFiche.prototype.attach=function(a){console.log("FICHE: ATTACH");lsi.createDataset("fiches");this.storageToFields();this.handler=a;var b=this,b=this;this.nav_container.addEventListener("click",function(a){b.nav(a.target);b.handler()},!1)};
|
||||
|
|
|
@ -286,7 +286,7 @@ inputPhoneFiche.prototype.storageToFields = function(){
|
|||
console.log('FICHE: STORAGE TO FIELDS');
|
||||
|
||||
// {1} Pour chaque contact du 'localStorage' //
|
||||
var existingFiches = lsi.keys('fiches');
|
||||
var ficheData = lsi.export('fiches');
|
||||
|
||||
// On réinitialise le HTML
|
||||
this.container.innerHTML = '';
|
||||
|
@ -294,15 +294,13 @@ inputPhoneFiche.prototype.storageToFields = function(){
|
|||
// On récupère les UIDS
|
||||
var UIDs = [];
|
||||
//
|
||||
for( var i = 0 ; i < existingFiches.length ; i++ ){
|
||||
// {2} On récupère les informations du contact //
|
||||
var ficheData = lsi.get('fiches', existingFiches[i]);
|
||||
for( var key in ficheData ){
|
||||
var uid = ficheData[key].uid;
|
||||
|
||||
UIDs.push(ficheData.uid);
|
||||
|
||||
if( i == this.selected )
|
||||
this.add(ficheData);
|
||||
if( uid == this.selected )
|
||||
this.add(ficheData[key]);
|
||||
|
||||
UIDs.push(uid);
|
||||
}
|
||||
|
||||
|
||||
|
@ -407,15 +405,13 @@ inputPhoneFiche.prototype.updateNavBar = function(uid_list){
|
|||
}
|
||||
|
||||
/* (3) On montre les FICHES qui sont correctes */
|
||||
var ficheKeys = lsi.keys('fiches');
|
||||
for( var i = 0 ; i < ficheKeys.length ; i++ ){
|
||||
|
||||
var ficheData = lsi.get('fiches', ficheKeys[i]);
|
||||
var ficheData = lsi.export('fiches');
|
||||
for( var key in ficheData ){
|
||||
|
||||
// Si la MINI fiche est valide
|
||||
if( ficheData.valid === true ) this.nav_container.children[ficheData.uid].addClass('done');
|
||||
if( ficheData[key].valid === true ) this.nav_container.children[ficheData[key].uid].addClass('done');
|
||||
// Si elle est invalide
|
||||
else this.nav_container.children[ficheData.uid].remClass('done');
|
||||
else this.nav_container.children[ficheData[key].uid].remClass('done');
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ job:c.job.value,loc:c.loc};c.valid=this.check(c);lsi.set("mini-fiches","form"+c.
|
|||
inputPhoneMini.prototype.add=function(a){console.log("MINI FICHE: ADD");if(null==a.uid)return!1;a.firstname=null!=a.firstname?a.firstname:this.defaultData.firstname;a.lastname=null!=a.lastname?a.lastname:this.defaultData.lastname;a.username=null!=a.username?a.username:this.defaultData.username;a.age=null!=a.age?a.age:this.defaultData.age;a.sexe=null!=a.sexe?a.sexe:this.defaultData.sexe;a.job=null!=a.job?a.job:this.defaultData.job;a.loc=null!=a.loc?a.loc:this.defaultData.loc;this.container.innerHTML+=
|
||||
miniFicheBuilder.build({firstname:a.firstname,lastname:a.lastname,username:a.username,uid:a.uid,age:a.age,job:a.job});var b=$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="job"]>option[value="'+a.job+'"]');null!=b&&b.setAttribute("selected","selected");for(var c=$$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'),b=0;b<c.length&&b<a.sexe.length;b++)a.sexe[b].status?c[b].setAttribute("checked",
|
||||
"checked"):c[b].removeAttribute("checked");c=$$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(b=0;b<c.length&&b<a.loc.length;b++)a.loc[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked")};
|
||||
inputPhoneMini.prototype.storageToFields=function(){console.log("MINI FICHE: STORAGE TO FIELDS");var a=lsi.keys("mini-fiches");this.container.innerHTML="";for(var b=[],c=0;c<a.length;c++){var d=lsi.get("mini-fiches",a[c]);c==this.selected&&this.add(d);b.push(d.uid)}this.updateNavBar(b)};
|
||||
inputPhoneMini.prototype.sync=function(){console.log("MINI FICHE: SYNC");for(var a=lsi.keys("contacts"),b=0;b<a.length;b++){var c=lsi.get("contacts",a[b]),d=lsi.get("mini-fiches",a[b]);null==d&&(d=this.defaultData,d.valid=!1);d.uid=c.uid;d.firstname=c.firstname;d.lastname=c.lastname;d.username=c.username;lsi.set("mini-fiches",a[b],d)}};
|
||||
inputPhoneMini.prototype.storageToFields=function(){console.log("MINI FICHE: STORAGE TO FIELDS");var a=lsi["export"]("mini-fiches");this.container.innerHTML="";var b=[],c;for(c in a){var d=a[c].uid;d==this.selected&&this.add(a[c]);b.push(d)}this.updateNavBar(b)};
|
||||
inputPhoneMini.prototype.sync=function(){console.log("MINI FICHE: SYNC");var a=lsi["export"]("contacts"),b;for(b in a){var c=lsi.get("mini-fiches",b);null==c&&(c=this.defaultData,c.valid=!1);c.uid=a[b].uid;c.firstname=a[b].firstname;c.lastname=a[b].lastname;c.username=a[b].username;lsi.set("mini-fiches",b,c)}};
|
||||
inputPhoneMini.prototype.nav=function(a){if("undefined"==typeof a||isNaN(a.innerHTML))return!1;for(var b=$$("#nav-mini > span.active"),c=0;c<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.innerHTML)-1};
|
||||
inputPhoneMini.prototype.updateNavBar=function(a){if(this.nav_container.children.length!=a.length){this.nav_container.innerHTML="";for(var b=0;b<a.length;b++)this.nav_container.innerHTML+="<span>"+(parseInt(a[b])+1)+"</span>"}a=lsi.keys("mini-fiches");for(b=0;b<a.length;b++){var c=lsi.get("mini-fiches",a[b]);!0===c.valid?this.nav_container.children[c.uid].addClass("done"):this.nav_container.children[c.uid].remClass("done")}this.nav(this.nav_container.children[this.selected])};
|
||||
inputPhoneMini.prototype.updateNavBar=function(a){if(this.nav_container.children.length!=a.length){this.nav_container.innerHTML="";for(var b=0;b<a.length;b++)this.nav_container.innerHTML+="<span>"+(parseInt(a[b])+1)+"</span>"}a=lsi["export"]("mini-fiches");for(var c in a)!0===a[c].valid?this.nav_container.children[a[c].uid].addClass("done"):this.nav_container.children[a[c].uid].remClass("done");this.nav(this.nav_container.children[this.selected])};
|
||||
inputPhoneMini.prototype.check=function(a){return!isNaN(parseInt(a.age))&&checkRadioValue(a.sexe)&&"."!=a.job&&checkRadioValue(a.loc)?!0:!1};inputPhoneMini.prototype.attach=function(a){console.log("MINI FICHE: ATTACH");lsi.createDataset("mini-fiches");this.storageToFields();this.handler=a;var b=this,b=this;this.nav_container.addEventListener("click",function(a){b.nav(a.target);b.handler(a.target)},!1)};
|
||||
|
|
|
@ -152,7 +152,7 @@ inputPhoneMini.prototype.storageToFields = function(){
|
|||
console.log('MINI FICHE: STORAGE TO FIELDS');
|
||||
|
||||
// {1} Pour chaque contact du 'localStorage' //
|
||||
var existingMiniFiches = lsi.keys('mini-fiches');
|
||||
var miniData = lsi.export('mini-fiches');
|
||||
|
||||
// On réinitialise le HTML
|
||||
this.container.innerHTML = '';
|
||||
|
@ -160,16 +160,15 @@ inputPhoneMini.prototype.storageToFields = function(){
|
|||
// On récupère les UIDS
|
||||
var UIDs = [];
|
||||
|
||||
for( var i = 0 ; i < existingMiniFiches.length ; i++ ){
|
||||
// {2} On récupère les informations de la MINI fiche //
|
||||
var miniData = lsi.get('mini-fiches', existingMiniFiches[i]);
|
||||
for( var key in miniData ){
|
||||
var uid = miniData[key].uid;
|
||||
|
||||
// {3} On affiche la MINI fiche sélectionnée //
|
||||
if( i == this.selected )
|
||||
this.add(miniData);
|
||||
if( uid == this.selected )
|
||||
this.add(miniData[key]);
|
||||
|
||||
// {4} On enregistre l'UID //
|
||||
UIDs.push(miniData.uid);
|
||||
UIDs.push(uid);
|
||||
}
|
||||
|
||||
|
||||
|
@ -195,34 +194,30 @@ inputPhoneMini.prototype.sync = function(){
|
|||
console.log('MINI FICHE: SYNC');
|
||||
|
||||
/* (1) On récupère les clés de tous les CONTACTS */
|
||||
var contactUIDs = lsi.keys('contacts');
|
||||
var contactData = lsi.export('contacts');
|
||||
|
||||
/* (2) Pour chaque CONTACT, on met à jour/crée la MINI fiche associée */
|
||||
for( var i = 0 ; i < contactUIDs.length ; i++ ){
|
||||
for( var key in contactData ){
|
||||
|
||||
/* (3) On récupère les informations du CONTACT */
|
||||
var contactData = lsi.get('contacts', contactUIDs[i]);
|
||||
|
||||
/* (4) On récupère les informations de la MINI (si elle existe) */
|
||||
var miniData = lsi.get('mini-fiches', contactUIDs[i]);
|
||||
/* (3) On récupère les informations de la MINI (si elle existe) */
|
||||
var miniData = lsi.get('mini-fiches', key);
|
||||
|
||||
|
||||
/* (5) Si la MINI fiche n'exise pas, on la crée avec les valeurs par défaut */
|
||||
/* (4) Si la MINI fiche n'exise pas, on la crée avec les valeurs par défaut */
|
||||
if( miniData == null ){
|
||||
miniData = this.defaultData;
|
||||
miniData = this.defaultData;
|
||||
miniData.valid = false;
|
||||
}
|
||||
|
||||
|
||||
/* (6) On met à jour la MINI fiche */
|
||||
miniData.uid = contactData.uid;
|
||||
miniData.firstname = contactData.firstname;
|
||||
miniData.lastname = contactData.lastname;
|
||||
miniData.username = contactData.username;
|
||||
/* (5) On met à jour la MINI fiche */
|
||||
miniData.uid = contactData[key].uid;
|
||||
miniData.firstname = contactData[key].firstname;
|
||||
miniData.lastname = contactData[key].lastname;
|
||||
miniData.username = contactData[key].username;
|
||||
|
||||
|
||||
/* (7) On enregistre les modification */
|
||||
lsi.set('mini-fiches', contactUIDs[i], miniData);
|
||||
/* (6) On enregistre les modification */
|
||||
lsi.set('mini-fiches', key, miniData);
|
||||
|
||||
}
|
||||
|
||||
|
@ -275,15 +270,13 @@ inputPhoneMini.prototype.updateNavBar = function(uid_list){
|
|||
}
|
||||
|
||||
/* (3) On montre les MINI fiches qui sont correctes dans la navbar */
|
||||
var miniKeys = lsi.keys('mini-fiches');
|
||||
for( var i = 0 ; i < miniKeys.length ; i++ ){
|
||||
|
||||
var miniData = lsi.get('mini-fiches', miniKeys[i]);
|
||||
var miniData = lsi.export('mini-fiches');
|
||||
for( var key in miniData ){
|
||||
|
||||
// Si la MINI fiche est valide
|
||||
if( miniData.valid === true ) this.nav_container.children[miniData.uid].addClass('done');
|
||||
if( miniData[key].valid === true ) this.nav_container.children[miniData[key].uid].addClass('done');
|
||||
// Si elle est invalide
|
||||
else this.nav_container.children[miniData.uid].remClass('done');
|
||||
else this.nav_container.children[miniData[key].uid].remClass('done');
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
function localStorageInterface(){}
|
||||
localStorageInterface.prototype={dataset:[],dataset_keys:[],set:function(a,b,d){var c=this.dataset.indexOf(a);if(-1==c)return!1;-1==this.dataset_keys[c].indexOf(b)&&(this.dataset_keys[c].push(b),localStorage.setItem(a,JSON.stringify(this.dataset_keys[c])));localStorage.setItem(a+"_"+b,JSON.stringify(d));return!0},get:function(a,b){return-1==this.dataset.indexOf(a)?!1:JSON.parse(localStorage.getItem(a+"_"+b))},createDataset:function(a){if(null==a||"string"!=typeof a)return!1;if(-1<this.dataset.indexOf(a))return!0;
|
||||
var b=localStorage.getItem(a);null!=b?(this.dataset.push(a),this.dataset_keys.push(JSON.parse(b))):(this.dataset.push(a),this.dataset_keys.push([]),localStorage.setItem(a,JSON.stringify([])));return!0},keys:function(a){a=this.dataset.indexOf(a);return-1==a?!1:this.dataset_keys[a]}};var lsi=new localStorageInterface;
|
||||
var b=localStorage.getItem(a);null!=b?(this.dataset.push(a),this.dataset_keys.push(JSON.parse(b))):(this.dataset.push(a),this.dataset_keys.push([]),localStorage.setItem(a,JSON.stringify([])));return!0},keys:function(a){a=this.dataset.indexOf(a);return-1==a?!1:this.dataset_keys[a]},"export":function(a){var b=this.dataset.indexOf(a);if(-1==b)return!1;for(var d={},c=0;c<this.dataset_keys[b].length;c++)d[this.dataset_keys[b][c]]=this.get(a,this.dataset_keys[b][c]);return d}};var lsi=new localStorageInterface;
|
||||
|
|
|
@ -92,6 +92,21 @@ localStorageInterface.prototype = {
|
|||
/* (2) On retourne la liste des clés pour ce dataset */
|
||||
return this.dataset_keys[index];
|
||||
|
||||
},
|
||||
|
||||
|
||||
export: function(dataset){
|
||||
/* (1) Si le 'dataset' n'existe pas */
|
||||
var index = this.dataset.indexOf(dataset);
|
||||
if( index == -1 ) return false; // erreur
|
||||
|
||||
/* (2) On remplit l'objet avec toutes les données du dataset */
|
||||
var obj = {};
|
||||
for( var i = 0 ; i < this.dataset_keys[index].length ; i++ )
|
||||
obj[this.dataset_keys[index][i]] = this.get(dataset, this.dataset_keys[index][i]);
|
||||
|
||||
/* (3) On retourne le résultat */
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var clearAllButton=$("#clear-all"),importCallLog=$('input#call_log-import[type="file"]'),subjectManager,contactManager,miniManager,ficheManager;
|
||||
function dynamicUpdate(a){var b="SPAN"==a.tagName&&"switch-left"==a.className,c="SPAN"==a.tagName&&"switch-both"==a.className,e="INPUT"==a.tagName&&"submit"==a.type,d="SPAN"==a.tagName&&("nav-mini"==a.parentNode.id||"nav-fiche"==a.parentNode.id);if(!(c||b||e||d)&&!0!==a)return!1;c?(console.log("> switch firstname <-> lastname"),b=a.parentNode,a=b.children[3],b=b.children[5],c=a.value,a.value=b.value,b.value=c):b?(console.log("> switch firstname+lastname -> username"),b=a.parentNode,c=b.children[1],
|
||||
a=b.children[3],b=b.children[5],c.value=a.value+" "+b.value,a.value="",b.value=""):(console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),contactManager.storageToFields())}function checkRadioValue(a){for(var b=0,c=0;c<a.length;c++)!0===a[c].status&&b++;return 1!=b?!1:!0}
|
||||
function dynamicUpdate(a){var c=a instanceof Element,b=c&&"SPAN"==a.tagName&&"switch-left"==a.className,d=c&&"SPAN"==a.tagName&&"switch-both"==a.className,e=c&&"INPUT"==a.tagName&&"submit"==a.type,c=c&&"SPAN"==a.tagName&&("nav-mini"==a.parentNode.id||"nav-fiche"==a.parentNode.id);if(!(d||b||e||c)&&!0!==a)return!1;d?(console.log("> switch firstname <-> lastname"),b=a.parentNode,a=b.children[3],b=b.children[5],d=a.value,a.value=b.value,b.value=d):b?(console.log("> switch firstname+lastname -> username"),
|
||||
b=a.parentNode,d=b.children[1],a=b.children[3],b=b.children[5],d.value=a.value+" "+b.value,a.value="",b.value=""):(console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),contactManager.storageToFields())}function checkRadioValue(a){for(var c=0,b=0;b<a.length;b++)!0===a[b].status&&c++;return 1!=c?!1:!0}
|
||||
include("/js/includes/input-phone-subject.js",function(){include("/js/includes/input-phone-contact.js",function(){include("/js/includes/input-phone-mini.js",function(){include("/js/includes/input-phone-fiche.js",function(){subjectManager=new inputPhoneSubject($('article.subject-panel [data-name="number"]'),$('article.subject-panel [data-name="username"]'),$('article.subject-panel [data-name="firstname"]'),$('article.subject-panel [data-name="lastname"]'),$('article.subject-panel [data-name="submit"]'));
|
||||
subjectManager.attach();contactManager=new inputPhoneContact($("article.contact-panel"),$("h4.add-contact"));contactManager.attach(dynamicUpdate);miniManager=new inputPhoneMini($("article.mini-relation-panel"),$("#nav-mini"));miniManager.attach(dynamicUpdate);ficheManager=new inputPhoneFiche($("article.relation-panel"),$("#nav-fiche"));ficheManager.attach(dynamicUpdate);importCallLog.addEventListener("change",function(a){api.send({path:"upload/call_log",file:importCallLog.files[0]},function(a){console.log(a);
|
||||
0==a.ModuleError&&(importCallLog.addClass("active"),a={path:"call_log/unserialize",phone_number:$("#subject_phone_number").value},api.send(a,function(a){console.log(a);if(0==a.ModuleError){for(var b=0;b<a.directory.length&&20>b;b++){var d=a.directory[b].name.split(" ");lsi.set("contacts","form"+b,{uid:b,number:a.directory[b].number,username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):""})}dynamicUpdate()}}))})},!1);clearAllButton.addEventListener("click",
|
||||
0==a.ModuleError&&(importCallLog.addClass("active"),a={path:"call_log/unserialize",phone_number:$("#subject_phone_number").value},api.send(a,function(a){console.log(a);if(0==a.ModuleError){for(var d=0;d<a.directory.length&&20>d;d++){var c=a.directory[d].name.split(" ");lsi.set("contacts","form"+d,{uid:d,number:a.directory[d].number,username:1==c.length?c[0]:"",firstname:1<c.length?c[0]:"",lastname:1<c.length?c.splice(1).join(" "):""})}dynamicUpdate(!0)}}))})},!1);clearAllButton.addEventListener("click",
|
||||
function(a){localStorage.clear();reload()},!1)})})})});
|
||||
|
|
|
@ -21,12 +21,15 @@ var ficheManager;
|
|||
|
||||
/* (4) Fonctions utiles */
|
||||
function dynamicUpdate(target){
|
||||
|
||||
|
||||
/* (0) Vérification de la cohérence de la @target
|
||||
---------------------------------------------------------*/
|
||||
var isSwitchLeft = target.tagName == 'SPAN' && target.className == 'switch-left';
|
||||
var isSwitchBoth = target.tagName == 'SPAN' && target.className == 'switch-both';
|
||||
var isSaveButton = target.tagName == 'INPUT' && target.type == 'submit';
|
||||
var isNavButton = target.tagName == 'SPAN' && (target.parentNode.id == 'nav-mini' || target.parentNode.id == 'nav-fiche');
|
||||
var isElement = target instanceof Element;
|
||||
var isSwitchLeft = isElement && target.tagName == 'SPAN' && target.className == 'switch-left';
|
||||
var isSwitchBoth = isElement && target.tagName == 'SPAN' && target.className == 'switch-both';
|
||||
var isSaveButton = isElement && target.tagName == 'INPUT' && target.type == 'submit';
|
||||
var isNavButton = isElement && target.tagName == 'SPAN' && (target.parentNode.id == 'nav-mini' || target.parentNode.id == 'nav-fiche');
|
||||
|
||||
// Si erreur, on retourne une erreur
|
||||
if( !isSwitchBoth && !isSwitchLeft && !isSaveButton && !isNavButton && target !== true )
|
||||
|
@ -203,26 +206,26 @@ include('/js/includes/input-phone-fiche.js', function(){
|
|||
api.send(getCallLogRequest, function(dataResponse){
|
||||
console.log(dataResponse);
|
||||
|
||||
// Si tout est ok, on ajoute les données
|
||||
if( dataResponse.ModuleError == 0 ){
|
||||
// Si erreur, on quitte
|
||||
if( dataResponse.ModuleError != 0 )
|
||||
return;
|
||||
|
||||
/* (5) Pour chaque contact de l'annuaire, on ajoute un contact */
|
||||
for( var i = 0 ; i < dataResponse.directory.length && i < 20 ; i++ ){
|
||||
// On découpe le nom par espaces
|
||||
var splitted = dataResponse.directory[i].name.split(' ');
|
||||
/* (5) Pour chaque contact de l'annuaire, on ajoute un contact */
|
||||
for( var i = 0 ; i < dataResponse.directory.length && i < 20 ; i++ ){
|
||||
// On découpe le nom par espaces
|
||||
var splitted = dataResponse.directory[i].name.split(' ');
|
||||
|
||||
lsi.set('contacts', 'form'+i, {
|
||||
uid: i,
|
||||
number: dataResponse.directory[i].number,
|
||||
username: splitted.length == 1 ? splitted[0] : '', // Si un seul mot -> pseudo
|
||||
firstname: splitted.length > 1 ? splitted[0] : '', // Si plusieurs mots -> le 1er est le prénom
|
||||
lastname: splitted.length > 1 ? splitted.splice(1).join(' ') : '' // et les autres sont le nom
|
||||
});
|
||||
}
|
||||
|
||||
/* (6) On met à jour l'affichage */
|
||||
dynamicUpdate();
|
||||
lsi.set('contacts', 'form'+i, {
|
||||
uid: i,
|
||||
number: dataResponse.directory[i].number,
|
||||
username: splitted.length == 1 ? splitted[0] : '', // Si un seul mot -> pseudo
|
||||
firstname: splitted.length > 1 ? splitted[0] : '', // Si plusieurs mots -> le 1er est le prénom
|
||||
lastname: splitted.length > 1 ? splitted.splice(1).join(' ') : '' // et les autres sont le nom
|
||||
});
|
||||
}
|
||||
|
||||
/* (6) On met à jour l'affichage */
|
||||
dynamicUpdate(true);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue